Skip to content

Commit

Permalink
js chat interface
Browse files Browse the repository at this point in the history
  • Loading branch information
EddMarwa committed Jul 8, 2024
1 parent 1973e89 commit 013b0c5
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,27 @@ document.addEventListener("DOMContentLoaded", function() {

let isGreetingDisplayed = false;


chatIcon.addEventListener("click", function() {
chatInterface.style.display = "block";
chatIcon.style.display = "none";
userInput.focus();
});


function sendMessage() {
const message = userInput.value.trim();

if (message === "") {

chatInterface.style.display = "none";
chatIcon.style.display = "block";
return;
return;
}


displayMessage(message, 'left');


userInput.value = "";


displayTypingAnimation();


setTimeout(() => {
removeTypingAnimation();

if (!isGreetingDisplayed) {

const currentTime = new Date().getHours();
let greeting;
if (currentTime < 12) {
Expand All @@ -106,33 +94,27 @@ document.addEventListener("DOMContentLoaded", function() {
}, 7000);
}

// Function to handle next user message
function handleNextMessage() {

const finalResponse = "Thank you for your feedback! For more information about your request reach out to us on Instagram @invod.tech or Via WhatsApp 👇";
displayMessage(finalResponse, 'right');


setTimeout(() => {
displayWhatsAppIcon();
}, 2600);


userInput.removeEventListener("keyup", handleNextMessageOnEnter);
sendButton.removeEventListener("click", handleNextMessage);
}


userInput.addEventListener("keyup", function(event) {
if (event.key === "Enter") {
sendMessage();
}
});


sendButton.addEventListener("click", sendMessage);


function resetConversation() {
messages.innerHTML = "";
isGreetingDisplayed = false;
Expand All @@ -146,7 +128,6 @@ document.addEventListener("DOMContentLoaded", function() {
}
});


chatInterface.addEventListener("click", function(event) {
event.stopPropagation();
});
Expand Down Expand Up @@ -200,7 +181,6 @@ document.addEventListener("DOMContentLoaded", function() {
messages.appendChild(messageContainer);
messages.scrollTop = messages.scrollHeight;


whatsappIcon.style.animation = "zoomInOut 2s infinite alternate";

const style = document.createElement("style");
Expand Down

0 comments on commit 013b0c5

Please sign in to comment.