@helllo-ai/agent-chat-widget 0.1.15 → 0.1.16
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 +43 -29
- package/package.json +1 -1
package/agent-chat.staging.js
CHANGED
|
@@ -421,9 +421,7 @@
|
|
|
421
421
|
connecting = false
|
|
422
422
|
updateStatus('Connected', true)
|
|
423
423
|
|
|
424
|
-
//
|
|
425
|
-
sessionId = 'session_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9)
|
|
426
|
-
|
|
424
|
+
// Session ID will be received from connection_established message
|
|
427
425
|
// Don't show customer form yet - wait for first message
|
|
428
426
|
messages.style.display = 'flex'
|
|
429
427
|
inputWrap.style.display = 'flex'
|
|
@@ -432,41 +430,57 @@
|
|
|
432
430
|
ws.onmessage = (event) => {
|
|
433
431
|
try {
|
|
434
432
|
const data = JSON.parse(event.data)
|
|
433
|
+
|
|
434
|
+
// Handle connection_established message
|
|
435
|
+
if (data.type === 'connection_established') {
|
|
436
|
+
// Extract session_id from connection message
|
|
437
|
+
if (data.session_id) {
|
|
438
|
+
sessionId = data.session_id
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Display welcome message if provided
|
|
442
|
+
if (data.welcome_message) {
|
|
443
|
+
appendMessage(data.welcome_message, 'bot')
|
|
444
|
+
|
|
445
|
+
// Show customer info form after welcome message
|
|
446
|
+
if (!firstMessageReceived && captureCustomerInfo && customerForm && !customerInfoSubmitted) {
|
|
447
|
+
firstMessageReceived = true
|
|
448
|
+
// Small delay to let the message render first
|
|
449
|
+
setTimeout(() => {
|
|
450
|
+
customerForm.style.display = 'flex'
|
|
451
|
+
messages.style.display = 'none'
|
|
452
|
+
inputWrap.style.display = 'none'
|
|
453
|
+
// Focus first input
|
|
454
|
+
const nameInput = customerForm.querySelector('#acw-customer-name')
|
|
455
|
+
if (nameInput) setTimeout(() => nameInput.focus(), 100)
|
|
456
|
+
}, 300)
|
|
457
|
+
}
|
|
458
|
+
} else {
|
|
459
|
+
// No welcome message, but still show form if needed
|
|
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
|
+
}, 100)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return // Don't process as regular message
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Handle regular chat messages
|
|
435
475
|
const text = data.text || data.content || data.message || ''
|
|
436
476
|
const role = data.role || 'assistant'
|
|
437
477
|
if (text) {
|
|
438
478
|
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
479
|
}
|
|
454
480
|
} catch (e) {
|
|
455
481
|
// Fallback to raw text
|
|
456
482
|
if (event.data) {
|
|
457
483
|
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
484
|
}
|
|
471
485
|
}
|
|
472
486
|
}
|