Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new chatbot changes are made #1101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading