async_chatbot / templates /index2.html
unknown
going back to older version
6105d5c
Raw History Blame Contribute Delete
1.44 kB
<!DOCTYPE html>
<html>
<head>
<title>Async Chatbot</title>
<script src="/static/script2.js" defer></script>
<!-- <script >
async function sendMessage() {
const inputEl = document.getElementById("userInput");
const statusEl = document.getElementById("status");
const replyEl = document.getElementById("botReply");
const message = inputEl.value.trim();
if (!message) return;
// Update status
statusEl.innerText = "Connecting to service...";
await delay(300);
statusEl.innerText = "Getting data...";
const response = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message })
});
const data = await response.json();
statusEl.innerText = "Operation complete.";
replyEl.innerText = data.reply;
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
</script> -->
</head>
<body>
<h2>Talk to the Bot</h2>
<input type="text" id="userInput" placeholder="Say something..." />
<button onclick="sendMessage()">Send</button>
<p><strong>Status:</strong> <span id="status">Idle</span></p>
<p><strong>Bot:</strong> <span id="botReply"></span></p>
</body>
</html>