d3.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE html>
  2. <head>
  3. <title>ChatUI</title>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" href="../build/chatUI.css">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8. html, body{
  9. margin:0;
  10. padding:0;
  11. border:0;
  12. }
  13. #chatbot{
  14. width:100%;
  15. height: 100vh;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="chatbot">
  21. </div>
  22. <script src="https://d3js.org/d3.v4.min.js"></script>
  23. <script src="../build/index-d3.min.js"></script>
  24. <script type="text/javascript">
  25. var chat = chatUI(d3.select('#chatbot'));
  26. //Add Text saying 'Hi there!', with a typing delay of 1000ms
  27. chat.addBubble({ type: 'text', value: 'Hi there!', class: 'bot', delay: 1000 }, function () {
  28. //After initial bubble is presented, ask the user for her name
  29. chat.addBubble({ type: 'text', value: 'What is your name?', class: 'bot', delay: 0 });
  30. //Show the input container
  31. chat.showInput(function(input){
  32. //As input arrives, present the input
  33. chat.addBubble({ type: 'text', value: input, class: 'human', delay: 0 });
  34. //Hide the input container
  35. chat.hideInput();
  36. //And welcome the user with her name
  37. chat.addBubble({ type: 'text', value: 'Hello '+input, class: 'bot', delay: 500 });
  38. });
  39. });
  40. </script>
  41. </body>
  42. </html>