@@ -10,13 +10,16 @@ window.onload = () => {
1010 Welkom bij de <strong>AI Indicatiehulp</strong>!<br>
1111 Ik ben jouw digitale adviseur voor:<br>
1212 het stellen van de juiste indicatie en het opstellen van een conceptadvies voor de zorgexpert (Kim Brand).<br><br>
13+
1314 <strong>Kies een optie om te starten:</strong><br>
1415 1. In kaart brengen cliëntsituatie<br>
1516 2. Indicatiestelling extramuraal (zorg thuis)<br>
1617 3. Indicatiestelling intramuraal (verpleeghuis)<br><br>
18+
1719 Wil je direct een indicatieadvies laten opstellen? Dan heb ik meer informatie nodig over de cliënt.<br>
1820 Geef bij voorkeur ook je naam en een e-mailadres of telefoonnummer,<br>
1921 zodat we het conceptadvies voor beoordeling kunnen indienen.<br><br>
22+
2023 <em>Met welke optie wil je verder?</em>
2124 ` ;
2225 appendFormattedMessage ( "agent-message" , welkomstHTML ) ;
@@ -29,4 +32,50 @@ form.addEventListener("submit", async (e) => {
2932
3033 appendMessage ( "user-message" , message ) ;
3134 input . value = "" ;
32- streamOutput . textContent =
35+ streamOutput . textContent = "" ;
36+
37+ try {
38+ const response = await fetch ( "https://chatproxy.azurewebsites.net/api/chatproxy" , {
39+ method : "POST" ,
40+ headers : { "Content-Type" : "application/json" } ,
41+ body : JSON . stringify ( { message, thread_id : threadId } )
42+ } ) ;
43+
44+ const data = await response . json ( ) ;
45+ threadId = data . thread_id ;
46+
47+ } catch ( err ) {
48+ appendMessage ( "agent-message" , "Er ging iets mis bij het ophalen van een antwoord." ) ;
49+ console . error ( "Fout in fetch:" , err ) ;
50+ }
51+ } ) ;
52+
53+ function appendMessage ( cssClass , text ) {
54+ const msg = document . createElement ( "div" ) ;
55+ msg . classList . add ( "message" , cssClass ) ;
56+ msg . textContent = text ;
57+ chat . appendChild ( msg ) ;
58+ chat . scrollTop = chat . scrollHeight ;
59+ }
60+
61+ function appendFormattedMessage ( cssClass , htmlContent ) {
62+ const msg = document . createElement ( "div" ) ;
63+ msg . classList . add ( "message" , cssClass ) ;
64+ msg . innerHTML = htmlContent ;
65+ chat . appendChild ( msg ) ;
66+ chat . scrollTop = chat . scrollHeight ;
67+ }
68+
69+ // ✅ SignalR verbinden en tokens verwerken
70+ const connection = new signalR . HubConnectionBuilder ( )
71+ . withUrl ( "https://chatproxy.azurewebsites.net/api" )
72+ . build ( ) ;
73+
74+ connection . on ( "newToken" , token => {
75+ streamOutput . textContent += token + " " ;
76+ chat . scrollTop = chat . scrollHeight ;
77+ } ) ;
78+
79+ connection . start ( )
80+ . then ( ( ) => console . log ( "Verbonden met SignalR" ) )
81+ . catch ( err => console . error ( "SignalR fout:" , err ) ) ;
0 commit comments