forked from hngi/heracles-chatbot-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
69 lines (54 loc) · 1.82 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
let bot = new RiveScript();
const message_container = document.querySelector('.messages');
const form = document.querySelector('form');
const input_box = document.querySelector('input');
const brains = [
'https://gist.githubusercontent.com/benjamin-bala/6ad440da644d80c33f22e6266c087d0c/raw/17ad459de274b80f29095d3bf9383a29132f8227/brain.rive'
];
const anagram =[
'https://gist.githubusercontent.com/benjamin-bala/984cfdacdd7e89aa86f58bb04948daec/raw/2273bbcd7bc9504a50fbbd3774c3a50c550fa73a/anagram.rive'
];
bot.loadFile(anagram).catch(botNotReady);
bot.loadFile(brains).then(botReady).catch(botNotReady);
form.addEventListener('submit', (e) => {
e.preventDefault();
selfReply(input_box.value);
input_box.value = '';
});
function botReply(message){
message_container.innerHTML += `<div class="bot">${message}</div>`;
location.href = '#edge';
}
function selfReply(message){
message_container.innerHTML += `<div class="self">${message}</div>`;
location.href = '#edge';
bot.reply("local-user", message).then(function(reply) {
botReply(reply);
});
}
function botReady(){
bot.sortReplies();
botReply('Hello');
}
function botNotReady(err){
console.log("An error has occurred.", err);
}