Update index.html
Browse files- index.html +12 -32
index.html
CHANGED
@@ -295,58 +295,38 @@
|
|
295 |
showTypingIndicator();
|
296 |
|
297 |
try {
|
298 |
-
const response = await fetch('/
|
299 |
method: 'POST',
|
300 |
headers: {
|
301 |
'Content-Type': 'application/json',
|
302 |
},
|
303 |
body: JSON.stringify({ message: message })
|
304 |
});
|
305 |
-
|
306 |
-
if (!response.ok)
|
307 |
-
throw new Error('Network response was not ok');
|
308 |
-
}
|
309 |
|
310 |
const data = await response.json();
|
311 |
removeTypingIndicator();
|
312 |
appendMessage(data.response);
|
313 |
} catch (error) {
|
314 |
removeTypingIndicator();
|
315 |
-
|
316 |
-
errorDiv.className = 'error-message';
|
317 |
-
errorDiv.textContent = 'عذراً، حدث خطأ في الاتصال. يرجى المحاولة مرة أخرى.';
|
318 |
-
document.getElementById('chat-container').appendChild(errorDiv);
|
319 |
-
} finally {
|
320 |
-
isProcessing = false;
|
321 |
-
sendButton.disabled = false;
|
322 |
-
input.focus();
|
323 |
}
|
324 |
-
}
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
input.value = suggestion;
|
329 |
-
sendMessage();
|
330 |
}
|
331 |
|
332 |
function clearChat() {
|
333 |
const chatContainer = document.getElementById('chat-container');
|
334 |
chatContainer.innerHTML = '';
|
335 |
-
// إضافة رسالة ترحيبية جديدة
|
336 |
-
appendMessage('مرحباً بك! كيف يمكنني مساعدتك اليوم؟');
|
337 |
}
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
});
|
345 |
-
|
346 |
-
// رسالة الترحيب عند تحميل الصفحة
|
347 |
-
window.onload = function() {
|
348 |
-
appendMessage('مرحباً بك! كيف يمكنني مساعدتك اليوم؟');
|
349 |
-
};
|
350 |
</script>
|
351 |
</body>
|
352 |
-
</html>
|
|
|
295 |
showTypingIndicator();
|
296 |
|
297 |
try {
|
298 |
+
const response = await fetch('/api/chat', {
|
299 |
method: 'POST',
|
300 |
headers: {
|
301 |
'Content-Type': 'application/json',
|
302 |
},
|
303 |
body: JSON.stringify({ message: message })
|
304 |
});
|
305 |
+
|
306 |
+
if (!response.ok) throw new Error('حدث خطأ في الاتصال بالسيرفر.');
|
|
|
|
|
307 |
|
308 |
const data = await response.json();
|
309 |
removeTypingIndicator();
|
310 |
appendMessage(data.response);
|
311 |
} catch (error) {
|
312 |
removeTypingIndicator();
|
313 |
+
appendMessage('⚠️ حدث خطأ، يرجى المحاولة مرة أخرى.', false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
}
|
|
|
315 |
|
316 |
+
isProcessing = false;
|
317 |
+
sendButton.disabled = false;
|
|
|
|
|
318 |
}
|
319 |
|
320 |
function clearChat() {
|
321 |
const chatContainer = document.getElementById('chat-container');
|
322 |
chatContainer.innerHTML = '';
|
|
|
|
|
323 |
}
|
324 |
|
325 |
+
function sendSuggestion(suggestion) {
|
326 |
+
const input = document.getElementById('message-input');
|
327 |
+
input.value = suggestion;
|
328 |
+
sendMessage();
|
329 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
</script>
|
331 |
</body>
|
332 |
+
</html>
|