test / index.html
joermd's picture
Update index.html
8f76c97 verified
raw
history blame
1.86 kB
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<!-- Previous head content remains the same -->
</head>
<body>
<!-- Previous body content remains the same until the script section -->
<script>
let isSending = false;
async function sendMessage() {
if (isSending) return;
var input = document.getElementById('message-input');
var message = input.value.trim();
if (message !== '') {
isSending = true;
appendMessage('user-message', message);
input.value = '';
document.getElementById('loading').classList.add('visible');
try {
const response = await fetch('/message', { // Updated endpoint
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: message })
});
if (response.ok) {
const data = await response.json();
appendMessage('bot-message', data.response);
} else {
appendMessage('bot-message', 'عذراً، حدث خطأ في معالجة رسالتك.');
}
} catch (error) {
appendMessage('bot-message', 'عذراً، حدث خطأ في الاتصال.');
} finally {
document.getElementById('loading').classList.remove('visible');
isSending = false;
}
}
}
// Rest of the JavaScript functions remain the same
</script>
</body>
</html>