async function sendMessage() { const input = document.getElementById('user-input'); const message = input.value; if (!message.trim()) return; const chatBox = document.getElementById('chat-box'); chatBox.innerHTML += `
You: ${message}
`; input.value = ''; const response = await fetch('/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message }) }); const data = await response.json(); chatBox.innerHTML += `
Bot: ${data.response}
`; chatBox.scrollTop = chatBox.scrollHeight; }