Skip to content

Commit

Permalink
Update: Refactored Source Code (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangsonww committed Jun 24, 2024
1 parent 59a34e2 commit 1c3d7b2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ document.querySelector(".chatbot").prepend(chatTitleElem);

chatInput.addEventListener("keydown", (e) => {
if (e.key === "Enter" && e.target.value.trim()) {
scrollToBottom();
const question = e.target.value.trim();
const userMsgElem = document.createElement("div");
userMsgElem.innerText = `You: ${question}`;
chatMessages.appendChild(userMsgElem);
scrollToBottom();

setTimeout(async () => {
const response = await getBotResponse(question);
const elizaMsgElem = document.createElement("div");
elizaMsgElem.innerText = `WeatherMate: ${response}`;
chatMessages.appendChild(elizaMsgElem);
scrollToBottom();
}, 1000);

e.target.value = '';
Expand Down

0 comments on commit 1c3d7b2

Please sign in to comment.