@helllo-ai/agent-chat-widget 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-chat.staging.js +38 -14
- package/package.json +1 -1
package/agent-chat.staging.js
CHANGED
|
@@ -199,6 +199,7 @@
|
|
|
199
199
|
let customerForm = null
|
|
200
200
|
let sessionId = null
|
|
201
201
|
let customerInfoSubmitted = false
|
|
202
|
+
let firstMessageReceived = false
|
|
202
203
|
|
|
203
204
|
if (captureCustomerInfo) {
|
|
204
205
|
customerForm = document.createElement('div')
|
|
@@ -404,6 +405,7 @@
|
|
|
404
405
|
function connect() {
|
|
405
406
|
if (connected || connecting) return
|
|
406
407
|
connecting = true
|
|
408
|
+
firstMessageReceived = false // Reset when connecting
|
|
407
409
|
const url = resolvedWsUrl
|
|
408
410
|
try {
|
|
409
411
|
ws = new WebSocket(url)
|
|
@@ -422,18 +424,9 @@
|
|
|
422
424
|
// Generate session ID when websocket connects
|
|
423
425
|
sessionId = 'session_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9)
|
|
424
426
|
|
|
425
|
-
//
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
messages.style.display = 'none'
|
|
429
|
-
inputWrap.style.display = 'none'
|
|
430
|
-
// Focus first input
|
|
431
|
-
const nameInput = customerForm.querySelector('#acw-customer-name')
|
|
432
|
-
if (nameInput) setTimeout(() => nameInput.focus(), 100)
|
|
433
|
-
} else {
|
|
434
|
-
messages.style.display = 'flex'
|
|
435
|
-
inputWrap.style.display = 'flex'
|
|
436
|
-
}
|
|
427
|
+
// Don't show customer form yet - wait for first message
|
|
428
|
+
messages.style.display = 'flex'
|
|
429
|
+
inputWrap.style.display = 'flex'
|
|
437
430
|
}
|
|
438
431
|
|
|
439
432
|
ws.onmessage = (event) => {
|
|
@@ -441,10 +434,40 @@
|
|
|
441
434
|
const data = JSON.parse(event.data)
|
|
442
435
|
const text = data.text || data.content || data.message || ''
|
|
443
436
|
const role = data.role || 'assistant'
|
|
444
|
-
if (text)
|
|
437
|
+
if (text) {
|
|
438
|
+
appendMessage(text, role === 'user' ? 'user' : 'bot')
|
|
439
|
+
|
|
440
|
+
// Show customer info form after first bot message (welcome message)
|
|
441
|
+
if (!firstMessageReceived && role !== 'user' && captureCustomerInfo && customerForm && !customerInfoSubmitted) {
|
|
442
|
+
firstMessageReceived = true
|
|
443
|
+
// Small delay to let the message render first
|
|
444
|
+
setTimeout(() => {
|
|
445
|
+
customerForm.style.display = 'flex'
|
|
446
|
+
messages.style.display = 'none'
|
|
447
|
+
inputWrap.style.display = 'none'
|
|
448
|
+
// Focus first input
|
|
449
|
+
const nameInput = customerForm.querySelector('#acw-customer-name')
|
|
450
|
+
if (nameInput) setTimeout(() => nameInput.focus(), 100)
|
|
451
|
+
}, 300)
|
|
452
|
+
}
|
|
453
|
+
}
|
|
445
454
|
} catch (e) {
|
|
446
455
|
// Fallback to raw text
|
|
447
|
-
if (event.data)
|
|
456
|
+
if (event.data) {
|
|
457
|
+
appendMessage(String(event.data), 'bot')
|
|
458
|
+
|
|
459
|
+
// Show customer info form after first bot message (welcome message)
|
|
460
|
+
if (!firstMessageReceived && captureCustomerInfo && customerForm && !customerInfoSubmitted) {
|
|
461
|
+
firstMessageReceived = true
|
|
462
|
+
setTimeout(() => {
|
|
463
|
+
customerForm.style.display = 'flex'
|
|
464
|
+
messages.style.display = 'none'
|
|
465
|
+
inputWrap.style.display = 'none'
|
|
466
|
+
const nameInput = customerForm.querySelector('#acw-customer-name')
|
|
467
|
+
if (nameInput) setTimeout(() => nameInput.focus(), 100)
|
|
468
|
+
}, 300)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
448
471
|
}
|
|
449
472
|
}
|
|
450
473
|
|
|
@@ -475,6 +498,7 @@
|
|
|
475
498
|
updateStatus('Disconnected', false)
|
|
476
499
|
sessionId = null
|
|
477
500
|
customerInfoSubmitted = false
|
|
501
|
+
firstMessageReceived = false
|
|
478
502
|
if (customerForm) {
|
|
479
503
|
customerForm.style.display = 'none'
|
|
480
504
|
const nameInput = customerForm.querySelector('#acw-customer-name')
|