Spaces:
Running
Running
Rohit Ghosh
commited on
Commit
·
535fb1f
1
Parent(s):
27b6a0d
something
Browse files
script.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
// script.js
|
2 |
async function sendMessage() {
|
3 |
const userInput = document.getElementById("user-input");
|
4 |
const message = userInput.value;
|
@@ -18,17 +17,19 @@ async function sendMessage() {
|
|
18 |
// Check if the response is okay
|
19 |
try {
|
20 |
const jsonResponse = await response.json();
|
|
|
21 |
document.getElementById(
|
22 |
"chatbox"
|
23 |
).value += `Bot: ${jsonResponse.response}\n`;
|
|
|
|
|
|
|
24 |
} catch (error) {
|
25 |
console.error("Failed to parse JSON:", error);
|
26 |
document.getElementById(
|
27 |
"chat-log"
|
28 |
).value += `Bot: Something went wrong. Please try again.\n`;
|
29 |
}
|
30 |
-
const data = await response.json();
|
31 |
-
displayMessage("Bot: " + data.response, "bot-message");
|
32 |
}
|
33 |
|
34 |
function displayMessage(text, className) {
|
|
|
|
|
1 |
async function sendMessage() {
|
2 |
const userInput = document.getElementById("user-input");
|
3 |
const message = userInput.value;
|
|
|
17 |
// Check if the response is okay
|
18 |
try {
|
19 |
const jsonResponse = await response.json();
|
20 |
+
// Display the bot's response in the chatbox
|
21 |
document.getElementById(
|
22 |
"chatbox"
|
23 |
).value += `Bot: ${jsonResponse.response}\n`;
|
24 |
+
|
25 |
+
// Also display the message using displayMessage function
|
26 |
+
displayMessage("Bot: " + jsonResponse.response, "bot-message");
|
27 |
} catch (error) {
|
28 |
console.error("Failed to parse JSON:", error);
|
29 |
document.getElementById(
|
30 |
"chat-log"
|
31 |
).value += `Bot: Something went wrong. Please try again.\n`;
|
32 |
}
|
|
|
|
|
33 |
}
|
34 |
|
35 |
function displayMessage(text, className) {
|