34602-vm/assets/js/chatbot.js
Flatlogic Bot 1db3c7ce8a 10-16-2025
2025-10-16 19:40:16 +00:00

51 lines
1.7 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const chatIcon = document.getElementById('chat-icon');
const chatWindow = document.getElementById('chat-window');
const closeChat = document.getElementById('close-chat');
const chatInput = document.getElementById('chat-input');
const chatSend = document.getElementById('chat-send');
const chatMessages = document.getElementById('chat-messages');
chatIcon.addEventListener('click', () => {
chatWindow.classList.toggle('open');
});
closeChat.addEventListener('click', () => {
chatWindow.classList.remove('open');
});
const addMessage = (message, sender) => {
const messageElement = document.createElement('div');
messageElement.classList.add('chat-message', sender);
messageElement.textContent = message;
chatMessages.appendChild(messageElement);
chatMessages.scrollTop = chatMessages.scrollHeight;
};
const handleSendMessage = () => {
const message = chatInput.value.trim();
if (message) {
addMessage(message, 'user');
chatInput.value = '';
// Placeholder bot response
setTimeout(() => {
addMessage("Thanks for your message! I'm just a prototype, but I'll be able to help soon.", 'bot');
}, 1000);
}
};
chatSend.addEventListener('click', handleSendMessage);
chatInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
handleSendMessage();
}
});
// Initial bot message
setTimeout(() => {
addMessage("Hello! How can I help you today?", 'bot');
}, 1500);
});