@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.
@@ -252,7 +252,7 @@
252
252
  customerForm.appendChild(phoneField)
253
253
  customerForm.appendChild(formActions)
254
254
 
255
- async function submitCustomerInfo() {
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
- const baseUrl = voiceServiceUrl || apiBaseUrl || new URL(document.currentScript?.src || window.location.href).origin
270
- let apiBase = (baseUrl || '').replace(/\/$/, '')
271
- // Convert ws:// to http:// for HTTP requests
272
- if (apiBase.startsWith('ws://')) {
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
- const response = await fetch(endpoint, {
281
- method: 'POST',
282
- headers: {
283
- 'Content-Type': 'application/json',
284
- },
285
- body: JSON.stringify({
286
- session_id: sessionId,
287
- phone_number: phone,
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
- if (response.ok) {
293
- customerInfoSubmitted = true
294
- customerForm.style.display = 'none'
295
- messages.style.display = 'flex'
296
- inputWrap.style.display = 'flex'
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 submitting customer info:', error)
292
+ console.error('[AgentChatWidget] Error sending customer info:', error)
304
293
  alert('Error submitting information. Please try again.')
305
294
  }
306
295
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helllo-ai/agent-chat-widget",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Bot Swarm Agent Chat Widget - Embeddable chat widget for AI agents",
5
5
  "main": "agent-chat.latest.js",
6
6
  "files": [