Skip to content

Commit

Permalink
new chatbot changes are made
Browse files Browse the repository at this point in the history
  • Loading branch information
varshasric4 committed Nov 8, 2024
1 parent 2acbbd0 commit ac89e6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
15 changes: 9 additions & 6 deletions chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ function displayBotMessage(message) {
chat.scrollTop = chat.scrollHeight;
}

// Send the user message and get the bot response
// Send the user message and get the bot response
async function sendMessage() {
let input = document.getElementById("chatbot-input").value;
if (input) {
displayUserMessage(input);

// Clear the input field immediately after displaying the user message
document.getElementById("chatbot-input").value = "";

// Wait for the chatbot response
let output = await chatbot(input); // Ensure this line is awaited
let output = await chatbot(input);

setTimeout(function () {
displayBotMessage(output);
}, 1000);

document.getElementById("chatbot-input").value = "";
// Display the bot's response
displayBotMessage(output);
}
}

Expand All @@ -85,3 +86,5 @@ document
sendMessage();
}
});


17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@ <h2>What type of transportation do you prefer for your travels?</h2>
<input type="text" class="chatbot-input" id="chatbot-input" placeholder="Type your message here...." />
<button class="chatbot-button" id="chatbot-button"><i class="fa-brands fa-telegram"></i></button>
</div>
<script>
document.getElementById("chatbot-button").onclick = function() {
const inputField = document.getElementById("chatbot-input");
const message = inputField.value.trim();

if (message) {
const chatContainer = document.getElementById("chatbot-chat");
const userMessage = document.createElement("div");
userMessage.className = "user-message"; // Add styling class as needed
userMessage.textContent = message;
chatContainer.appendChild(userMessage);

// Clear the input field
inputField.value = "";
}
};
</script>
<button onclick="moveToTop()" id="topBtn" title="Go to top"
style="display:flex; position: fixed; right: 30px; z-index: 100000;">
<i class="fa fa-arrow-up" aria-hidden="true"></i>
Expand Down

0 comments on commit ac89e6b

Please sign in to comment.