From 5f089f40402d59bcbe8c3c5dd134a74e40ba464d Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 20 Jan 2020 13:18:59 +1000 Subject: [PATCH] basic chat functionality --- app/static/script.js | 21 +++++++++++++++++++++ app/templates/bot/chat.html | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/static/script.js diff --git a/app/static/script.js b/app/static/script.js new file mode 100644 index 0000000..7a4868e --- /dev/null +++ b/app/static/script.js @@ -0,0 +1,21 @@ +function sendMessage() { + let id = window.location.href.split("/").slice(-1)[0] + message = document.getElementById("chatbox-input-box").value + document.getElementById("chatbox-input-box").value = '' + document.getElementById("chatbox").innerHTML += `
${message}
`; + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + message = this.responseText.replace("\n", "
"); + } else { + message = "Encountered an error while trying to get a response."; + } + document.getElementById("chatbox").innerHTML += `
${this.responseText}
`; + } + }; + xhttp.open("GET", `/bot/chat/${id}/message`, true); + xhttp.send(); + return false; +} + diff --git a/app/templates/bot/chat.html b/app/templates/bot/chat.html index 98a4396..de65c30 100644 --- a/app/templates/bot/chat.html +++ b/app/templates/bot/chat.html @@ -29,13 +29,13 @@
-
+