Skip to content

Instantly share code, notes, and snippets.

@sam-thecoder
Created April 22, 2019 07:28
Show Gist options
  • Save sam-thecoder/5c329dacbe4e10ef89e55678efcd85fb to your computer and use it in GitHub Desktop.
Save sam-thecoder/5c329dacbe4e10ef89e55678efcd85fb to your computer and use it in GitHub Desktop.
window.onload = function () {
var app = new Vue({
delimiters: ['[[', ']]'],
el: '#app',
data: {
messages: [],
input: '',
send_blank: false,
placeholder: 'Send a message to the chatbot...',
},
created: function() {
},
methods: {
add_message: function() {
if (this.input.length > 0) {
var message = {
'text': this.input,
'user': true,
'chat_bot': false,
};
this.messages.push(message);
this.input = '';
//just incase
this.send_blank = false;
this.placeholder = "Send a message to the chatbot...";
fetch("/get-response/", {
body: JSON.stringify({'message': message['text']}),
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'user-agent': 'Mozilla/4.0 MDN Example',
'content-type': 'application/json'
},
method: 'POST',
mode: 'cors',
redirect: 'follow',
referrer: 'no-referrer',
})
.then(response => response.json()).then((json) => {
this.messages.push(json['message'])
})
} else {
this.send_blank = true;
this.placeholder = "Please put in some text";
}
},
check_content: function() {
if (this.input.length > 0) {
this.send_blank = false;
this.placeholder = "Send a message to the chatbot...";
} else {
this.send_blank = true;
this.placeholder = "Please put in some text";
}
},
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment