Skip to content

Commit e56f61e

Browse files
authored
Add files via upload
0 parents  commit e56f61e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<title>Indicatiehulp Webchat</title>
7+
<style>
8+
body { font-family: sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; height: 100vh; }
9+
#chat { flex: 1; overflow-y: auto; padding: 1em; background: #f4f4f4; }
10+
#input-form { display: flex; padding: 1em; background: #fff; }
11+
input { flex: 1; padding: 0.5em; font-size: 1em; }
12+
button { padding: 0.5em 1em; }
13+
.user { font-weight: bold; margin-top: 1em; }
14+
.agent { margin-left: 1em; color: #333; }
15+
</style>
16+
</head>
17+
<body>
18+
<div id="chat"></div>
19+
<form id="input-form">
20+
<input type="text" id="user-input" placeholder="Typ hier je vraag..." autocomplete="off" />
21+
<button type="submit">Verzend</button>
22+
</form>
23+
<script src="script.js"></script>
24+
</body>
25+
</html>

script.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const chat = document.getElementById("chat");
2+
const form = document.getElementById("input-form");
3+
const input = document.getElementById("user-input");
4+
5+
form.addEventListener("submit", async (e) => {
6+
e.preventDefault();
7+
const message = input.value.trim();
8+
if (!message) return;
9+
10+
appendMessage("Gebruiker", message);
11+
input.value = "";
12+
13+
try {
14+
const response = await fetch("https://indicatiehulp-fn-py.azurewebsites.net/api/chatproxy", {
15+
method: "POST",
16+
headers: { "Content-Type": "application/json" },
17+
body: JSON.stringify({ message })
18+
});
19+
20+
const text = await response.text();
21+
appendMessage("Agent", text);
22+
} catch (err) {
23+
appendMessage("Agent", "Er ging iets mis.");
24+
console.error(err);
25+
}
26+
});
27+
28+
function appendMessage(sender, text) {
29+
const msg = document.createElement("div");
30+
msg.innerHTML = `<div class="user">${sender}:</div><div class="agent">${text}</div>`;
31+
chat.appendChild(msg);
32+
chat.scrollTop = chat.scrollHeight;
33+
}

0 commit comments

Comments
 (0)