mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 08:38:59 +00:00
basic chat functionality
This commit is contained in:
parent
60728c0b35
commit
5f089f4040
2 changed files with 23 additions and 2 deletions
21
app/static/script.js
Normal file
21
app/static/script.js
Normal file
|
@ -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 += `<div class="message-container user"><div class="message user">${message}</div></div>`;
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4) {
|
||||
if (this.status == 200) {
|
||||
message = this.responseText.replace("\n", "<br>");
|
||||
} else {
|
||||
message = "Encountered an error while trying to get a response.";
|
||||
}
|
||||
document.getElementById("chatbox").innerHTML += `<div class="message-container bot"><div class="bot-icon"></div><div class="message bot">${this.responseText}</div></div>`;
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", `/bot/chat/${id}/message`, true);
|
||||
xhttp.send();
|
||||
return false;
|
||||
}
|
||||
|
|
@ -29,13 +29,13 @@
|
|||
|
||||
<div class="container">
|
||||
<div id="chatbox">
|
||||
<div class="message-container user">
|
||||
<!-- <div class="message-container user">
|
||||
<div class="message user">Henlo</div>
|
||||
</div>
|
||||
<div class="message-container bot">
|
||||
<div class="bot-icon"></div>
|
||||
<div class="message bot">Henlo human uwu<br>How are you</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<form id="chatbox-input">
|
||||
|
|
Loading…
Reference in a new issue