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

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
@@ -1,1530 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _events = _interopRequireDefault(require("events"));
8
- var _calling = require("@webex/calling");
9
- var _Utils = require("../core/Utils");
10
- var _types = require("../../types");
11
- var _constants = require("../../constants");
12
- var _constants2 = require("./constants");
13
- var _loggerProxy = _interopRequireDefault(require("../../logger-proxy"));
14
- var _types2 = require("./types");
15
- var _MetricsManager = _interopRequireDefault(require("../../metrics/MetricsManager"));
16
- var _constants3 = require("../../metrics/constants");
17
- var _AutoWrapup = _interopRequireDefault(require("./AutoWrapup"));
18
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
- /**
20
- * Task class represents a contact center task/interaction that can be managed by an agent.
21
- * This class provides all the necessary methods to manage tasks in a contact center environment,
22
- * handling various call control operations and task lifecycle management.
23
- *
24
- * - Task Lifecycle Management:
25
- * - {@link accept} - Accept incoming task
26
- * - {@link decline} - Decline incoming task
27
- * - {@link end} - End active task
28
- * - Media Controls:
29
- * - {@link toggleMute} - Mute/unmute microphone for voice tasks
30
- * - {@link hold} - Place task on hold
31
- * - {@link resume} - Resume held task
32
- * - Recording Controls:
33
- * - {@link pauseRecording} - Pause task recording
34
- * - {@link resumeRecording} - Resume paused recording
35
- * - Task Transfer & Consultation:
36
- * - {@link consult} - Initiate consultation with another agent/queue
37
- * - {@link endConsult} - End ongoing consultation
38
- * - {@link transfer} - Transfer task to another agent/queue
39
- * - {@link consultTransfer} - Transfer after consultation
40
- * - Task Completion:
41
- * - {@link wrapup} - Complete task wrap-up
42
- *
43
- * Key events emitted by Task instances (see {@link TASK_EVENTS} for details):
44
- *
45
- * - Task Lifecycle:
46
- * - task:incoming — New task is being offered
47
- * - task:assigned — Task assigned to agent
48
- * - task:unassigned — Task unassigned from agent
49
- * - task:end — Task has ended
50
- * - task:wrapup — Task entered wrap-up state
51
- * - task:wrappedup — Task wrap-up completed
52
- * - task:rejected — Task was rejected/unanswered
53
- * - task:hydrate — Task data populated
54
- *
55
- * - Media & Controls:
56
- * - task:media — Voice call media track received
57
- * - task:hold — Task placed on hold
58
- * - task:unhold — Task resumed from hold
59
- *
60
- * - Consultation & Transfer:
61
- * - task:consultCreated — Consultation initiated
62
- * - task:consulting — Consultation in progress
63
- * - task:consultAccepted — Consultation accepted
64
- * - task:consultEnd — Consultation ended
65
- * - task:consultQueueCancelled — Queue consultation cancelled
66
- * - task:consultQueueFailed — Queue consultation failed
67
- * - task:offerConsult — Consultation offered
68
- * - task:offerContact — New contact offered
69
- *
70
- * - Recording:
71
- * - task:recordingPaused — Recording paused
72
- * - task:recordingPauseFailed — Recording pause failed
73
- * - task:recordingResumed — Recording resumed
74
- * - task:recordingResumeFailed — Recording resume failed
75
- *
76
- * @implements {ITask}
77
- * @example
78
- * ```typescript
79
- * // 1. Initialize task
80
- * const task = new Task(contact, webCallingService, taskData);
81
- *
82
- * // 2. Set up event listeners
83
- * task.on('task:media', (track) => {
84
- * // Handle voice call media
85
- * const audioElement = document.getElementById('remote-audio');
86
- * audioElement.srcObject = new MediaStream([track]);
87
- * });
88
- *
89
- * task.on('task:hold', () => {
90
- * console.log('Task is on hold');
91
- * // Update UI to show hold state
92
- * });
93
- *
94
- * task.on('task:end', () => {
95
- * console.log('Task ended');
96
- * if (task.data.wrapUpRequired) {
97
- * // Show wrap-up form
98
- * }
99
- * });
100
- *
101
- * // 3. Example task operations
102
- * await task.accept(); // Accept incoming task
103
- * await task.hold(); // Place on hold
104
- * await task.resume(); // Resume from hold
105
- * await task.end(); // End task
106
- *
107
- * // 4. Handle wrap-up if required
108
- * await task.wrapup({
109
- * auxCodeId: 'RESOLVED',
110
- * wrapUpReason: 'Customer issue resolved'
111
- * });
112
- * ```
113
- */
114
-
115
- class Task extends _events.default {
116
- /**
117
- * Creates a new Task instance which provides the following features:
118
- * @param contact - The routing contact service instance
119
- * @param webCallingService - The web calling service instance
120
- * @param data - Initial task data
121
- * @param wrapupData - Wrap-up configuration data
122
- */
123
- constructor(contact, webCallingService, data, wrapupData, agentId) {
124
- super();
125
- this.contact = contact;
126
- this.data = data;
127
- this.webCallingService = webCallingService;
128
- this.webCallMap = {};
129
- this.wrapupData = wrapupData;
130
- this.metricsManager = _MetricsManager.default.getInstance();
131
- this.registerWebCallListeners();
132
- this.setupAutoWrapupTimer();
133
- this.agentId = agentId;
134
- }
135
-
136
- /**
137
- * Sets up the automatic wrap-up timer if wrap-up is required
138
- * @private
139
- */
140
- setupAutoWrapupTimer() {
141
- if (this.data.wrapUpRequired &&
142
- // only when wrapup required
143
- !this.autoWrapup &&
144
- // if autoWrapup is not already set
145
- this.wrapupData &&
146
- // wrapupData is not defined
147
- this.wrapupData.wrapUpProps // wrapUpProps is defined
148
- ) {
149
- const wrapUpProps = this.wrapupData.wrapUpProps;
150
- if (!wrapUpProps || wrapUpProps.autoWrapup === false) {
151
- _loggerProxy.default.info(`Auto wrap-up is not required for this task`, {
152
- module: _constants.TASK_FILE,
153
- method: _constants2.METHODS.SETUP_AUTO_WRAPUP_TIMER,
154
- interactionId: this.data.interactionId
155
- });
156
- return;
157
- }
158
- const defaultWrapupReason = wrapUpProps.wrapUpReasonList?.find(r => r.isDefault) ?? wrapUpProps.wrapUpReasonList?.[0];
159
- if (!defaultWrapupReason) {
160
- _loggerProxy.default.error('No wrap-up reason configured', {
161
- module: _constants.TASK_FILE,
162
- method: _constants2.METHODS.SETUP_AUTO_WRAPUP_TIMER
163
- });
164
- return;
165
- }
166
- const intervalMs = wrapUpProps.autoWrapupInterval;
167
- if (!intervalMs || intervalMs <= 0) {
168
- _loggerProxy.default.error(`Invalid auto wrap-up interval: ${intervalMs}`, {
169
- module: _constants.TASK_FILE,
170
- method: _constants2.METHODS.SETUP_AUTO_WRAPUP_TIMER
171
- });
172
- }
173
- this.autoWrapup = new _AutoWrapup.default(intervalMs, wrapUpProps.allowCancelAutoWrapup);
174
- this.autoWrapup.start(async () => {
175
- _loggerProxy.default.info(`Auto wrap-up timer triggered`, {
176
- module: _constants.TASK_FILE,
177
- method: _constants2.METHODS.SETUP_AUTO_WRAPUP_TIMER,
178
- interactionId: this.data.interactionId
179
- });
180
- await this.wrapup({
181
- wrapUpReason: defaultWrapupReason.name,
182
- auxCodeId: defaultWrapupReason.id
183
- });
184
- });
185
- }
186
- }
187
-
188
- /**
189
- * Cancels the automatic wrap-up timer if it's running
190
- * @public - Public so it can be called externally when needed
191
- * Note: This is supported only in single session mode. Not supported in multi-session mode.
192
- */
193
- cancelAutoWrapupTimer() {
194
- this.autoWrapup?.clear();
195
- this.autoWrapup = undefined;
196
- _loggerProxy.default.info(`Auto wrap-up timer cancelled`, {
197
- module: _constants.TASK_FILE,
198
- method: _constants2.METHODS.CANCEL_AUTO_WRAPUP_TIMER,
199
- interactionId: this.data?.interactionId
200
- });
201
- }
202
-
203
- /**
204
- * @ignore
205
- * @private
206
- */
207
- handleRemoteMedia = track => {
208
- this.emit(_types2.TASK_EVENTS.TASK_MEDIA, track);
209
- };
210
-
211
- /**
212
- * @ignore
213
- * @private
214
- */
215
- registerWebCallListeners() {
216
- this.webCallingService.on(_calling.CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
217
- }
218
-
219
- /**
220
- * @ignore
221
- */
222
- unregisterWebCallListeners() {
223
- this.webCallingService.off(_calling.CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
224
- }
225
-
226
- /**
227
- * Updates the task data with new information
228
- * @param updatedData - New task data to merge with existing data
229
- * @param shouldOverwrite - If true, completely replace data instead of merging
230
- * @returns The updated task instance
231
- * @example
232
- * ```typescript
233
- * task.updateTaskData(newData);
234
- * task.updateTaskData(newData, true); // completely replace data
235
- * ```
236
- */
237
- updateTaskData = (updatedData, shouldOverwrite = false) => {
238
- this.data = shouldOverwrite ? updatedData : this.reconcileData(this.data, updatedData);
239
- this.setupAutoWrapupTimer();
240
- return this;
241
- };
242
-
243
- /**
244
- * Recursively merges old data with new data
245
- * @private
246
- */
247
- reconcileData(oldData, newData) {
248
- // Remove keys from oldData that are not in newData
249
- Object.keys(oldData).forEach(key => {
250
- if (!(key in newData) && !_constants2.KEYS_TO_NOT_DELETE.includes(key)) {
251
- delete oldData[key];
252
- }
253
- });
254
-
255
- // Merge or update keys from newData
256
- Object.keys(newData).forEach(key => {
257
- if (newData[key] && typeof newData[key] === 'object' && !Array.isArray(newData[key]) && oldData[key] && typeof oldData[key] === 'object' && !Array.isArray(oldData[key])) {
258
- this.reconcileData(oldData[key], newData[key]);
259
- } else {
260
- oldData[key] = newData[key];
261
- }
262
- });
263
- return oldData;
264
- }
265
-
266
- /**
267
- * Agent accepts the incoming task.
268
- * After accepting, the task will emit task:assigned event and for voice calls,
269
- * a task:media event with the audio stream.
270
- *
271
- * @returns Promise<TaskResponse>
272
- * @throws Error if accepting task fails or media requirements not met
273
- * @example
274
- * ```typescript
275
- * // Set up event handlers before accepting
276
- * task.on(TASK_EVENTS.TASK_ASSIGNED, () => {
277
- * console.log('Task assigned, ID:', task.data.interactionId);
278
- * // Update UI to show active task
279
- * });
280
- *
281
- * // For voice calls, handle media
282
- * task.on(TASK_EVENTS.TASK_MEDIA, (track) => {
283
- * const audioElement = document.getElementById('remote-audio');
284
- * audioElement.srcObject = new MediaStream([track]);
285
- * });
286
- *
287
- * // Accept the task
288
- * try {
289
- * await task.accept();
290
- * console.log('Successfully accepted task');
291
- * } catch (error) {
292
- * console.error('Failed to accept task:', error);
293
- * // Handle error (e.g., show error message to agent)
294
- * }
295
- * ```
296
- */
297
- async accept() {
298
- try {
299
- _loggerProxy.default.info(`Accepting task`, {
300
- module: _constants.TASK_FILE,
301
- method: _constants2.METHODS.ACCEPT,
302
- interactionId: this.data.interactionId
303
- });
304
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED]);
305
- if (this.data.interaction.mediaType !== _types2.MEDIA_CHANNEL.TELEPHONY) {
306
- const response = await this.contact.accept({
307
- interactionId: this.data.interactionId
308
- });
309
- _loggerProxy.default.log(`Task accepted successfully`, {
310
- module: _constants.TASK_FILE,
311
- method: _constants2.METHODS.ACCEPT,
312
- trackingId: response.trackingId,
313
- interactionId: this.data.interactionId
314
- });
315
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS, {
316
- taskId: this.data.interactionId,
317
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(this.data)
318
- }, ['operational', 'behavioral', 'business']);
319
- return response;
320
- }
321
- if (this.webCallingService.loginOption === _types.LoginOption.BROWSER) {
322
- const constraints = {
323
- audio: true
324
- };
325
- const localStream = await navigator.mediaDevices.getUserMedia(constraints);
326
- const audioTrack = localStream.getAudioTracks()[0];
327
- this.localAudioStream = new _calling.LocalMicrophoneStream(new MediaStream([audioTrack]));
328
- this.webCallingService.answerCall(this.localAudioStream, this.data.interactionId);
329
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS, {
330
- taskId: this.data.interactionId,
331
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(this.data)
332
- }, ['operational', 'behavioral', 'business']);
333
- _loggerProxy.default.log(`Task accepted successfully with webrtc calling`, {
334
- module: _constants.TASK_FILE,
335
- method: _constants2.METHODS.ACCEPT,
336
- interactionId: this.data.interactionId
337
- });
338
- }
339
- return Promise.resolve(); // TODO: reject for extension as part of refactor
340
- } catch (error) {
341
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.ACCEPT, _constants.TASK_FILE);
342
- const taskErrorProps = {
343
- trackingId: err.data?.trackingId,
344
- errorMessage: err.data?.message,
345
- errorType: err.data?.errorType,
346
- errorData: err.data?.errorData,
347
- reasonCode: err.data?.reasonCode
348
- };
349
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED, {
350
- taskId: this.data.interactionId,
351
- error: error.toString(),
352
- ...taskErrorProps,
353
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details)
354
- }, ['operational', 'behavioral', 'business']);
355
- throw err;
356
- }
357
- }
358
-
359
- /**
360
- * Agent can mute/unmute their microphone during a WebRTC task.
361
- * This method toggles between muted and unmuted states for the local audio stream.
362
- *
363
- * @returns Promise<void> - Resolves when mute/unmute operation completes
364
- * @throws Error if toggling mute state fails or audio stream is not available
365
- * @example
366
- * ```typescript
367
- * // Toggle mute state
368
- * task.toggleMute()
369
- * .then(() => console.log('Mute state toggled successfully'))
370
- * .catch(error => console.error('Failed to toggle mute:', error));
371
- * ```
372
- */
373
- async toggleMute() {
374
- try {
375
- _loggerProxy.default.info(`Toggling mute state`, {
376
- module: _constants.TASK_FILE,
377
- method: _constants2.METHODS.TOGGLE_MUTE,
378
- interactionId: this.data.interactionId
379
- });
380
- this.webCallingService.muteUnmuteCall(this.localAudioStream);
381
- _loggerProxy.default.log(`Mute state toggled successfully isCallMuted: ${this.webCallingService.isCallMuted()}`, {
382
- module: _constants.TASK_FILE,
383
- method: _constants2.METHODS.TOGGLE_MUTE,
384
- interactionId: this.data.interactionId
385
- });
386
- return Promise.resolve();
387
- } catch (error) {
388
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.TOGGLE_MUTE, _constants.TASK_FILE);
389
- throw err;
390
- }
391
- }
392
-
393
- /**
394
- * Declines the incoming task. This will reject the task and notify the routing system.
395
- * For voice calls, this is equivalent to declining the incoming call.
396
- *
397
- * @returns Promise<TaskResponse>
398
- * @throws Error if the decline operation fails
399
- * @example
400
- * ```typescript
401
- * // Decline an incoming task
402
- * task.decline()
403
- * .then(() => console.log('Task declined successfully'))
404
- * .catch(error => console.error('Failed to decline task:', error));
405
- * ```
406
- */
407
- async decline() {
408
- try {
409
- _loggerProxy.default.info(`Declining task`, {
410
- module: _constants.TASK_FILE,
411
- method: _constants2.METHODS.DECLINE,
412
- interactionId: this.data.interactionId
413
- });
414
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_DECLINE_FAILED]);
415
- this.webCallingService.declineCall(this.data.interactionId);
416
- this.unregisterWebCallListeners();
417
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS, {
418
- taskId: this.data.interactionId
419
- }, ['operational', 'behavioral']);
420
- _loggerProxy.default.log(`Task declined successfully`, {
421
- module: _constants.TASK_FILE,
422
- method: _constants2.METHODS.DECLINE,
423
- interactionId: this.data.interactionId
424
- });
425
- return Promise.resolve();
426
- } catch (error) {
427
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.DECLINE, _constants.TASK_FILE);
428
- const taskErrorProps = {
429
- trackingId: err.data?.trackingId,
430
- errorMessage: err.data?.message,
431
- errorType: err.data?.errorType,
432
- errorData: err.data?.errorData,
433
- reasonCode: err.data?.reasonCode
434
- };
435
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_DECLINE_FAILED, {
436
- taskId: this.data.interactionId,
437
- error: error.toString(),
438
- ...taskErrorProps,
439
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
440
- }, ['operational', 'behavioral']);
441
- throw err;
442
- }
443
- }
444
-
445
- /**
446
- * Puts the current task/interaction on hold.
447
- * Emits task:hold event when successful. For voice tasks, this mutes the audio.
448
- *
449
- * @param mediaResourceId - Optional media resource ID to use for the hold operation. If not provided, uses the task's current mediaResourceId
450
- * @returns Promise<TaskResponse>
451
- * @throws Error if hold operation fails
452
- * @example
453
- * ```typescript
454
- * // Set up hold event handler
455
- * task.on(TASK_EVENTS.TASK_HOLD, () => {
456
- * console.log('Task is now on hold');
457
- * // Update UI to show hold state (e.g., enable resume button, show hold indicator)
458
- * document.getElementById('resume-btn').disabled = false;
459
- * document.getElementById('hold-indicator').style.display = 'block';
460
- * });
461
- *
462
- * // Place task on hold
463
- * try {
464
- * await task.hold();
465
- * console.log('Successfully placed task on hold');
466
- * } catch (error) {
467
- * console.error('Failed to place task on hold:', error);
468
- * // Handle error (e.g., show error message, reset UI state)
469
- * }
470
- *
471
- * // Place task on hold with custom mediaResourceId
472
- * try {
473
- * await task.hold('custom-media-resource-id');
474
- * console.log('Successfully placed task on hold with custom mediaResourceId');
475
- * } catch (error) {
476
- * console.error('Failed to place task on hold:', error);
477
- * }
478
- * ```
479
- */
480
- async hold(mediaResourceId) {
481
- try {
482
- _loggerProxy.default.info(`Holding task`, {
483
- module: _constants.TASK_FILE,
484
- method: _constants2.METHODS.HOLD,
485
- interactionId: this.data.interactionId
486
- });
487
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_HOLD_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_HOLD_FAILED]);
488
- const {
489
- mainInteractionId
490
- } = this.data.interaction;
491
- const defaultMediaResourceId = this.data.interaction.media[mainInteractionId]?.mediaResourceId;
492
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
493
- const response = await this.contact.hold({
494
- interactionId: this.data.interactionId,
495
- data: {
496
- mediaResourceId: effectiveMediaResourceId
497
- }
498
- });
499
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_HOLD_SUCCESS, {
500
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response),
501
- taskId: this.data.interactionId,
502
- mediaResourceId: effectiveMediaResourceId
503
- }, ['operational', 'behavioral']);
504
- _loggerProxy.default.log(`Task placed on hold successfully`, {
505
- module: _constants.TASK_FILE,
506
- method: _constants2.METHODS.HOLD,
507
- trackingId: response.trackingId,
508
- interactionId: this.data.interactionId
509
- });
510
- return response;
511
- } catch (error) {
512
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.HOLD, _constants.TASK_FILE);
513
- const taskErrorProps = {
514
- trackingId: err.data?.trackingId,
515
- errorMessage: err.data?.message,
516
- errorType: err.data?.errorType,
517
- errorData: err.data?.errorData,
518
- reasonCode: err.data?.reasonCode
519
- };
520
- const defaultMediaResourceId = this.data.interaction.media[this.data.interaction.mainInteractionId]?.mediaResourceId;
521
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
522
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_HOLD_FAILED, {
523
- taskId: this.data.interactionId,
524
- mediaResourceId: effectiveMediaResourceId,
525
- error: error.toString(),
526
- ...taskErrorProps,
527
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
528
- }, ['operational', 'behavioral']);
529
- throw err;
530
- }
531
- }
532
-
533
- /**
534
- * Resumes the task/interaction that was previously put on hold.
535
- * Emits task:resume event when successful. For voice tasks, this restores the audio.
536
- *
537
- * @param mediaResourceId - Optional media resource ID to use for the resume operation. If not provided, uses the task's current mediaResourceId from interaction media
538
- * @returns Promise<TaskResponse>
539
- * @throws Error if resume operation fails
540
- * @example
541
- * ```typescript
542
- * // Set up resume event handler
543
- * task.on(TASK_EVENTS.TASK_RESUME, () => {
544
- * console.log('Task resumed from hold');
545
- * // Update UI to show active state
546
- * document.getElementById('hold-btn').disabled = false;
547
- * document.getElementById('hold-indicator').style.display = 'none';
548
- * });
549
- *
550
- * // Resume task from hold
551
- * try {
552
- * await task.resume();
553
- * console.log('Successfully resumed task from hold');
554
- * } catch (error) {
555
- * console.error('Failed to resume task:', error);
556
- * // Handle error (e.g., show error message)
557
- * }
558
- *
559
- * // Resume task from hold with custom mediaResourceId
560
- * try {
561
- * await task.resume('custom-media-resource-id');
562
- * console.log('Successfully resumed task from hold with custom mediaResourceId');
563
- * } catch (error) {
564
- * console.error('Failed to resume task:', error);
565
- * }
566
- * ```
567
- */
568
- async resume(mediaResourceId) {
569
- try {
570
- _loggerProxy.default.info(`Resuming task`, {
571
- module: _constants.TASK_FILE,
572
- method: _constants2.METHODS.RESUME,
573
- interactionId: this.data.interactionId
574
- });
575
- const {
576
- mainInteractionId
577
- } = this.data.interaction;
578
- const defaultMediaResourceId = this.data.interaction.media[mainInteractionId]?.mediaResourceId;
579
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
580
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_RESUME_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_RESUME_FAILED]);
581
- const response = await this.contact.unHold({
582
- interactionId: this.data.interactionId,
583
- data: {
584
- mediaResourceId: effectiveMediaResourceId
585
- }
586
- });
587
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_SUCCESS, {
588
- taskId: this.data.interactionId,
589
- mainInteractionId,
590
- mediaResourceId: effectiveMediaResourceId,
591
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
592
- }, ['operational', 'behavioral']);
593
- _loggerProxy.default.log(`Task resumed successfully`, {
594
- module: _constants.TASK_FILE,
595
- method: _constants2.METHODS.RESUME,
596
- trackingId: response.trackingId,
597
- interactionId: this.data.interactionId
598
- });
599
- return response;
600
- } catch (error) {
601
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.RESUME, _constants.TASK_FILE);
602
- const mainInteractionId = this.data.interaction?.mainInteractionId;
603
- const defaultMediaResourceId = mainInteractionId ? this.data.interaction.media[mainInteractionId]?.mediaResourceId : '';
604
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
605
- const taskErrorProps = {
606
- trackingId: err.data?.trackingId,
607
- errorMessage: err.data?.message,
608
- errorType: err.data?.errorType,
609
- errorData: err.data?.errorData,
610
- reasonCode: err.data?.reasonCode
611
- };
612
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_FAILED, {
613
- taskId: this.data.interactionId,
614
- mainInteractionId,
615
- mediaResourceId: effectiveMediaResourceId,
616
- ...taskErrorProps,
617
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
618
- }, ['operational', 'behavioral']);
619
- throw err;
620
- }
621
- }
622
-
623
- /**
624
- * Ends the task/interaction with the customer.
625
- * Emits task:end event when successful. If task requires wrap-up,
626
- * this will be indicated in the task:end event data.
627
- *
628
- * @returns Promise<TaskResponse>
629
- * @throws Error if ending task fails
630
- * @example
631
- * ```typescript
632
- * // Set up task end event handler
633
- * task.on(TASK_EVENTS.TASK_END, (data) => {
634
- * console.log('Task ended:', task.data.interactionId);
635
- *
636
- * if (data.wrapUpRequired) {
637
- * // Show wrap-up form
638
- * showWrapupForm();
639
- * } else {
640
- * // Clean up and prepare for next task
641
- * cleanupTask();
642
- * }
643
- * });
644
- *
645
- * // End the task
646
- * try {
647
- * await task.end();
648
- * console.log('Task end request successful');
649
- * } catch (error) {
650
- * console.error('Failed to end task:', error);
651
- * // Handle error (e.g., show error message, retry option)
652
- * }
653
- *
654
- * function showWrapupForm() {
655
- * // Show wrap-up UI with required codes
656
- * document.getElementById('wrapup-form').style.display = 'block';
657
- * }
658
- *
659
- * function cleanupTask() {
660
- * // Reset UI state
661
- * document.getElementById('active-task').style.display = 'none';
662
- * document.getElementById('controls').style.display = 'none';
663
- * }
664
- * ```
665
- */
666
- async end() {
667
- try {
668
- _loggerProxy.default.info(`Ending task`, {
669
- module: _constants.TASK_FILE,
670
- method: _constants2.METHODS.END,
671
- interactionId: this.data.interactionId
672
- });
673
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_END_FAILED]);
674
- const response = await this.contact.end({
675
- interactionId: this.data.interactionId
676
- });
677
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, {
678
- taskId: this.data.interactionId,
679
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
680
- }, ['operational', 'behavioral', 'business']);
681
- _loggerProxy.default.log(`Task ended successfully`, {
682
- module: _constants.TASK_FILE,
683
- method: _constants2.METHODS.END,
684
- trackingId: response.trackingId,
685
- interactionId: this.data.interactionId
686
- });
687
- return response;
688
- } catch (error) {
689
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.END, _constants.TASK_FILE);
690
- const taskErrorProps = {
691
- trackingId: err.data?.trackingId,
692
- errorMessage: err.data?.message,
693
- errorType: err.data?.errorType,
694
- errorData: err.data?.errorData,
695
- reasonCode: err.data?.reasonCode
696
- };
697
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_FAILED, {
698
- taskId: this.data.interactionId,
699
- ...taskErrorProps,
700
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
701
- }, ['operational', 'behavioral', 'business']);
702
- throw err;
703
- }
704
- }
705
-
706
- /**
707
- * Wraps up the task/interaction with the customer.
708
- * This is called after task:end event if wrapUpRequired is true.
709
- * Emits task:wrappedup event when successful.
710
- *
711
- * @param wrapupPayload - WrapupPayLoad containing:
712
- * - auxCodeId: Required ID for the wrap-up code
713
- * - wrapUpReason: Required description of wrap-up reason
714
- * @returns Promise<TaskResponse>
715
- * @throws Error if task data is unavailable, auxCodeId is missing, or wrapUpReason is missing
716
- * @example
717
- * ```typescript
718
- * // Set up wrap-up events
719
- * task.on(TASK_EVENTS.TASK_WRAPUP, () => {
720
- * console.log('Task ready for wrap-up');
721
- * // Show wrap-up form
722
- * document.getElementById('wrapup-form').style.display = 'block';
723
- * });
724
- *
725
- * task.on(TASK_EVENTS.TASK_WRAPPEDUP, () => {
726
- * console.log('Task wrap-up completed');
727
- * // Clean up UI
728
- * document.getElementById('wrapup-form').style.display = 'none';
729
- * });
730
- *
731
- * // Submit wrap-up
732
- * try {
733
- * const wrapupPayload = {
734
- * auxCodeId: selectedCode, // e.g., 'ISSUE_RESOLVED'
735
- * wrapUpReason: 'Customer issue resolved successfully'
736
- * };
737
- * await task.wrapup(wrapupPayload);
738
- * console.log('Successfully submitted wrap-up');
739
- * } catch (error) {
740
- * console.error('Failed to submit wrap-up:', error);
741
- * // Handle validation errors
742
- * if (error.message.includes('required')) {
743
- * // Show validation error to agent
744
- * }
745
- * }
746
- * ```
747
- */
748
- async wrapup(wrapupPayload) {
749
- try {
750
- this.cancelAutoWrapupTimer();
751
- _loggerProxy.default.info(`Wrapping up task`, {
752
- module: _constants.TASK_FILE,
753
- method: _constants2.METHODS.WRAPUP,
754
- interactionId: this.data.interactionId
755
- });
756
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED]);
757
- if (!this.data) {
758
- throw new Error('No task data available');
759
- }
760
- if (!wrapupPayload.auxCodeId || wrapupPayload.auxCodeId.length === 0) {
761
- throw new Error('AuxCodeId is required');
762
- }
763
- if (!wrapupPayload.wrapUpReason || wrapupPayload.wrapUpReason.length === 0) {
764
- throw new Error('WrapUpReason is required');
765
- }
766
- const response = await this.contact.wrapup({
767
- interactionId: this.data.interactionId,
768
- data: wrapupPayload
769
- });
770
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, {
771
- taskId: this.data.interactionId,
772
- wrapUpCode: wrapupPayload.auxCodeId,
773
- wrapUpReason: wrapupPayload.wrapUpReason,
774
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
775
- }, ['operational', 'behavioral', 'business']);
776
- _loggerProxy.default.log(`Task wrapped up successfully`, {
777
- module: _constants.TASK_FILE,
778
- method: _constants2.METHODS.WRAPUP,
779
- trackingId: response.trackingId,
780
- interactionId: this.data.interactionId
781
- });
782
- return response;
783
- } catch (error) {
784
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.WRAPUP, _constants.TASK_FILE);
785
- const taskErrorProps = {
786
- trackingId: err.data?.trackingId,
787
- errorMessage: err.data?.message,
788
- errorType: err.data?.errorType,
789
- errorData: err.data?.errorData,
790
- reasonCode: err.data?.reasonCode
791
- };
792
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED, {
793
- taskId: this.data.interactionId,
794
- wrapUpCode: wrapupPayload.auxCodeId,
795
- wrapUpReason: wrapupPayload.wrapUpReason,
796
- ...taskErrorProps,
797
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
798
- }, ['operational', 'behavioral', 'business']);
799
- throw err;
800
- }
801
- }
802
-
803
- /**
804
- * Pauses the recording for the current voice task.
805
- * Emits task:recordingPaused event when successful.
806
- *
807
- * @returns Promise<TaskResponse>
808
- * @throws Error if pause recording fails
809
- * @example
810
- * ```typescript
811
- * // Set up recording events
812
- * task.on(TASK_EVENTS.TASK_RECORDING_PAUSED, () => {
813
- * console.log('Recording paused');
814
- * // Update UI to show recording paused state
815
- * document.getElementById('recording-status').textContent = 'Recording Paused';
816
- * document.getElementById('pause-recording-btn').style.display = 'none';
817
- * document.getElementById('resume-recording-btn').style.display = 'block';
818
- * });
819
- *
820
- * task.on(TASK_EVENTS.TASK_RECORDING_PAUSE_FAILED, (error) => {
821
- * console.error('Failed to pause recording:', error);
822
- * // Show error to agent
823
- * });
824
- *
825
- * // Pause recording
826
- * try {
827
- * await task.pauseRecording();
828
- * console.log('Pause recording request sent');
829
- * } catch (error) {
830
- * console.error('Error sending pause recording request:', error);
831
- * // Handle error
832
- * }
833
- * ```
834
- */
835
- async pauseRecording() {
836
- try {
837
- _loggerProxy.default.info(`Pausing recording`, {
838
- module: _constants.TASK_FILE,
839
- method: _constants2.METHODS.PAUSE_RECORDING,
840
- interactionId: this.data.interactionId
841
- });
842
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED]);
843
- const result = await this.contact.pauseRecording({
844
- interactionId: this.data.interactionId
845
- });
846
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS, {
847
- taskId: this.data.interactionId,
848
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
849
- }, ['operational', 'behavioral', 'business']);
850
- _loggerProxy.default.log(`Recording paused successfully`, {
851
- module: _constants.TASK_FILE,
852
- method: _constants2.METHODS.PAUSE_RECORDING,
853
- trackingId: result.trackingId,
854
- interactionId: this.data.interactionId
855
- });
856
- return result;
857
- } catch (error) {
858
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.PAUSE_RECORDING, _constants.TASK_FILE);
859
- const taskErrorProps = {
860
- trackingId: err.data?.trackingId,
861
- errorMessage: err.data?.message,
862
- errorType: err.data?.errorType,
863
- errorData: err.data?.errorData,
864
- reasonCode: err.data?.reasonCode
865
- };
866
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED, {
867
- taskId: this.data.interactionId,
868
- error: error.toString(),
869
- ...taskErrorProps,
870
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
871
- }, ['operational', 'behavioral', 'business']);
872
- throw err;
873
- }
874
- }
875
-
876
- /**
877
- * Resumes the recording for the voice task that was previously paused.
878
- * Emits task:recordingResumed event when successful.
879
- *
880
- * @param resumeRecordingPayload - Configuration for resuming recording:
881
- * - autoResumed: Indicates if resume was automatic (defaults to false)
882
- * @returns Promise<TaskResponse>
883
- * @throws Error if resume recording fails
884
- * @example
885
- * ```typescript
886
- * // Set up recording resume events
887
- * task.on(TASK_EVENTS.TASK_RECORDING_RESUMED, () => {
888
- * console.log('Recording resumed');
889
- * // Update UI to show active recording state
890
- * document.getElementById('recording-status').textContent = 'Recording Active';
891
- * document.getElementById('pause-recording-btn').style.display = 'block';
892
- * document.getElementById('resume-recording-btn').style.display = 'none';
893
- * });
894
- *
895
- * task.on(TASK_EVENTS.TASK_RECORDING_RESUME_FAILED, (error) => {
896
- * console.error('Failed to resume recording:', error);
897
- * // Show error to agent
898
- * });
899
- *
900
- * // Resume recording
901
- * try {
902
- * const resumePayload = {
903
- * autoResumed: false // Set to true if triggered by system
904
- * };
905
- * await task.resumeRecording(resumePayload);
906
- * console.log('Resume recording request sent');
907
- * } catch (error) {
908
- * console.error('Error sending resume recording request:', error);
909
- * // Handle error
910
- * }
911
- * ```
912
- */
913
- async resumeRecording(resumeRecordingPayload) {
914
- try {
915
- _loggerProxy.default.info(`Resuming recording`, {
916
- module: _constants.TASK_FILE,
917
- method: _constants2.METHODS.RESUME_RECORDING,
918
- interactionId: this.data.interactionId
919
- });
920
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED]);
921
- resumeRecordingPayload ??= {
922
- autoResumed: false
923
- };
924
- const result = await this.contact.resumeRecording({
925
- interactionId: this.data.interactionId,
926
- data: resumeRecordingPayload
927
- });
928
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS, {
929
- taskId: this.data.interactionId,
930
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
931
- }, ['operational', 'behavioral', 'business']);
932
- _loggerProxy.default.log(`Recording resumed successfully`, {
933
- module: _constants.TASK_FILE,
934
- method: _constants2.METHODS.RESUME_RECORDING,
935
- trackingId: result.trackingId,
936
- interactionId: this.data.interactionId
937
- });
938
- return result;
939
- } catch (error) {
940
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.RESUME_RECORDING, _constants.TASK_FILE);
941
- const taskErrorProps = {
942
- trackingId: err.data?.trackingId,
943
- errorMessage: err.data?.message,
944
- errorType: err.data?.errorType,
945
- errorData: err.data?.errorData,
946
- reasonCode: err.data?.reasonCode
947
- };
948
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED, {
949
- taskId: this.data.interactionId,
950
- error: error.toString(),
951
- ...taskErrorProps,
952
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
953
- }, ['operational', 'behavioral', 'business']);
954
- throw err;
955
- }
956
- }
957
-
958
- /**
959
- * Consults another agent or queue on an ongoing task for further assistance.
960
- * During consultation, the original customer is typically placed on hold while
961
- * the agent seeks guidance from another agent or queue.
962
- *
963
- * @param consultPayload - Configuration for the consultation containing:
964
- * - to: ID of the agent or queue to consult with
965
- * - destinationType: Type of destination (AGENT, QUEUE, etc.)
966
- * - holdParticipants: Whether to hold other participants (defaults to true)
967
- * @returns Promise<TaskResponse> - Resolves with consultation result
968
- * @throws Error if consultation fails or invalid parameters provided
969
- * @example
970
- * ```typescript
971
- * // Consult with another agent
972
- * const consultPayload = {
973
- * to: 'agentId123',
974
- * destinationType: DESTINATION_TYPE.AGENT,
975
- * holdParticipants: true
976
- * };
977
- * task.consult(consultPayload)
978
- * .then(response => console.log('Consultation started successfully'))
979
- * .catch(error => console.error('Failed to start consultation:', error));
980
- *
981
- * // Consult with a queue
982
- * const queueConsultPayload = {
983
- * to: 'salesQueue123',
984
- * destinationType: DESTINATION_TYPE.QUEUE
985
- * };
986
- * task.consult(queueConsultPayload)
987
- * .then(response => console.log('Queue consultation started'))
988
- * .catch(error => console.error('Failed to start queue consultation:', error));
989
- * ```
990
- */
991
- async consult(consultPayload) {
992
- try {
993
- _loggerProxy.default.info(`Starting consult`, {
994
- module: _constants.TASK_FILE,
995
- method: _constants2.METHODS.CONSULT,
996
- interactionId: this.data.interactionId
997
- });
998
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED]);
999
- const result = await this.contact.consult({
1000
- interactionId: this.data.interactionId,
1001
- data: consultPayload
1002
- });
1003
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS, {
1004
- taskId: this.data.interactionId,
1005
- destination: consultPayload.to,
1006
- destinationType: consultPayload.destinationType,
1007
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1008
- }, ['operational', 'behavioral', 'business']);
1009
- _loggerProxy.default.log(`Consult started successfully to ${consultPayload.to}`, {
1010
- module: _constants.TASK_FILE,
1011
- method: _constants2.METHODS.CONSULT,
1012
- trackingId: result.trackingId,
1013
- interactionId: this.data.interactionId
1014
- });
1015
- return result;
1016
- } catch (error) {
1017
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT, _constants.TASK_FILE);
1018
- const taskErrorProps = {
1019
- trackingId: err.data?.trackingId,
1020
- errorMessage: err.data?.message,
1021
- errorType: err.data?.errorType,
1022
- errorData: err.data?.errorData,
1023
- reasonCode: err.data?.reasonCode
1024
- };
1025
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED, {
1026
- taskId: this.data.interactionId,
1027
- destination: consultPayload.to,
1028
- destinationType: consultPayload.destinationType,
1029
- error: error.toString(),
1030
- ...taskErrorProps,
1031
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1032
- }, ['operational', 'behavioral', 'business']);
1033
- throw err;
1034
- }
1035
- }
1036
-
1037
- /**
1038
- * Ends an ongoing consultation session for the task.
1039
- * This terminates the consultation while maintaining the original customer connection.
1040
- *
1041
- * @param consultEndPayload - Configuration for ending the consultation containing:
1042
- * - isConsult: Must be true to indicate this is a consultation end
1043
- * - taskId: ID of the task being consulted on
1044
- * - queueId: (Optional) Queue ID if this was a queue consultation
1045
- * - isSecondaryEpDnAgent: (Optional) Indicates if this involves a secondary entry point
1046
- * @returns Promise<TaskResponse> - Resolves when consultation is ended
1047
- * @throws Error if ending consultation fails or invalid parameters provided
1048
- * @example
1049
- * ```typescript
1050
- * // End a direct agent consultation
1051
- * const consultEndPayload = {
1052
- * isConsult: true,
1053
- * taskId: 'task123'
1054
- * };
1055
- * task.endConsult(consultEndPayload)
1056
- * .then(response => console.log('Consultation ended successfully'))
1057
- * .catch(error => console.error('Failed to end consultation:', error));
1058
- *
1059
- * // End a queue consultation
1060
- * const queueConsultEndPayload = {
1061
- * isConsult: true,
1062
- * taskId: 'task123',
1063
- * queueId: 'queue123'
1064
- * };
1065
- * task.endConsult(queueConsultEndPayload)
1066
- * .then(response => console.log('Queue consultation ended'))
1067
- * .catch(error => console.error('Failed to end queue consultation:', error));
1068
- * ```
1069
- */
1070
- async endConsult(consultEndPayload) {
1071
- try {
1072
- _loggerProxy.default.info(`Ending consult`, {
1073
- module: _constants.TASK_FILE,
1074
- method: _constants2.METHODS.END_CONSULT,
1075
- interactionId: this.data.interactionId
1076
- });
1077
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED]);
1078
- const result = await this.contact.consultEnd({
1079
- interactionId: this.data.interactionId,
1080
- data: consultEndPayload
1081
- });
1082
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS, {
1083
- taskId: this.data.interactionId,
1084
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1085
- }, ['operational', 'behavioral', 'business']);
1086
- _loggerProxy.default.log(`Consult ended successfully`, {
1087
- module: _constants.TASK_FILE,
1088
- method: _constants2.METHODS.END_CONSULT,
1089
- trackingId: result.trackingId,
1090
- interactionId: this.data.interactionId
1091
- });
1092
- return result;
1093
- } catch (error) {
1094
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.END_CONSULT, _constants.TASK_FILE);
1095
- const taskErrorProps = {
1096
- trackingId: err.data?.trackingId,
1097
- errorMessage: err.data?.message,
1098
- errorType: err.data?.errorType,
1099
- errorData: err.data?.errorData,
1100
- reasonCode: err.data?.reasonCode
1101
- };
1102
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED, {
1103
- taskId: this.data.interactionId,
1104
- error: error.toString(),
1105
- ...taskErrorProps,
1106
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1107
- }, ['operational', 'behavioral', 'business']);
1108
- throw err;
1109
- }
1110
- }
1111
-
1112
- /**
1113
- * Transfer the task to an agent directly or to a queue.
1114
- * This is a blind transfer that immediately redirects the task to the specified destination.
1115
- *
1116
- * @param transferPayload - Transfer configuration containing:
1117
- * - to: ID of the agent or queue to transfer to
1118
- * - destinationType: Type of destination (AGENT, QUEUE, etc.)
1119
- * @returns Promise<TaskResponse> - Resolves when transfer is completed
1120
- * @throws Error if transfer fails or invalid parameters provided
1121
- * @example
1122
- * ```typescript
1123
- * // Transfer to a queue
1124
- * const queueTransferPayload = {
1125
- * to: 'salesQueue123',
1126
- * destinationType: DESTINATION_TYPE.QUEUE
1127
- * };
1128
- * task.transfer(queueTransferPayload)
1129
- * .then(response => console.log('Task transferred to queue successfully'))
1130
- * .catch(error => console.error('Failed to transfer to queue:', error));
1131
- *
1132
- * // Transfer to an agent
1133
- * const agentTransferPayload = {
1134
- * to: 'agentId123',
1135
- * destinationType: DESTINATION_TYPE.AGENT
1136
- * };
1137
- * task.transfer(agentTransferPayload)
1138
- * .then(response => console.log('Task transferred to agent successfully'))
1139
- * .catch(error => console.error('Failed to transfer to agent:', error));
1140
- * ```
1141
- */
1142
- async transfer(transferPayload) {
1143
- try {
1144
- _loggerProxy.default.info(`Transferring task to ${transferPayload.to}`, {
1145
- module: _constants.TASK_FILE,
1146
- method: _constants2.METHODS.TRANSFER,
1147
- interactionId: this.data.interactionId
1148
- });
1149
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED]);
1150
- let result;
1151
- if (transferPayload.destinationType === _types2.DESTINATION_TYPE.QUEUE) {
1152
- result = await this.contact.vteamTransfer({
1153
- interactionId: this.data.interactionId,
1154
- data: transferPayload
1155
- });
1156
- } else {
1157
- result = await this.contact.blindTransfer({
1158
- interactionId: this.data.interactionId,
1159
- data: transferPayload
1160
- });
1161
- }
1162
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, {
1163
- taskId: this.data.interactionId,
1164
- destination: transferPayload.to,
1165
- destinationType: transferPayload.destinationType,
1166
- isConsultTransfer: false,
1167
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1168
- }, ['operational', 'behavioral', 'business']);
1169
- _loggerProxy.default.log(`Task transferred successfully to ${transferPayload.to}`, {
1170
- module: _constants.TASK_FILE,
1171
- method: _constants2.METHODS.TRANSFER,
1172
- trackingId: result.trackingId,
1173
- interactionId: this.data.interactionId
1174
- });
1175
- return result;
1176
- } catch (error) {
1177
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.TRANSFER, _constants.TASK_FILE);
1178
- const taskErrorProps = {
1179
- trackingId: err.data?.trackingId,
1180
- errorMessage: err.data?.message,
1181
- errorType: err.data?.errorType,
1182
- errorData: err.data?.errorData,
1183
- reasonCode: err.data?.reasonCode
1184
- };
1185
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED, {
1186
- taskId: this.data.interactionId,
1187
- destination: transferPayload.to,
1188
- destinationType: transferPayload.destinationType,
1189
- isConsultTransfer: false,
1190
- error: error.toString(),
1191
- ...taskErrorProps,
1192
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1193
- }, ['operational', 'behavioral', 'business']);
1194
- throw err;
1195
- }
1196
- }
1197
-
1198
- /**
1199
- * Transfer the task to the party that was consulted.
1200
- * This completes a consultative transfer where the agent first consulted with the target
1201
- * before transferring the task. For queue consultations, the transfer is automatically
1202
- * directed to the agent who accepted the consultation.
1203
- *
1204
- * @param consultTransferPayload - Configuration for the consultation transfer containing:
1205
- * - to: ID of the agent or queue to transfer to
1206
- * - destinationType: Type of destination (AGENT, QUEUE, etc. from CONSULT_TRANSFER_DESTINATION_TYPE)
1207
- * @returns Promise<TaskResponse> - Resolves when consultation transfer is completed
1208
- * @throws Error if transfer fails, no agent has accepted a queue consultation, or other validation errors
1209
- * @example
1210
- * ```typescript
1211
- * // Complete consultation transfer to an agent
1212
- * const agentConsultTransfer = {
1213
- * to: 'agentId123',
1214
- * destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.AGENT
1215
- * };
1216
- * task.consultTransfer(agentConsultTransfer)
1217
- * .then(response => console.log('Consultation transfer to agent completed'))
1218
- * .catch(error => console.error('Failed to complete agent consultation transfer:', error));
1219
- *
1220
- * // Complete consultation transfer to a queue agent
1221
- * const queueConsultTransfer = {
1222
- * to: 'queue123',
1223
- * destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE
1224
- * };
1225
- * task.consultTransfer(queueConsultTransfer)
1226
- * .then(response => console.log('Consultation transfer to queue agent completed'))
1227
- * .catch(error => console.error('Failed to complete queue consultation transfer:', error));
1228
- * ```
1229
- */
1230
- async consultTransfer(consultTransferPayload) {
1231
- // Get the destination agent ID using custom logic from participants data
1232
- const destAgentId = (0, _Utils.calculateDestAgentId)(this.data.interaction, this.agentId);
1233
-
1234
- // Resolve the target id (queue consult transfers go to the accepted agent)
1235
- if (!destAgentId) {
1236
- throw new Error('No agent has accepted this queue consult yet');
1237
- }
1238
- _loggerProxy.default.info(`Initiating consult transfer to ${consultTransferPayload?.to || destAgentId}`, {
1239
- module: _constants.TASK_FILE,
1240
- method: _constants2.METHODS.CONSULT_TRANSFER,
1241
- interactionId: this.data.interactionId
1242
- });
1243
-
1244
- // Derive destination type from the participant's type property
1245
- const destType = (0, _Utils.calculateDestType)(this.data.interaction, this.agentId);
1246
- // By default we always use the computed destAgentId as the target id
1247
- const consultTransferRequest = {
1248
- to: destAgentId,
1249
- destinationType: destType
1250
- };
1251
- try {
1252
- const result = await this.contact.consultTransfer({
1253
- interactionId: this.data.interactionId,
1254
- data: consultTransferRequest
1255
- });
1256
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, {
1257
- taskId: this.data.interactionId,
1258
- destination: consultTransferRequest.to,
1259
- destinationType: consultTransferRequest.destinationType,
1260
- isConsultTransfer: true,
1261
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1262
- }, ['operational', 'behavioral', 'business']);
1263
- _loggerProxy.default.log(`Consult transfer completed successfully to ${consultTransferPayload?.to || destAgentId}`, {
1264
- module: _constants.TASK_FILE,
1265
- method: _constants2.METHODS.CONSULT_TRANSFER,
1266
- trackingId: result.trackingId,
1267
- interactionId: this.data.interactionId
1268
- });
1269
- return result;
1270
- } catch (error) {
1271
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT_TRANSFER, _constants.TASK_FILE);
1272
- const taskErrorProps = {
1273
- trackingId: err.data?.trackingId,
1274
- errorMessage: err.data?.message,
1275
- errorType: err.data?.errorType,
1276
- errorData: err.data?.errorData,
1277
- reasonCode: err.data?.reasonCode
1278
- };
1279
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED, {
1280
- taskId: this.data.interactionId,
1281
- destination: destAgentId || '',
1282
- destinationType: destType,
1283
- isConsultTransfer: true,
1284
- error: error.toString(),
1285
- ...taskErrorProps,
1286
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1287
- }, ['operational', 'behavioral', 'business']);
1288
- throw err;
1289
- }
1290
- }
1291
-
1292
- /**
1293
- * Starts a consultation conference by merging the consultation call with the main call
1294
- *
1295
- * Creates a three-way conference between the agent, customer, and consulted party
1296
- * Extracts required consultation data from the current task data
1297
- * On success, emits a `task:conferenceStarted` event
1298
- *
1299
- * @returns Promise<TaskResponse> - Response from the consultation conference API
1300
- * @throws Error if the operation fails or if consultation data is invalid
1301
- *
1302
- * @example
1303
- * ```typescript
1304
- * try {
1305
- * await task.consultConference();
1306
- * console.log('Conference started successfully');
1307
- * } catch (error) {
1308
- * console.error('Failed to start conference:', error);
1309
- * }
1310
- * ```
1311
- */
1312
- async consultConference() {
1313
- // Get the destination agent ID dynamically from participants
1314
- // This handles multi-party conference scenarios, CBT (Capacity Based Team), and EP-DN cases
1315
- const destAgentId = (0, _Utils.calculateDestAgentId)(this.data.interaction, this.agentId);
1316
-
1317
- // Validate that we have a destination agent (for queue consult scenarios)
1318
- if (!destAgentId) {
1319
- throw new Error('No agent has accepted this queue consult yet');
1320
- }
1321
-
1322
- // Get the destination agent ID for fetching destination type
1323
- // This helps determine the correct participant type for CBT (Capacity Based Team) and EP-DN scenarios
1324
- const destAgentType = (0, _Utils.calculateDestType)(this.data.interaction, this.agentId);
1325
-
1326
- // Extract consultation conference data from task data (used in both try and catch)
1327
- const consultationData = {
1328
- agentId: this.agentId,
1329
- to: destAgentId,
1330
- destinationType: destAgentType || this.data.destinationType || 'agent'
1331
- };
1332
- try {
1333
- _loggerProxy.default.info(`Initiating consult conference to ${destAgentId}`, {
1334
- module: _constants.TASK_FILE,
1335
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1336
- interactionId: this.data.interactionId
1337
- });
1338
- const response = await this.contact.consultConference({
1339
- interactionId: this.data.interactionId,
1340
- data: consultationData
1341
- });
1342
-
1343
- // Track success metrics (following consultTransfer pattern)
1344
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_START_SUCCESS, {
1345
- taskId: this.data.interactionId,
1346
- destination: consultationData.to,
1347
- destinationType: consultationData.destinationType,
1348
- agentId: consultationData.agentId,
1349
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1350
- }, ['operational', 'behavioral', 'business']);
1351
- _loggerProxy.default.log(`Consult conference started successfully`, {
1352
- module: _constants.TASK_FILE,
1353
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1354
- interactionId: this.data.interactionId
1355
- });
1356
- return response;
1357
- } catch (error) {
1358
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT_CONFERENCE, _constants.TASK_FILE);
1359
- const taskErrorProps = {
1360
- trackingId: err.data?.trackingId,
1361
- errorMessage: err.data?.message,
1362
- errorType: err.data?.errorType,
1363
- errorData: err.data?.errorData,
1364
- reasonCode: err.data?.reasonCode
1365
- };
1366
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_START_FAILED, {
1367
- taskId: this.data.interactionId,
1368
- destination: consultationData.to,
1369
- destinationType: consultationData.destinationType,
1370
- agentId: consultationData.agentId,
1371
- error: error.toString(),
1372
- ...taskErrorProps,
1373
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1374
- }, ['operational', 'behavioral', 'business']);
1375
- _loggerProxy.default.error(`Failed to start consult conference`, {
1376
- module: _constants.TASK_FILE,
1377
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1378
- interactionId: this.data.interactionId
1379
- });
1380
- throw err;
1381
- }
1382
- }
1383
-
1384
- /**
1385
- * Exits the current conference by removing the agent from the conference call
1386
- *
1387
- * Exits the agent from the conference, leaving the customer and consulted party connected
1388
- * On success, emits a `task:conferenceEnded` event
1389
- *
1390
- * @returns Promise<TaskResponse> - Response from the conference exit API
1391
- * @throws Error if the operation fails or if no active conference exists
1392
- *
1393
- * @example
1394
- * ```typescript
1395
- * try {
1396
- * await task.exitConference();
1397
- * console.log('Successfully exited conference');
1398
- * } catch (error) {
1399
- * console.error('Failed to exit conference:', error);
1400
- * }
1401
- * ```
1402
- */
1403
- async exitConference() {
1404
- try {
1405
- _loggerProxy.default.info(`Exiting consult conference`, {
1406
- module: _constants.TASK_FILE,
1407
- method: _constants2.METHODS.EXIT_CONFERENCE,
1408
- interactionId: this.data.interactionId
1409
- });
1410
-
1411
- // Validate that interaction ID exists
1412
- if (!this.data.interactionId) {
1413
- throw new Error('Invalid interaction ID');
1414
- }
1415
- const response = await this.contact.exitConference({
1416
- interactionId: this.data.interactionId
1417
- });
1418
-
1419
- // Track success metrics (following consultTransfer pattern)
1420
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_END_SUCCESS, {
1421
- taskId: this.data.interactionId,
1422
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1423
- }, ['operational', 'behavioral', 'business']);
1424
- _loggerProxy.default.log(`Consult conference exited successfully`, {
1425
- module: _constants.TASK_FILE,
1426
- method: _constants2.METHODS.EXIT_CONFERENCE,
1427
- interactionId: this.data.interactionId
1428
- });
1429
- return response;
1430
- } catch (error) {
1431
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.EXIT_CONFERENCE, _constants.TASK_FILE);
1432
- const taskErrorProps = {
1433
- trackingId: err.data?.trackingId,
1434
- errorMessage: err.data?.message,
1435
- errorType: err.data?.errorType,
1436
- errorData: err.data?.errorData,
1437
- reasonCode: err.data?.reasonCode
1438
- };
1439
-
1440
- // Track failure metrics (following consultTransfer pattern)
1441
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_END_FAILED, {
1442
- taskId: this.data.interactionId,
1443
- error: error.toString(),
1444
- ...taskErrorProps,
1445
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1446
- }, ['operational', 'behavioral', 'business']);
1447
- _loggerProxy.default.error(`Failed to exit consult conference`, {
1448
- module: _constants.TASK_FILE,
1449
- method: _constants2.METHODS.EXIT_CONFERENCE,
1450
- interactionId: this.data.interactionId
1451
- });
1452
- throw err;
1453
- }
1454
- }
1455
-
1456
- /**
1457
- * Transfers the current conference to another agent
1458
- *
1459
- * Moves the entire conference (including all participants) to a new agent,
1460
- * while the current agent exits and goes to wrapup
1461
- * On success, the current agent receives `task:conferenceEnded` event
1462
- *
1463
- * @returns Promise<TaskResponse> - Response from the conference transfer API
1464
- * @throws Error if the operation fails or if no active conference exists
1465
- *
1466
- * @example
1467
- * ```typescript
1468
- * try {
1469
- * await task.transferConference();
1470
- * console.log('Conference transferred successfully');
1471
- * } catch (error) {
1472
- * console.error('Failed to transfer conference:', error);
1473
- * }
1474
- * ```
1475
- */
1476
- async transferConference() {
1477
- try {
1478
- _loggerProxy.default.info(`Transferring conference`, {
1479
- module: _constants.TASK_FILE,
1480
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1481
- interactionId: this.data.interactionId
1482
- });
1483
-
1484
- // Validate that interaction ID exists
1485
- if (!this.data.interactionId) {
1486
- throw new Error('Invalid interaction ID');
1487
- }
1488
- const response = await this.contact.conferenceTransfer({
1489
- interactionId: this.data.interactionId
1490
- });
1491
-
1492
- // Track success metrics (following consultTransfer pattern)
1493
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_SUCCESS, {
1494
- taskId: this.data.interactionId,
1495
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1496
- }, ['operational', 'behavioral', 'business']);
1497
- _loggerProxy.default.log(`Conference transferred successfully`, {
1498
- module: _constants.TASK_FILE,
1499
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1500
- interactionId: this.data.interactionId
1501
- });
1502
- return response;
1503
- } catch (error) {
1504
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.TRANSFER_CONFERENCE, _constants.TASK_FILE);
1505
- const taskErrorProps = {
1506
- trackingId: err.data?.trackingId,
1507
- errorMessage: err.data?.message,
1508
- errorType: err.data?.errorType,
1509
- errorData: err.data?.errorData,
1510
- reasonCode: err.data?.reasonCode
1511
- };
1512
-
1513
- // Track failure metrics (following consultTransfer pattern)
1514
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_FAILED, {
1515
- taskId: this.data.interactionId,
1516
- error: error.toString(),
1517
- ...taskErrorProps,
1518
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1519
- }, ['operational', 'behavioral', 'business']);
1520
- _loggerProxy.default.error(`Failed to transfer conference`, {
1521
- module: _constants.TASK_FILE,
1522
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1523
- interactionId: this.data.interactionId
1524
- });
1525
- throw err;
1526
- }
1527
- }
1528
- }
1529
- exports.default = Task;
1530
- //# sourceMappingURL=index.js.map