Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.99 KB | None | 0 0
  1. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/botui/0.3.9/botui.min.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/botui/0.3.9/botui-theme-default.css">
  3. <style>
  4.     #chat-bot{
  5.         position:fixed;
  6.         z-index:99999;
  7.         bottom:50px;
  8.         right:80px;
  9.         width:300px;
  10.         height:500px;
  11.         background-color:#fff;
  12.         box-shadow:0px 2px 7px #aaa;
  13.         padding-top:50px;
  14.         overflow:scroll;
  15.     }
  16.  
  17.     .chat-bot-title{
  18.         position:absolute;
  19.         top:0px;
  20.         color:#fff;
  21.         width:300px;
  22.         height:40px;
  23.         background-color:#73be1e;
  24.         display:flex;
  25.         align-items:center;
  26.         padding-left:10px;
  27.     }
  28.  
  29.     #chat-bot-textarea {
  30.         position: absolute;
  31.         bottom: 10px;
  32.         right: 10px;
  33.         left: 10px;
  34.         width: 280px;
  35.         height: 45px;
  36.         background-color: #fff;
  37.         outline: 0;
  38.         padding-left: 15px;
  39.         padding-right: 15px;
  40.         color: #000;
  41.         font-weight: 300;
  42.         font-size: 1rem;
  43.         line-height: 1.5;
  44.         border-radius:100px;
  45.         border:1px solid #eee;
  46.     }
  47. </style>
  48.  
  49.  
  50. <div id="chat-bot">
  51.     <div class="chat-bot-title">Emploitic Chatbot</div>
  52.     <bot-ui class="bot-ui"></bot-ui>
  53.     <input autocomplete="off" type="text" id="chat-bot-textarea" placeholder="Ask your question, type here..." onclick>
  54. </div>
  55.  
  56. <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
  57. <script src="https://cdnjs.cloudflare.com/ajax/libs/botui/0.3.9/botui.min.js"></script>
  58. <script type="text/javascript">
  59.  
  60.     let faq_group = [
  61.         {
  62.             text:"What are your opening hours?",
  63.             value:"hours",
  64.             answer:"We're openning from 8h to 17h from Sunday to Thursday"
  65.         },
  66.         {
  67.             text:"What are you services?",
  68.             value:"services",
  69.             answer:"We help candidates to find a job"
  70.         },
  71.         {
  72.             text:"How to apply for an opportunity?",
  73.             value:"apply",
  74.             answer:"[Consult the link](https://www.youtube.com/watch?v=uzLdgTUz9Ms)"
  75.         }
  76.  
  77.     ];
  78.    
  79.     let faq_groups = [
  80.         {
  81.             text:"group questions 1?",
  82.             value:"group-1",
  83.             actions:[
  84.                 {
  85.                     text:"What are your opening hours?",
  86.                     value:"hours",
  87.                     answer:"We're openning from 8h to 17h from Sunday to Thursday"
  88.                 },
  89.                 {
  90.                     text:"What are you services?",
  91.                     value:"services",
  92.                     answer:"We help candidates to find a job"
  93.                 },
  94.                 {
  95.                     text:"How to apply for an opportunity?",
  96.                     value:"apply",
  97.                     answer:"[Consult the link](https://www.youtube.com/watch?v=uzLdgTUz9Ms)"
  98.                 }
  99.  
  100.             ]
  101.         },
  102.         {
  103.             text:"group questions 2?",
  104.             value:"group-2",
  105.             actions:[
  106.                 {
  107.                     text:"How to create a cv?",
  108.                     value:"",
  109.                     answer:"[Consult the link](https://www.youtube.com/watch?v=uzLdgTUz9Ms)"
  110.                 }
  111.  
  112.             ]
  113.         }
  114.     ]
  115.  
  116.     let addMessage = function(botui,message,delay=1000){
  117.         return botui.message.add({
  118.             type:"text",
  119.             delay:delay,
  120.             content: message
  121.         })
  122.     };
  123.  
  124.     let addAction = function(botui,question,faq_group){
  125.         return addMessage(botui,question).then(function(){
  126.             return botui.action.button({
  127.                 action:faq_group
  128.             }).then(function(result){
  129.                 faq_group.forEach(element => {
  130.                     if(element.value === result.value){
  131.                         return addMessage(botui,element.answer);
  132.                     }
  133.                 });
  134.             })
  135.         });
  136.     }
  137.  
  138.     let addActionGroups = function(botui,question,faq_groups){
  139.         return addMessage(botui,question).then(function(){
  140.             return botui.action.button({
  141.                 action:faq_groups
  142.             }).then(function(result){
  143.                 faq_groups.forEach(element => {
  144.                     if(element.value === result.value){
  145.                         return addAction(botui,"Choose a question?",element.actions);;
  146.                     }
  147.                 });
  148.             })
  149.         });
  150.     }
  151.  
  152.  
  153.     var botui = new BotUI('chat-bot');
  154.  
  155.     addActionGroups(botui,"Choose a group of questions",faq_groups);
  156.     //addAction(botui,"Do you have any questions?",faq_group);
  157.    
  158.     document.getElementById("chat-bot-textarea").addEventListener("keyup", event => {
  159.         if(event.keyCode === 13){
  160.             message = document.getElementById('chat-bot-textarea').value;
  161.             addMessage(botui,message,0);
  162.             document.getElementById('chat-bot-textarea').value = "";
  163.         }
  164.     });
  165. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement