@ihoomanai/chat-widget 3.0.12 → 3.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ihoomanai/chat-widget",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "type": "module",
5
5
  "description": "Universal chat support widget for any website - secure Widget ID based initialization",
6
6
  "main": "dist/index.cjs.js",
package/src/types.ts CHANGED
@@ -606,6 +606,7 @@ export type WidgetEvent =
606
606
  | 'connection:change'
607
607
  | 'newConversation'
608
608
  | 'escalation:start'
609
+ | 'escalation:accepted'
609
610
  | 'escalation:end'
610
611
  | 'survey:shown'
611
612
  | 'survey:submitted'
package/src/widget.ts CHANGED
@@ -17,7 +17,7 @@ import type {
17
17
  WidgetView,
18
18
  } from './types';
19
19
 
20
- const VERSION = '3.0.12';
20
+ const VERSION = '3.0.13';
21
21
  const STORAGE_PREFIX = 'ihooman_chat_';
22
22
  const DEFAULT_SERVER_URL = 'https://api.ihooman.ai';
23
23
 
@@ -1498,17 +1498,55 @@ function connectWebSocket(chatEndpoint?: string): void {
1498
1498
  } else if (data.type === 'message') {
1499
1499
  hideTyping();
1500
1500
  const sender = data.sender === 'user' ? 'user' : 'bot';
1501
+
1502
+ // Check if this is an agent-related system message
1503
+ const metadata = data.metadata || {};
1504
+ if (metadata.agent_accepted) {
1505
+ // Agent has accepted the escalation - update status
1506
+ isLiveAgentMode = true;
1507
+ updateStatusBar('connected', '🟢 Connected to live agent');
1508
+ emit('escalation:accepted', { type: 'live_agent' });
1509
+ }
1510
+ if (metadata.closed_by_agent) {
1511
+ // Agent has closed the conversation - return to AI mode
1512
+ isLiveAgentMode = false;
1513
+ stopLiveAgentPolling();
1514
+ updateStatusBar('hidden');
1515
+ emit('escalation:end', { type: 'live_agent' });
1516
+ }
1517
+
1518
+ // Track message received analytics
1519
+ trackAnalyticsEvent('message_received', {
1520
+ session_id: state.sessionId,
1521
+ visitor_id: state.visitorId,
1522
+ sender: data.sender,
1523
+ is_system_message: metadata.is_system_message || false,
1524
+ });
1525
+
1501
1526
  addMessage(data.content, sender, {
1502
1527
  confidence: data.confidence,
1503
1528
  agent_name: data.agent_name,
1504
1529
  escalation_offered: data.escalation_offered,
1505
1530
  escalated: data.escalated,
1506
1531
  quick_replies: data.quick_replies,
1532
+ ...metadata,
1507
1533
  });
1508
1534
  } else if (data.type === 'typing') {
1509
1535
  data.is_typing ? showTyping() : hideTyping();
1510
1536
  } else if (data.type === 'pong') {
1511
1537
  // Heartbeat response
1538
+ } else if (data.type === 'agent_status') {
1539
+ // Handle agent status updates
1540
+ if (data.status === 'connected') {
1541
+ isLiveAgentMode = true;
1542
+ updateStatusBar('connected', '🟢 Connected to live agent');
1543
+ emit('escalation:accepted', { type: 'live_agent' });
1544
+ } else if (data.status === 'disconnected') {
1545
+ isLiveAgentMode = false;
1546
+ stopLiveAgentPolling();
1547
+ updateStatusBar('hidden');
1548
+ emit('escalation:end', { type: 'live_agent' });
1549
+ }
1512
1550
  } else if (data.type === 'error') {
1513
1551
  console.error('WebSocket server error:', data.message);
1514
1552
  emit('error', { message: data.message });