|
|
const chatBox = document.getElementById("chat-box"); |
|
|
const userInput = document.getElementById("user-input"); |
|
|
const sendBtn = document.getElementById("send-btn"); |
|
|
|
|
|
sendBtn.onclick = async () => { |
|
|
const message = userInput.value; |
|
|
if (!message) return; |
|
|
|
|
|
|
|
|
const userDiv = document.createElement("div"); |
|
|
userDiv.textContent = "أنت: " + message; |
|
|
chatBox.appendChild(userDiv); |
|
|
|
|
|
userInput.value = ""; |
|
|
|
|
|
|
|
|
const response = await fetch("http://localhost:8000/chat", { |
|
|
method: "POST", |
|
|
headers: { "Content-Type": "application/json" }, |
|
|
body: JSON.stringify({ user_id: "user1", message: message }) |
|
|
}); |
|
|
const data = await response.json(); |
|
|
|
|
|
const novaDiv = document.createElement("div"); |
|
|
novaDiv.textContent = "NOVA AI: " + data.response; |
|
|
chatBox.appendChild(novaDiv); |
|
|
|
|
|
chatBox.scrollTop = chatBox.scrollHeight; |
|
|
}; |