@webex/contact-center 3.12.0-next.73 → 3.12.0-next.75

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.
Files changed (188) hide show
  1. package/AGENTS.md +438 -0
  2. package/ai-docs/README.md +131 -0
  3. package/ai-docs/RULES.md +455 -0
  4. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  5. package/ai-docs/patterns/testing-patterns.md +480 -0
  6. package/ai-docs/patterns/typescript-patterns.md +365 -0
  7. package/ai-docs/templates/README.md +102 -0
  8. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  9. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  10. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  11. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  12. package/ai-docs/templates/new-method/00-master.md +80 -0
  13. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  14. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  15. package/ai-docs/templates/new-method/03-tests.md +201 -0
  16. package/ai-docs/templates/new-method/04-validation.md +141 -0
  17. package/ai-docs/templates/new-service/00-master.md +109 -0
  18. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  19. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  20. package/ai-docs/templates/new-service/03-integration.md +178 -0
  21. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  22. package/ai-docs/templates/new-service/05-validation.md +145 -0
  23. package/dist/cc.js +53 -38
  24. package/dist/cc.js.map +1 -1
  25. package/dist/config.js +6 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/constants.js +14 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/index.js +13 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/metrics/behavioral-events.js +26 -0
  32. package/dist/metrics/behavioral-events.js.map +1 -1
  33. package/dist/metrics/constants.js +9 -3
  34. package/dist/metrics/constants.js.map +1 -1
  35. package/dist/services/ApiAiAssistant.js +74 -3
  36. package/dist/services/ApiAiAssistant.js.map +1 -1
  37. package/dist/services/config/Util.js +2 -2
  38. package/dist/services/config/Util.js.map +1 -1
  39. package/dist/services/config/types.js +25 -9
  40. package/dist/services/config/types.js.map +1 -1
  41. package/dist/services/core/Utils.js +74 -27
  42. package/dist/services/core/Utils.js.map +1 -1
  43. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  44. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  45. package/dist/services/core/websocket/types.js.map +1 -1
  46. package/dist/services/index.js +1 -1
  47. package/dist/services/index.js.map +1 -1
  48. package/dist/services/task/Task.js +688 -0
  49. package/dist/services/task/Task.js.map +1 -0
  50. package/dist/services/task/TaskFactory.js +45 -0
  51. package/dist/services/task/TaskFactory.js.map +1 -0
  52. package/dist/services/task/TaskManager.js +725 -612
  53. package/dist/services/task/TaskManager.js.map +1 -1
  54. package/dist/services/task/TaskUtils.js +162 -26
  55. package/dist/services/task/TaskUtils.js.map +1 -1
  56. package/dist/services/task/constants.js +6 -1
  57. package/dist/services/task/constants.js.map +1 -1
  58. package/dist/services/task/digital/Digital.js +77 -0
  59. package/dist/services/task/digital/Digital.js.map +1 -0
  60. package/dist/services/task/state-machine/TaskStateMachine.js +837 -0
  61. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  62. package/dist/services/task/state-machine/actions.js +543 -0
  63. package/dist/services/task/state-machine/actions.js.map +1 -0
  64. package/dist/services/task/state-machine/constants.js +161 -0
  65. package/dist/services/task/state-machine/constants.js.map +1 -0
  66. package/dist/services/task/state-machine/guards.js +340 -0
  67. package/dist/services/task/state-machine/guards.js.map +1 -0
  68. package/dist/services/task/state-machine/index.js +53 -0
  69. package/dist/services/task/state-machine/index.js.map +1 -0
  70. package/dist/services/task/state-machine/types.js +54 -0
  71. package/dist/services/task/state-machine/types.js.map +1 -0
  72. package/dist/services/task/state-machine/uiControlsComputer.js +553 -0
  73. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  74. package/dist/services/task/taskDataNormalizer.js +99 -0
  75. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  76. package/dist/services/task/types.js +168 -16
  77. package/dist/services/task/types.js.map +1 -1
  78. package/dist/services/task/voice/Voice.js +1042 -0
  79. package/dist/services/task/voice/Voice.js.map +1 -0
  80. package/dist/services/task/voice/WebRTC.js +149 -0
  81. package/dist/services/task/voice/WebRTC.js.map +1 -0
  82. package/dist/types/cc.d.ts +19 -18
  83. package/dist/types/config.d.ts +6 -0
  84. package/dist/types/constants.d.ts +14 -1
  85. package/dist/types/index.d.ts +11 -5
  86. package/dist/types/metrics/constants.d.ts +7 -1
  87. package/dist/types/services/ApiAiAssistant.d.ts +11 -3
  88. package/dist/types/services/config/types.d.ts +113 -9
  89. package/dist/types/services/core/Utils.d.ts +23 -10
  90. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  91. package/dist/types/services/core/websocket/types.d.ts +1 -1
  92. package/dist/types/services/index.d.ts +1 -1
  93. package/dist/types/services/task/Task.d.ts +157 -0
  94. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  95. package/dist/types/services/task/TaskUtils.d.ts +46 -2
  96. package/dist/types/services/task/constants.d.ts +5 -0
  97. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  98. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1144 -0
  99. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  100. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  101. package/dist/types/services/task/state-machine/guards.d.ts +90 -0
  102. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  103. package/dist/types/services/task/state-machine/types.d.ts +267 -0
  104. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  105. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  106. package/dist/types/services/task/types.d.ts +551 -78
  107. package/dist/types/services/task/voice/Voice.d.ts +184 -0
  108. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  109. package/dist/types/types.d.ts +92 -0
  110. package/dist/types/webex.d.ts +1 -0
  111. package/dist/types.js +85 -0
  112. package/dist/types.js.map +1 -1
  113. package/dist/webex.js +14 -2
  114. package/dist/webex.js.map +1 -1
  115. package/package.json +15 -12
  116. package/src/cc.ts +63 -43
  117. package/src/config.ts +6 -0
  118. package/src/constants.ts +14 -1
  119. package/src/index.ts +14 -5
  120. package/src/metrics/ai-docs/AGENTS.md +348 -0
  121. package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
  122. package/src/metrics/behavioral-events.ts +28 -0
  123. package/src/metrics/constants.ts +9 -4
  124. package/src/services/ApiAiAssistant.ts +104 -3
  125. package/src/services/agent/ai-docs/AGENTS.md +238 -0
  126. package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
  127. package/src/services/ai-docs/AGENTS.md +384 -0
  128. package/src/services/config/Util.ts +2 -2
  129. package/src/services/config/ai-docs/AGENTS.md +253 -0
  130. package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
  131. package/src/services/config/types.ts +116 -10
  132. package/src/services/core/Utils.ts +85 -34
  133. package/src/services/core/ai-docs/AGENTS.md +379 -0
  134. package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
  135. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  136. package/src/services/core/websocket/types.ts +1 -1
  137. package/src/services/index.ts +1 -1
  138. package/src/services/task/Task.ts +837 -0
  139. package/src/services/task/TaskFactory.ts +55 -0
  140. package/src/services/task/TaskManager.ts +738 -697
  141. package/src/services/task/TaskUtils.ts +205 -25
  142. package/src/services/task/ai-docs/AGENTS.md +455 -0
  143. package/src/services/task/ai-docs/ARCHITECTURE.md +585 -0
  144. package/src/services/task/constants.ts +5 -0
  145. package/src/services/task/digital/Digital.ts +95 -0
  146. package/src/services/task/state-machine/TaskStateMachine.ts +1077 -0
  147. package/src/services/task/state-machine/actions.ts +685 -0
  148. package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
  149. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
  150. package/src/services/task/state-machine/constants.ts +172 -0
  151. package/src/services/task/state-machine/guards.ts +406 -0
  152. package/src/services/task/state-machine/index.ts +28 -0
  153. package/src/services/task/state-machine/types.ts +241 -0
  154. package/src/services/task/state-machine/uiControlsComputer.ts +867 -0
  155. package/src/services/task/taskDataNormalizer.ts +137 -0
  156. package/src/services/task/types.ts +654 -85
  157. package/src/services/task/voice/Voice.ts +1267 -0
  158. package/src/services/task/voice/WebRTC.ts +187 -0
  159. package/src/types.ts +112 -1
  160. package/src/utils/AGENTS.md +276 -0
  161. package/src/webex.js +2 -0
  162. package/test/unit/spec/cc.ts +133 -3
  163. package/test/unit/spec/logger-proxy.ts +70 -0
  164. package/test/unit/spec/services/ApiAiAssistant.ts +122 -17
  165. package/test/unit/spec/services/WebCallingService.ts +7 -1
  166. package/test/unit/spec/services/config/index.ts +27 -27
  167. package/test/unit/spec/services/core/Utils.ts +335 -1
  168. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  169. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  170. package/test/unit/spec/services/task/Task.ts +477 -0
  171. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  172. package/test/unit/spec/services/task/TaskManager.ts +821 -1936
  173. package/test/unit/spec/services/task/TaskUtils.ts +206 -0
  174. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  175. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1825 -0
  176. package/test/unit/spec/services/task/state-machine/guards.ts +479 -0
  177. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  178. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +2020 -0
  179. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  180. package/test/unit/spec/services/task/voice/Voice.ts +631 -0
  181. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  182. package/umd/contact-center.min.js +2 -2
  183. package/umd/contact-center.min.js.map +1 -1
  184. package/dist/services/task/index.js +0 -1530
  185. package/dist/services/task/index.js.map +0 -1
  186. package/dist/types/services/task/index.d.ts +0 -650
  187. package/src/services/task/index.ts +0 -1806
  188. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -352,6 +352,34 @@ const eventTaxonomyMap: Record<string, BehavioralEventTaxonomy> = {
352
352
  verb: 'fail',
353
353
  },
354
354
 
355
+ // Conference Exit
356
+ [METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_SUCCESS]: {
357
+ product,
358
+ agent: 'user',
359
+ target: 'task_conference_exit',
360
+ verb: 'complete',
361
+ },
362
+ [METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_FAILED]: {
363
+ product,
364
+ agent: 'user',
365
+ target: 'task_conference_exit',
366
+ verb: 'fail',
367
+ },
368
+
369
+ // Switch Call
370
+ [METRIC_EVENT_NAMES.TASK_SWITCH_CALL_SUCCESS]: {
371
+ product,
372
+ agent: 'user',
373
+ target: 'task_switch_call',
374
+ verb: 'complete',
375
+ },
376
+ [METRIC_EVENT_NAMES.TASK_SWITCH_CALL_FAILED]: {
377
+ product,
378
+ agent: 'user',
379
+ target: 'task_switch_call',
380
+ verb: 'fail',
381
+ },
382
+
355
383
  // upload logs
356
384
  [METRIC_EVENT_NAMES.UPLOAD_LOGS_SUCCESS]: {
357
385
  product,
@@ -129,6 +129,10 @@ export const METRIC_EVENT_NAMES = {
129
129
  TASK_CONFERENCE_END_FAILED: 'Task Conference End Failed',
130
130
  TASK_CONFERENCE_TRANSFER_SUCCESS: 'Task Conference Transfer Success',
131
131
  TASK_CONFERENCE_TRANSFER_FAILED: 'Task Conference Transfer Failed',
132
+ TASK_CONFERENCE_EXIT_SUCCESS: 'Task Conference Exit Success',
133
+ TASK_CONFERENCE_EXIT_FAILED: 'Task Conference Exit Failed',
134
+ TASK_SWITCH_CALL_SUCCESS: 'Task Switch Call Success',
135
+ TASK_SWITCH_CALL_FAILED: 'Task Switch Call Failed',
132
136
 
133
137
  TASK_OUTDIAL_SUCCESS: 'Task Outdial Success',
134
138
  TASK_OUTDIAL_FAILED: 'Task Outdial Failed',
@@ -138,11 +142,10 @@ export const METRIC_EVENT_NAMES = {
138
142
  WEBSOCKET_DEREGISTER_SUCCESS: 'Websocket Deregister Success',
139
143
  WEBSOCKET_DEREGISTER_FAIL: 'Websocket Deregister Failed',
140
144
 
141
- // WebSocket message events
142
- WEBSOCKET_EVENT_RECEIVED: 'Websocket Event Received',
143
-
144
145
  AGENT_DEVICE_TYPE_UPDATE_SUCCESS: 'Agent Device Type Update Success',
145
146
  AGENT_DEVICE_TYPE_UPDATE_FAILED: 'Agent Device Type Update Failed',
147
+ // WebSocket message events
148
+ WEBSOCKET_EVENT_RECEIVED: 'Websocket Event Received',
146
149
 
147
150
  // EntryPoint API Events
148
151
  ENTRYPOINT_FETCH_SUCCESS: 'Entrypoint Fetch Success',
@@ -168,9 +171,11 @@ export const METRIC_EVENT_NAMES = {
168
171
  CAMPAIGN_PREVIEW_REMOVE_SUCCESS: 'Campaign Preview Remove Success',
169
172
  CAMPAIGN_PREVIEW_REMOVE_FAILED: 'Campaign Preview Remove Failed',
170
173
 
171
- // AI Assistant transcript events
174
+ // AI Assistant Transcript events
172
175
  AI_ASSISTANT_SEND_EVENT_SUCCESS: 'AI Assistant Send Event Success',
173
176
  AI_ASSISTANT_SEND_EVENT_FAILED: 'AI Assistant Send Event Failed',
177
+ AI_ASSISTANT_GET_SUGGESTED_RESPONSE_SUCCESS: 'AI Assistant Get Suggested Response Success',
178
+ AI_ASSISTANT_GET_SUGGESTED_RESPONSE_FAILED: 'AI Assistant Get Suggested Response Failed',
174
179
  AI_ASSISTANT_FETCH_HISTORIC_TRANSCRIPTS_SUCCESS:
175
180
  'AI Assistant Fetch Historic Transcripts Success',
176
181
  AI_ASSISTANT_FETCH_HISTORIC_TRANSCRIPTS_FAILED: 'AI Assistant Fetch Historic Transcripts Failed',
@@ -1,3 +1,4 @@
1
+ import {v4 as uuidv4} from 'uuid';
1
2
  import LoggerProxy from '../logger-proxy';
2
3
  import MetricsManager from '../metrics/MetricsManager';
3
4
  import {METRIC_EVENT_NAMES} from '../metrics/constants';
@@ -10,6 +11,7 @@ import {
10
11
  AIAssistantEventType,
11
12
  AIAssistantEventName,
12
13
  HistoricTranscriptsResponse,
14
+ SuggestedResponseParams,
13
15
  } from '../types';
14
16
  import {getErrorDetails} from './core/Utils';
15
17
  import {
@@ -27,7 +29,7 @@ import {AIFeatureFlags} from './config/types';
27
29
  export class ApiAIAssistant {
28
30
  private webex: WebexSDK;
29
31
  private metricsManager: MetricsManager;
30
- public aiFeature: AIFeatureFlags;
32
+ private aiFeature: AIFeatureFlags;
31
33
 
32
34
  constructor(webex: WebexSDK) {
33
35
  this.webex = webex;
@@ -83,13 +85,16 @@ export class ApiAIAssistant {
83
85
  interactionId: string,
84
86
  eventType: AIAssistantEventType,
85
87
  eventName: AIAssistantEventName,
86
- action: TranscriptAction
88
+ action?: TranscriptAction,
89
+ context?: string,
90
+ languageCode?: string,
91
+ trackingId?: string
87
92
  ): Promise<Record<string, unknown>> {
88
93
  LoggerProxy.info('Sending event', {
89
94
  module: CC_FILE,
90
95
  method: METHODS.SEND_EVENT,
91
96
  interactionId,
92
- data: {eventType, eventName, action},
97
+ data: {eventType, eventName, action, context},
93
98
  });
94
99
  this.metricsManager.timeEvent([
95
100
  METRIC_EVENT_NAMES.AI_ASSISTANT_SEND_EVENT_SUCCESS,
@@ -112,7 +117,10 @@ export class ApiAIAssistant {
112
117
  data: {
113
118
  interactionId,
114
119
  action,
120
+ context,
115
121
  actionTimeStamp: String(Date.now()),
122
+ languageCode,
123
+ trackingId,
116
124
  },
117
125
  },
118
126
  },
@@ -143,6 +151,98 @@ export class ApiAIAssistant {
143
151
  }
144
152
  }
145
153
 
154
+ /**
155
+ * Requests a suggested response for an interaction.
156
+ *
157
+ * @param params - Suggestion request parameters
158
+ * @returns HTTP response body from the AI Assistant event API
159
+ * @public
160
+ */
161
+ public async getSuggestedResponse(params: SuggestedResponseParams): Promise<any> {
162
+ const {agentId, interactionId, context} = params;
163
+ const trimmedContext = context?.trim();
164
+ const languageCode = params.languageCode ?? 'en';
165
+ const trackingId = `WX_CC_SDK_${uuidv4()}`;
166
+ const eventName = trimmedContext
167
+ ? AIAssistantEventName.ADD_SUGGESTIONS_EXTRA_CONTEXT
168
+ : AIAssistantEventName.GET_SUGGESTIONS;
169
+
170
+ const loggerContext = {
171
+ module: CC_FILE,
172
+ method: METHODS.GET_SUGGESTED_RESPONSE,
173
+ interactionId,
174
+ trackingId,
175
+ data: {eventName},
176
+ };
177
+
178
+ LoggerProxy.info('Requesting suggested response', loggerContext);
179
+
180
+ this.metricsManager.timeEvent([
181
+ METRIC_EVENT_NAMES.AI_ASSISTANT_GET_SUGGESTED_RESPONSE_SUCCESS,
182
+ METRIC_EVENT_NAMES.AI_ASSISTANT_GET_SUGGESTED_RESPONSE_FAILED,
183
+ ]);
184
+
185
+ try {
186
+ if (!this.aiFeature?.suggestedResponses?.enable) {
187
+ const {error: detailedError} = getErrorDetails(
188
+ new Error('SUGGESTED_RESPONSES_NOT_ENABLED'),
189
+ METHODS.GET_SUGGESTED_RESPONSE,
190
+ CC_FILE
191
+ );
192
+ throw detailedError;
193
+ }
194
+
195
+ const orgId = this.webex.credentials.getOrgId();
196
+
197
+ const response = await this.sendEvent(
198
+ agentId,
199
+ interactionId,
200
+ AIAssistantEventType.CUSTOM_EVENT,
201
+ eventName,
202
+ undefined,
203
+ trimmedContext,
204
+ languageCode,
205
+ trackingId
206
+ );
207
+
208
+ this.metricsManager.trackEvent(
209
+ METRIC_EVENT_NAMES.AI_ASSISTANT_GET_SUGGESTED_RESPONSE_SUCCESS,
210
+ {
211
+ agentId,
212
+ orgId,
213
+ interactionId,
214
+ eventName,
215
+ trackingId,
216
+ context,
217
+ },
218
+ ['operational']
219
+ );
220
+ LoggerProxy.log('Suggested response request succeeded', loggerContext);
221
+
222
+ return response;
223
+ } catch (error) {
224
+ LoggerProxy.error('Suggested response request failed', {...loggerContext, error});
225
+ this.metricsManager.trackEvent(
226
+ METRIC_EVENT_NAMES.AI_ASSISTANT_GET_SUGGESTED_RESPONSE_FAILED,
227
+ {
228
+ agentId,
229
+ interactionId,
230
+ trackingId,
231
+ eventName,
232
+ error: error instanceof Error ? error.message : String(error),
233
+ },
234
+ ['operational']
235
+ );
236
+
237
+ const {error: detailedError} = getErrorDetails(
238
+ error,
239
+ METHODS.GET_SUGGESTED_RESPONSE,
240
+ CC_FILE
241
+ );
242
+ throw detailedError;
243
+ }
244
+ }
245
+
146
246
  /**
147
247
  * Fetches historic transcripts for an interaction.
148
248
  * This API is allowed only when real-time transcription feature is enabled.
@@ -201,6 +301,7 @@ export class ApiAIAssistant {
201
301
  },
202
302
  ['operational']
203
303
  );
304
+
204
305
  if (error instanceof Error) {
205
306
  throw error;
206
307
  }
@@ -0,0 +1,238 @@
1
+ # Agent Service - AI Agent Guide
2
+
3
+ > **Purpose**: Manage agent lifecycle including login, logout, state changes, and buddy agent queries.
4
+
5
+ ---
6
+
7
+ ## Quick Start
8
+
9
+ ```typescript
10
+ const cc = webex.cc;
11
+
12
+ // Register and login
13
+ const profile = await cc.register();
14
+ await cc.stationLogin({
15
+ teamId: profile.teams[0].teamId,
16
+ loginOption: 'BROWSER',
17
+ });
18
+
19
+ // Set state to Available
20
+ await cc.setAgentState({
21
+ state: 'Available',
22
+ auxCodeId: '0',
23
+ });
24
+
25
+ // Get available agents for transfer
26
+ const buddies = await cc.getBuddyAgents({
27
+ state: 'Available',
28
+ mediaType: 'telephony',
29
+ });
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Key Capabilities
35
+
36
+ - **Station Login**: Login with browser (WebRTC), extension, or dial number
37
+ - **Station Logout**: Logout from current station with reason
38
+ - **State Management**: Toggle between Available/Idle states with aux codes
39
+ - **Buddy Agents**: Query available agents for consult/transfer
40
+ - **Silent Relogin**: Automatic re-authentication on reconnection
41
+
42
+ ---
43
+
44
+ ## API Reference
45
+
46
+ ### Login Options
47
+
48
+ | Option | Description | Requires dialNumber |
49
+ |--------|-------------|---------------------|
50
+ | `BROWSER` | WebRTC softphone in browser | No |
51
+ | `EXTENSION` | Desk phone extension | Yes |
52
+ | `AGENT_DN` | Direct dial number | Yes |
53
+
54
+ ### Methods
55
+
56
+ #### `cc.stationLogin(params)`
57
+
58
+ Login agent to a station.
59
+
60
+ **Parameters**:
61
+ - `teamId` (string): Team to login to
62
+ - `loginOption` ('BROWSER' | 'EXTENSION' | 'AGENT_DN'): Device type
63
+ - `dialNumber` (string, optional): Required for EXTENSION/AGENT_DN
64
+
65
+ **Returns**: `Promise<StationLoginResponse>`
66
+
67
+ **Example**:
68
+ ```typescript
69
+ // Browser login
70
+ const response = await cc.stationLogin({
71
+ teamId: 'team-123',
72
+ loginOption: 'BROWSER',
73
+ });
74
+
75
+ // Extension login
76
+ const response = await cc.stationLogin({
77
+ teamId: 'team-123',
78
+ loginOption: 'EXTENSION',
79
+ dialNumber: '1234',
80
+ });
81
+ ```
82
+
83
+ ---
84
+
85
+ #### `cc.stationLogout(params)`
86
+
87
+ Logout agent from station.
88
+
89
+ **Parameters**:
90
+ - `logoutReason` (string, optional): 'User requested logout' | 'Inactivity Logout' | 'User requested agent profile update'
91
+
92
+ **Returns**: `Promise<StationLogoutResponse>`
93
+
94
+ **Example**:
95
+ ```typescript
96
+ await cc.stationLogout({
97
+ logoutReason: 'User requested logout',
98
+ });
99
+ ```
100
+
101
+ ---
102
+
103
+ #### `cc.setAgentState(params)`
104
+
105
+ Change agent state (Available/Idle).
106
+
107
+ **Parameters**:
108
+ - `state` ('Available' | 'Idle'): New state
109
+ - `auxCodeId` (string): Auxiliary code ID
110
+ - `lastStateChangeReason` (string, optional): Reason for change
111
+ - `agentId` (string, optional): Agent ID (defaults to current agent)
112
+
113
+ **Returns**: `Promise<SetStateResponse>`
114
+
115
+ **Example**:
116
+ ```typescript
117
+ // Go Available
118
+ await cc.setAgentState({
119
+ state: 'Available',
120
+ auxCodeId: '0',
121
+ });
122
+
123
+ // Go to Idle with specific code
124
+ await cc.setAgentState({
125
+ state: 'Idle',
126
+ auxCodeId: 'break-code-123',
127
+ lastStateChangeReason: 'Coffee break',
128
+ });
129
+ ```
130
+
131
+ ---
132
+
133
+ #### `cc.getBuddyAgents(params)`
134
+
135
+ Get list of agents for consult/transfer.
136
+
137
+ **Parameters**:
138
+ - `state` (string, optional): Filter by state ('Available', 'Idle')
139
+ - `mediaType` (string): Media type filter ('telephony', 'chat', 'social', 'email')
140
+ **Returns**: `Promise<BuddyAgentsResponse>`
141
+
142
+ **Example**:
143
+ ```typescript
144
+ const response = await cc.getBuddyAgents({
145
+ state: 'Available',
146
+ mediaType: 'telephony',
147
+ });
148
+
149
+ response.data.agentList.forEach(agent => {
150
+ console.log(`${agent.agentName} (${agent.state})`);
151
+ });
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Events
157
+
158
+ | Event | Type | Description |
159
+ |-------|------|-------------|
160
+ | `agent:stationLoginSuccess` | `StationLoginSuccessResponse` | Login succeeded |
161
+ | `agent:stationLoginFailed` | Error | Login failed |
162
+ | `agent:logoutSuccess` | `LogoutSuccess` | Logout succeeded |
163
+ | `agent:logoutFailed` | Error | Logout failed |
164
+ | `agent:stateChange` | `StateChangeSuccess` | State changed (any source) |
165
+ | `agent:stateChangeSuccess` | `StateChangeSuccess` | State change succeeded |
166
+ | `agent:stateChangeFailed` | Error | State change failed |
167
+ | `agent:multiLogin` | Object | Multi-login detected |
168
+ | `agent:reloginSuccess` | `ReloginSuccess` | Silent relogin succeeded |
169
+ | `agent:dnRegistered` | Object | DN registration complete |
170
+
171
+ ### Event Usage
172
+
173
+ ```typescript
174
+ cc.on('agent:stateChange', (event) => {
175
+ console.log(`State: ${event.subStatus}, AuxCode: ${event.auxCodeId}`);
176
+ });
177
+
178
+ cc.on('agent:multiLogin', (event) => {
179
+ console.warn('Another session detected');
180
+ });
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Agent States
186
+
187
+ The `AgentState` type (`'Available' | 'Idle' | 'RONA' | string`) is extensible -- the `string` union member allows backend-defined states beyond the known values listed below.
188
+
189
+ | State | SubStatus | Description |
190
+ |-------|-----------|-------------|
191
+ | LoggedIn | Available | Ready to receive tasks |
192
+ | LoggedIn | Idle | On break or not ready (uses aux code for sub-reason) |
193
+ | RONA | - | Rang but no answer; agent failed to accept offered task |
194
+ | LoggedOut | - | Not logged in |
195
+ | LoggedIn | *(custom)* | Additional org-specific states defined via aux codes |
196
+
197
+ > **Note**: `AgentState` is a union with `string`, so consumers should handle unknown state values gracefully rather than exhaustively matching only the known literals.
198
+
199
+ ---
200
+
201
+ ## Error Handling
202
+
203
+ ```typescript
204
+ try {
205
+ await cc.stationLogin(params);
206
+ } catch (error) {
207
+ console.error('Login failed:', error.message);
208
+ // Access error details
209
+ if (error.data) {
210
+ console.error('Field:', error.data.fieldName);
211
+ console.error('Message:', error.data.message);
212
+ }
213
+ }
214
+ ```
215
+
216
+ ### Common Error Reasons
217
+
218
+ | Reason | Description |
219
+ |--------|-------------|
220
+ | `DUPLICATE_LOCATION` | Extension/DN already in use |
221
+ | `INVALID_DIAL_NUMBER` | Invalid phone number format |
222
+ | `AGENT_NOT_FOUND` | Agent doesn't exist (silent relogin) |
223
+
224
+ ---
225
+
226
+ ## Dependencies
227
+
228
+ - Requires `cc.register()` to be called first
229
+ - Agent profile must be fetched before login
230
+ - WebRTC (BROWSER option) requires mercury connection
231
+
232
+ ---
233
+
234
+ ## Related
235
+
236
+ - [ARCHITECTURE.md](ARCHITECTURE.md) - Technical deep-dive
237
+ - [`cc.ts`](../../../cc.ts) - Main plugin implementation
238
+ - [`types.ts`](../types.ts) - Type definitions