@helllo-ai/agent-chat-widget 0.1.16 → 0.1.17
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 +20 -31
- package/package.json +1 -1
package/agent-chat.staging.js
CHANGED
|
@@ -252,7 +252,7 @@
|
|
|
252
252
|
customerForm.appendChild(phoneField)
|
|
253
253
|
customerForm.appendChild(formActions)
|
|
254
254
|
|
|
255
|
-
|
|
255
|
+
function submitCustomerInfo() {
|
|
256
256
|
const name = nameInput.value.trim()
|
|
257
257
|
const phone = phoneInput.value.trim()
|
|
258
258
|
|
|
@@ -263,44 +263,33 @@
|
|
|
263
263
|
|
|
264
264
|
if (!sessionId) {
|
|
265
265
|
console.error('[AgentChatWidget] No session ID available')
|
|
266
|
+
alert('Session not established. Please wait for connection.')
|
|
266
267
|
return
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
apiBase = apiBase.replace(/^ws/, 'http')
|
|
274
|
-
} else if (apiBase.startsWith('wss://')) {
|
|
275
|
-
apiBase = apiBase.replace(/^wss/, 'https')
|
|
270
|
+
// Ensure WebSocket is connected
|
|
271
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
272
|
+
alert('WebSocket not connected. Please wait for connection.')
|
|
273
|
+
return
|
|
276
274
|
}
|
|
277
|
-
const endpoint = `${apiBase}/api/v1/agent-voice/agents/text-chat/customer-info`
|
|
278
275
|
|
|
279
276
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
customer_name: name,
|
|
289
|
-
}),
|
|
290
|
-
})
|
|
277
|
+
// Send customer info via WebSocket
|
|
278
|
+
ws.send(JSON.stringify({
|
|
279
|
+
type: 'customer_info',
|
|
280
|
+
session_id: sessionId,
|
|
281
|
+
phone_number: phone,
|
|
282
|
+
customer_name: name,
|
|
283
|
+
embed_key: embedKey
|
|
284
|
+
}))
|
|
291
285
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
} else {
|
|
298
|
-
const errorText = await response.text()
|
|
299
|
-
console.error('[AgentChatWidget] Failed to submit customer info:', errorText)
|
|
300
|
-
alert('Failed to submit information. Please try again.')
|
|
301
|
-
}
|
|
286
|
+
// Mark as submitted and show chat interface
|
|
287
|
+
customerInfoSubmitted = true
|
|
288
|
+
customerForm.style.display = 'none'
|
|
289
|
+
messages.style.display = 'flex'
|
|
290
|
+
inputWrap.style.display = 'flex'
|
|
302
291
|
} catch (error) {
|
|
303
|
-
console.error('[AgentChatWidget] Error
|
|
292
|
+
console.error('[AgentChatWidget] Error sending customer info:', error)
|
|
304
293
|
alert('Error submitting information. Please try again.')
|
|
305
294
|
}
|
|
306
295
|
}
|