@webex/contact-center 3.12.0-next.8 → 3.12.0-task-refactor.1

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 (200) 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 +65 -123
  24. package/dist/cc.js.map +1 -1
  25. package/dist/constants.js +13 -2
  26. package/dist/constants.js.map +1 -1
  27. package/dist/index.js +13 -5
  28. package/dist/index.js.map +1 -1
  29. package/dist/metrics/behavioral-events.js +26 -13
  30. package/dist/metrics/behavioral-events.js.map +1 -1
  31. package/dist/metrics/constants.js +7 -6
  32. package/dist/metrics/constants.js.map +1 -1
  33. package/dist/services/ApiAiAssistant.js +0 -3
  34. package/dist/services/ApiAiAssistant.js.map +1 -1
  35. package/dist/services/config/Util.js +2 -3
  36. package/dist/services/config/Util.js.map +1 -1
  37. package/dist/services/config/types.js +16 -14
  38. package/dist/services/config/types.js.map +1 -1
  39. package/dist/services/constants.js +0 -1
  40. package/dist/services/constants.js.map +1 -1
  41. package/dist/services/core/Err.js.map +1 -1
  42. package/dist/services/core/Utils.js +79 -55
  43. package/dist/services/core/Utils.js.map +1 -1
  44. package/dist/services/core/aqm-reqs.js +17 -92
  45. package/dist/services/core/aqm-reqs.js.map +1 -1
  46. package/dist/services/core/websocket/WebSocketManager.js +5 -25
  47. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  48. package/dist/services/core/websocket/types.js.map +1 -1
  49. package/dist/services/index.js +1 -2
  50. package/dist/services/index.js.map +1 -1
  51. package/dist/services/task/Task.js +644 -0
  52. package/dist/services/task/Task.js.map +1 -0
  53. package/dist/services/task/TaskFactory.js +45 -0
  54. package/dist/services/task/TaskFactory.js.map +1 -0
  55. package/dist/services/task/TaskManager.js +556 -532
  56. package/dist/services/task/TaskManager.js.map +1 -1
  57. package/dist/services/task/TaskUtils.js +132 -28
  58. package/dist/services/task/TaskUtils.js.map +1 -1
  59. package/dist/services/task/constants.js +7 -6
  60. package/dist/services/task/constants.js.map +1 -1
  61. package/dist/services/task/dialer.js +0 -51
  62. package/dist/services/task/dialer.js.map +1 -1
  63. package/dist/services/task/digital/Digital.js +77 -0
  64. package/dist/services/task/digital/Digital.js.map +1 -0
  65. package/dist/services/task/state-machine/TaskStateMachine.js +634 -0
  66. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  67. package/dist/services/task/state-machine/actions.js +366 -0
  68. package/dist/services/task/state-machine/actions.js.map +1 -0
  69. package/dist/services/task/state-machine/constants.js +139 -0
  70. package/dist/services/task/state-machine/constants.js.map +1 -0
  71. package/dist/services/task/state-machine/guards.js +256 -0
  72. package/dist/services/task/state-machine/guards.js.map +1 -0
  73. package/dist/services/task/state-machine/index.js +53 -0
  74. package/dist/services/task/state-machine/index.js.map +1 -0
  75. package/dist/services/task/state-machine/types.js +54 -0
  76. package/dist/services/task/state-machine/types.js.map +1 -0
  77. package/dist/services/task/state-machine/uiControlsComputer.js +369 -0
  78. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  79. package/dist/services/task/taskDataNormalizer.js +99 -0
  80. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  81. package/dist/services/task/types.js +157 -18
  82. package/dist/services/task/types.js.map +1 -1
  83. package/dist/services/task/voice/Voice.js +1031 -0
  84. package/dist/services/task/voice/Voice.js.map +1 -0
  85. package/dist/services/task/voice/WebRTC.js +149 -0
  86. package/dist/services/task/voice/WebRTC.js.map +1 -0
  87. package/dist/types/cc.d.ts +4 -33
  88. package/dist/types/constants.d.ts +13 -2
  89. package/dist/types/index.d.ts +11 -5
  90. package/dist/types/metrics/constants.d.ts +5 -3
  91. package/dist/types/services/ApiAiAssistant.d.ts +1 -1
  92. package/dist/types/services/config/types.d.ts +97 -25
  93. package/dist/types/services/core/Err.d.ts +0 -2
  94. package/dist/types/services/core/Utils.d.ts +25 -23
  95. package/dist/types/services/core/aqm-reqs.d.ts +0 -49
  96. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -1
  97. package/dist/types/services/core/websocket/connection-service.d.ts +0 -1
  98. package/dist/types/services/core/websocket/types.d.ts +1 -1
  99. package/dist/types/services/index.d.ts +1 -1
  100. package/dist/types/services/task/Task.d.ts +146 -0
  101. package/dist/types/services/task/TaskFactory.d.ts +12 -0
  102. package/dist/types/services/task/TaskUtils.d.ts +39 -8
  103. package/dist/types/services/task/constants.d.ts +5 -4
  104. package/dist/types/services/task/dialer.d.ts +0 -15
  105. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  106. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +906 -0
  107. package/dist/types/services/task/state-machine/actions.d.ts +8 -0
  108. package/dist/types/services/task/state-machine/constants.d.ts +91 -0
  109. package/dist/types/services/task/state-machine/guards.d.ts +78 -0
  110. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  111. package/dist/types/services/task/state-machine/types.d.ts +256 -0
  112. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  113. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  114. package/dist/types/services/task/types.d.ts +539 -88
  115. package/dist/types/services/task/voice/Voice.d.ts +183 -0
  116. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  117. package/dist/types/types.d.ts +68 -0
  118. package/dist/types/webex.d.ts +1 -0
  119. package/dist/types.js +70 -0
  120. package/dist/types.js.map +1 -1
  121. package/dist/webex.js +14 -2
  122. package/dist/webex.js.map +1 -1
  123. package/package.json +14 -11
  124. package/src/cc.ts +91 -177
  125. package/src/constants.ts +13 -2
  126. package/src/index.ts +14 -5
  127. package/src/metrics/ai-docs/AGENTS.md +348 -0
  128. package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
  129. package/src/metrics/behavioral-events.ts +28 -14
  130. package/src/metrics/constants.ts +7 -8
  131. package/src/services/ApiAiAssistant.ts +2 -4
  132. package/src/services/agent/ai-docs/AGENTS.md +238 -0
  133. package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
  134. package/src/services/ai-docs/AGENTS.md +384 -0
  135. package/src/services/config/Util.ts +2 -3
  136. package/src/services/config/ai-docs/AGENTS.md +253 -0
  137. package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
  138. package/src/services/config/types.ts +108 -20
  139. package/src/services/constants.ts +0 -1
  140. package/src/services/core/Err.ts +0 -1
  141. package/src/services/core/Utils.ts +90 -67
  142. package/src/services/core/ai-docs/AGENTS.md +379 -0
  143. package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
  144. package/src/services/core/aqm-reqs.ts +22 -100
  145. package/src/services/core/websocket/WebSocketManager.ts +4 -23
  146. package/src/services/core/websocket/types.ts +1 -1
  147. package/src/services/index.ts +1 -2
  148. package/src/services/task/Task.ts +785 -0
  149. package/src/services/task/TaskFactory.ts +55 -0
  150. package/src/services/task/TaskManager.ts +567 -633
  151. package/src/services/task/TaskUtils.ts +175 -31
  152. package/src/services/task/ai-docs/AGENTS.md +448 -0
  153. package/src/services/task/ai-docs/ARCHITECTURE.md +573 -0
  154. package/src/services/task/constants.ts +5 -4
  155. package/src/services/task/dialer.ts +1 -56
  156. package/src/services/task/digital/Digital.ts +95 -0
  157. package/src/services/task/state-machine/TaskStateMachine.ts +793 -0
  158. package/src/services/task/state-machine/actions.ts +409 -0
  159. package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
  160. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
  161. package/src/services/task/state-machine/constants.ts +150 -0
  162. package/src/services/task/state-machine/guards.ts +295 -0
  163. package/src/services/task/state-machine/index.ts +28 -0
  164. package/src/services/task/state-machine/types.ts +228 -0
  165. package/src/services/task/state-machine/uiControlsComputer.ts +529 -0
  166. package/src/services/task/taskDataNormalizer.ts +137 -0
  167. package/src/services/task/types.ts +641 -95
  168. package/src/services/task/voice/Voice.ts +1255 -0
  169. package/src/services/task/voice/WebRTC.ts +187 -0
  170. package/src/types.ts +88 -5
  171. package/src/utils/AGENTS.md +276 -0
  172. package/src/webex.js +2 -0
  173. package/test/unit/spec/cc.ts +59 -142
  174. package/test/unit/spec/logger-proxy.ts +70 -0
  175. package/test/unit/spec/services/ApiAiAssistant.ts +17 -0
  176. package/test/unit/spec/services/config/index.ts +26 -55
  177. package/test/unit/spec/services/core/Utils.ts +103 -52
  178. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +48 -112
  179. package/test/unit/spec/services/core/websocket/connection-service.ts +5 -4
  180. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  181. package/test/unit/spec/services/task/Task.ts +416 -0
  182. package/test/unit/spec/services/task/TaskFactory.ts +62 -0
  183. package/test/unit/spec/services/task/TaskManager.ts +781 -1735
  184. package/test/unit/spec/services/task/TaskUtils.ts +125 -0
  185. package/test/unit/spec/services/task/dialer.ts +112 -198
  186. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  187. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +473 -0
  188. package/test/unit/spec/services/task/state-machine/guards.ts +288 -0
  189. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  190. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +147 -0
  191. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  192. package/test/unit/spec/services/task/voice/Voice.ts +587 -0
  193. package/test/unit/spec/services/task/voice/WebRTC.ts +242 -0
  194. package/umd/contact-center.min.js +2 -2
  195. package/umd/contact-center.min.js.map +1 -1
  196. package/dist/services/task/index.js +0 -1525
  197. package/dist/services/task/index.js.map +0 -1
  198. package/dist/types/services/task/index.d.ts +0 -650
  199. package/src/services/task/index.ts +0 -1801
  200. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -1,1525 +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 effectiveMediaResourceId = mediaResourceId ?? this.data.mediaResourceId;
489
- const response = await this.contact.hold({
490
- interactionId: this.data.interactionId,
491
- data: {
492
- mediaResourceId: effectiveMediaResourceId
493
- }
494
- });
495
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_HOLD_SUCCESS, {
496
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response),
497
- taskId: this.data.interactionId,
498
- mediaResourceId: effectiveMediaResourceId
499
- }, ['operational', 'behavioral']);
500
- _loggerProxy.default.log(`Task placed on hold successfully`, {
501
- module: _constants.TASK_FILE,
502
- method: _constants2.METHODS.HOLD,
503
- trackingId: response.trackingId,
504
- interactionId: this.data.interactionId
505
- });
506
- return response;
507
- } catch (error) {
508
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.HOLD, _constants.TASK_FILE);
509
- const taskErrorProps = {
510
- trackingId: err.data?.trackingId,
511
- errorMessage: err.data?.message,
512
- errorType: err.data?.errorType,
513
- errorData: err.data?.errorData,
514
- reasonCode: err.data?.reasonCode
515
- };
516
- const effectiveMediaResourceId = mediaResourceId ?? this.data.mediaResourceId;
517
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_HOLD_FAILED, {
518
- taskId: this.data.interactionId,
519
- mediaResourceId: effectiveMediaResourceId,
520
- error: error.toString(),
521
- ...taskErrorProps,
522
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
523
- }, ['operational', 'behavioral']);
524
- throw err;
525
- }
526
- }
527
-
528
- /**
529
- * Resumes the task/interaction that was previously put on hold.
530
- * Emits task:resume event when successful. For voice tasks, this restores the audio.
531
- *
532
- * @param mediaResourceId - Optional media resource ID to use for the resume operation. If not provided, uses the task's current mediaResourceId from interaction media
533
- * @returns Promise<TaskResponse>
534
- * @throws Error if resume operation fails
535
- * @example
536
- * ```typescript
537
- * // Set up resume event handler
538
- * task.on(TASK_EVENTS.TASK_RESUME, () => {
539
- * console.log('Task resumed from hold');
540
- * // Update UI to show active state
541
- * document.getElementById('hold-btn').disabled = false;
542
- * document.getElementById('hold-indicator').style.display = 'none';
543
- * });
544
- *
545
- * // Resume task from hold
546
- * try {
547
- * await task.resume();
548
- * console.log('Successfully resumed task from hold');
549
- * } catch (error) {
550
- * console.error('Failed to resume task:', error);
551
- * // Handle error (e.g., show error message)
552
- * }
553
- *
554
- * // Resume task from hold with custom mediaResourceId
555
- * try {
556
- * await task.resume('custom-media-resource-id');
557
- * console.log('Successfully resumed task from hold with custom mediaResourceId');
558
- * } catch (error) {
559
- * console.error('Failed to resume task:', error);
560
- * }
561
- * ```
562
- */
563
- async resume(mediaResourceId) {
564
- try {
565
- _loggerProxy.default.info(`Resuming task`, {
566
- module: _constants.TASK_FILE,
567
- method: _constants2.METHODS.RESUME,
568
- interactionId: this.data.interactionId
569
- });
570
- const {
571
- mainInteractionId
572
- } = this.data.interaction;
573
- const defaultMediaResourceId = this.data.interaction.media[mainInteractionId]?.mediaResourceId;
574
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
575
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_RESUME_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_RESUME_FAILED]);
576
- const response = await this.contact.unHold({
577
- interactionId: this.data.interactionId,
578
- data: {
579
- mediaResourceId: effectiveMediaResourceId
580
- }
581
- });
582
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_SUCCESS, {
583
- taskId: this.data.interactionId,
584
- mainInteractionId,
585
- mediaResourceId: effectiveMediaResourceId,
586
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
587
- }, ['operational', 'behavioral']);
588
- _loggerProxy.default.log(`Task resumed successfully`, {
589
- module: _constants.TASK_FILE,
590
- method: _constants2.METHODS.RESUME,
591
- trackingId: response.trackingId,
592
- interactionId: this.data.interactionId
593
- });
594
- return response;
595
- } catch (error) {
596
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.RESUME, _constants.TASK_FILE);
597
- const mainInteractionId = this.data.interaction?.mainInteractionId;
598
- const defaultMediaResourceId = mainInteractionId ? this.data.interaction.media[mainInteractionId]?.mediaResourceId : '';
599
- const effectiveMediaResourceId = mediaResourceId ?? defaultMediaResourceId;
600
- const taskErrorProps = {
601
- trackingId: err.data?.trackingId,
602
- errorMessage: err.data?.message,
603
- errorType: err.data?.errorType,
604
- errorData: err.data?.errorData,
605
- reasonCode: err.data?.reasonCode
606
- };
607
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_FAILED, {
608
- taskId: this.data.interactionId,
609
- mainInteractionId,
610
- mediaResourceId: effectiveMediaResourceId,
611
- ...taskErrorProps,
612
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
613
- }, ['operational', 'behavioral']);
614
- throw err;
615
- }
616
- }
617
-
618
- /**
619
- * Ends the task/interaction with the customer.
620
- * Emits task:end event when successful. If task requires wrap-up,
621
- * this will be indicated in the task:end event data.
622
- *
623
- * @returns Promise<TaskResponse>
624
- * @throws Error if ending task fails
625
- * @example
626
- * ```typescript
627
- * // Set up task end event handler
628
- * task.on(TASK_EVENTS.TASK_END, (data) => {
629
- * console.log('Task ended:', task.data.interactionId);
630
- *
631
- * if (data.wrapUpRequired) {
632
- * // Show wrap-up form
633
- * showWrapupForm();
634
- * } else {
635
- * // Clean up and prepare for next task
636
- * cleanupTask();
637
- * }
638
- * });
639
- *
640
- * // End the task
641
- * try {
642
- * await task.end();
643
- * console.log('Task end request successful');
644
- * } catch (error) {
645
- * console.error('Failed to end task:', error);
646
- * // Handle error (e.g., show error message, retry option)
647
- * }
648
- *
649
- * function showWrapupForm() {
650
- * // Show wrap-up UI with required codes
651
- * document.getElementById('wrapup-form').style.display = 'block';
652
- * }
653
- *
654
- * function cleanupTask() {
655
- * // Reset UI state
656
- * document.getElementById('active-task').style.display = 'none';
657
- * document.getElementById('controls').style.display = 'none';
658
- * }
659
- * ```
660
- */
661
- async end() {
662
- try {
663
- _loggerProxy.default.info(`Ending task`, {
664
- module: _constants.TASK_FILE,
665
- method: _constants2.METHODS.END,
666
- interactionId: this.data.interactionId
667
- });
668
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_END_FAILED]);
669
- const response = await this.contact.end({
670
- interactionId: this.data.interactionId
671
- });
672
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, {
673
- taskId: this.data.interactionId,
674
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
675
- }, ['operational', 'behavioral', 'business']);
676
- _loggerProxy.default.log(`Task ended successfully`, {
677
- module: _constants.TASK_FILE,
678
- method: _constants2.METHODS.END,
679
- trackingId: response.trackingId,
680
- interactionId: this.data.interactionId
681
- });
682
- return response;
683
- } catch (error) {
684
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.END, _constants.TASK_FILE);
685
- const taskErrorProps = {
686
- trackingId: err.data?.trackingId,
687
- errorMessage: err.data?.message,
688
- errorType: err.data?.errorType,
689
- errorData: err.data?.errorData,
690
- reasonCode: err.data?.reasonCode
691
- };
692
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_FAILED, {
693
- taskId: this.data.interactionId,
694
- ...taskErrorProps,
695
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
696
- }, ['operational', 'behavioral', 'business']);
697
- throw err;
698
- }
699
- }
700
-
701
- /**
702
- * Wraps up the task/interaction with the customer.
703
- * This is called after task:end event if wrapUpRequired is true.
704
- * Emits task:wrappedup event when successful.
705
- *
706
- * @param wrapupPayload - WrapupPayLoad containing:
707
- * - auxCodeId: Required ID for the wrap-up code
708
- * - wrapUpReason: Required description of wrap-up reason
709
- * @returns Promise<TaskResponse>
710
- * @throws Error if task data is unavailable, auxCodeId is missing, or wrapUpReason is missing
711
- * @example
712
- * ```typescript
713
- * // Set up wrap-up events
714
- * task.on(TASK_EVENTS.TASK_WRAPUP, () => {
715
- * console.log('Task ready for wrap-up');
716
- * // Show wrap-up form
717
- * document.getElementById('wrapup-form').style.display = 'block';
718
- * });
719
- *
720
- * task.on(TASK_EVENTS.TASK_WRAPPEDUP, () => {
721
- * console.log('Task wrap-up completed');
722
- * // Clean up UI
723
- * document.getElementById('wrapup-form').style.display = 'none';
724
- * });
725
- *
726
- * // Submit wrap-up
727
- * try {
728
- * const wrapupPayload = {
729
- * auxCodeId: selectedCode, // e.g., 'ISSUE_RESOLVED'
730
- * wrapUpReason: 'Customer issue resolved successfully'
731
- * };
732
- * await task.wrapup(wrapupPayload);
733
- * console.log('Successfully submitted wrap-up');
734
- * } catch (error) {
735
- * console.error('Failed to submit wrap-up:', error);
736
- * // Handle validation errors
737
- * if (error.message.includes('required')) {
738
- * // Show validation error to agent
739
- * }
740
- * }
741
- * ```
742
- */
743
- async wrapup(wrapupPayload) {
744
- try {
745
- this.cancelAutoWrapupTimer();
746
- _loggerProxy.default.info(`Wrapping up task`, {
747
- module: _constants.TASK_FILE,
748
- method: _constants2.METHODS.WRAPUP,
749
- interactionId: this.data.interactionId
750
- });
751
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED]);
752
- if (!this.data) {
753
- throw new Error('No task data available');
754
- }
755
- if (!wrapupPayload.auxCodeId || wrapupPayload.auxCodeId.length === 0) {
756
- throw new Error('AuxCodeId is required');
757
- }
758
- if (!wrapupPayload.wrapUpReason || wrapupPayload.wrapUpReason.length === 0) {
759
- throw new Error('WrapUpReason is required');
760
- }
761
- const response = await this.contact.wrapup({
762
- interactionId: this.data.interactionId,
763
- data: wrapupPayload
764
- });
765
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, {
766
- taskId: this.data.interactionId,
767
- wrapUpCode: wrapupPayload.auxCodeId,
768
- wrapUpReason: wrapupPayload.wrapUpReason,
769
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
770
- }, ['operational', 'behavioral', 'business']);
771
- _loggerProxy.default.log(`Task wrapped up successfully`, {
772
- module: _constants.TASK_FILE,
773
- method: _constants2.METHODS.WRAPUP,
774
- trackingId: response.trackingId,
775
- interactionId: this.data.interactionId
776
- });
777
- return response;
778
- } catch (error) {
779
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.WRAPUP, _constants.TASK_FILE);
780
- const taskErrorProps = {
781
- trackingId: err.data?.trackingId,
782
- errorMessage: err.data?.message,
783
- errorType: err.data?.errorType,
784
- errorData: err.data?.errorData,
785
- reasonCode: err.data?.reasonCode
786
- };
787
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED, {
788
- taskId: this.data.interactionId,
789
- wrapUpCode: wrapupPayload.auxCodeId,
790
- wrapUpReason: wrapupPayload.wrapUpReason,
791
- ...taskErrorProps,
792
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
793
- }, ['operational', 'behavioral', 'business']);
794
- throw err;
795
- }
796
- }
797
-
798
- /**
799
- * Pauses the recording for the current voice task.
800
- * Emits task:recordingPaused event when successful.
801
- *
802
- * @returns Promise<TaskResponse>
803
- * @throws Error if pause recording fails
804
- * @example
805
- * ```typescript
806
- * // Set up recording events
807
- * task.on(TASK_EVENTS.TASK_RECORDING_PAUSED, () => {
808
- * console.log('Recording paused');
809
- * // Update UI to show recording paused state
810
- * document.getElementById('recording-status').textContent = 'Recording Paused';
811
- * document.getElementById('pause-recording-btn').style.display = 'none';
812
- * document.getElementById('resume-recording-btn').style.display = 'block';
813
- * });
814
- *
815
- * task.on(TASK_EVENTS.TASK_RECORDING_PAUSE_FAILED, (error) => {
816
- * console.error('Failed to pause recording:', error);
817
- * // Show error to agent
818
- * });
819
- *
820
- * // Pause recording
821
- * try {
822
- * await task.pauseRecording();
823
- * console.log('Pause recording request sent');
824
- * } catch (error) {
825
- * console.error('Error sending pause recording request:', error);
826
- * // Handle error
827
- * }
828
- * ```
829
- */
830
- async pauseRecording() {
831
- try {
832
- _loggerProxy.default.info(`Pausing recording`, {
833
- module: _constants.TASK_FILE,
834
- method: _constants2.METHODS.PAUSE_RECORDING,
835
- interactionId: this.data.interactionId
836
- });
837
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED]);
838
- const result = await this.contact.pauseRecording({
839
- interactionId: this.data.interactionId
840
- });
841
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS, {
842
- taskId: this.data.interactionId,
843
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
844
- }, ['operational', 'behavioral', 'business']);
845
- _loggerProxy.default.log(`Recording paused successfully`, {
846
- module: _constants.TASK_FILE,
847
- method: _constants2.METHODS.PAUSE_RECORDING,
848
- trackingId: result.trackingId,
849
- interactionId: this.data.interactionId
850
- });
851
- return result;
852
- } catch (error) {
853
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.PAUSE_RECORDING, _constants.TASK_FILE);
854
- const taskErrorProps = {
855
- trackingId: err.data?.trackingId,
856
- errorMessage: err.data?.message,
857
- errorType: err.data?.errorType,
858
- errorData: err.data?.errorData,
859
- reasonCode: err.data?.reasonCode
860
- };
861
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED, {
862
- taskId: this.data.interactionId,
863
- error: error.toString(),
864
- ...taskErrorProps,
865
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
866
- }, ['operational', 'behavioral', 'business']);
867
- throw err;
868
- }
869
- }
870
-
871
- /**
872
- * Resumes the recording for the voice task that was previously paused.
873
- * Emits task:recordingResumed event when successful.
874
- *
875
- * @param resumeRecordingPayload - Configuration for resuming recording:
876
- * - autoResumed: Indicates if resume was automatic (defaults to false)
877
- * @returns Promise<TaskResponse>
878
- * @throws Error if resume recording fails
879
- * @example
880
- * ```typescript
881
- * // Set up recording resume events
882
- * task.on(TASK_EVENTS.TASK_RECORDING_RESUMED, () => {
883
- * console.log('Recording resumed');
884
- * // Update UI to show active recording state
885
- * document.getElementById('recording-status').textContent = 'Recording Active';
886
- * document.getElementById('pause-recording-btn').style.display = 'block';
887
- * document.getElementById('resume-recording-btn').style.display = 'none';
888
- * });
889
- *
890
- * task.on(TASK_EVENTS.TASK_RECORDING_RESUME_FAILED, (error) => {
891
- * console.error('Failed to resume recording:', error);
892
- * // Show error to agent
893
- * });
894
- *
895
- * // Resume recording
896
- * try {
897
- * const resumePayload = {
898
- * autoResumed: false // Set to true if triggered by system
899
- * };
900
- * await task.resumeRecording(resumePayload);
901
- * console.log('Resume recording request sent');
902
- * } catch (error) {
903
- * console.error('Error sending resume recording request:', error);
904
- * // Handle error
905
- * }
906
- * ```
907
- */
908
- async resumeRecording(resumeRecordingPayload) {
909
- try {
910
- _loggerProxy.default.info(`Resuming recording`, {
911
- module: _constants.TASK_FILE,
912
- method: _constants2.METHODS.RESUME_RECORDING,
913
- interactionId: this.data.interactionId
914
- });
915
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED]);
916
- resumeRecordingPayload ??= {
917
- autoResumed: false
918
- };
919
- const result = await this.contact.resumeRecording({
920
- interactionId: this.data.interactionId,
921
- data: resumeRecordingPayload
922
- });
923
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS, {
924
- taskId: this.data.interactionId,
925
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
926
- }, ['operational', 'behavioral', 'business']);
927
- _loggerProxy.default.log(`Recording resumed successfully`, {
928
- module: _constants.TASK_FILE,
929
- method: _constants2.METHODS.RESUME_RECORDING,
930
- trackingId: result.trackingId,
931
- interactionId: this.data.interactionId
932
- });
933
- return result;
934
- } catch (error) {
935
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.RESUME_RECORDING, _constants.TASK_FILE);
936
- const taskErrorProps = {
937
- trackingId: err.data?.trackingId,
938
- errorMessage: err.data?.message,
939
- errorType: err.data?.errorType,
940
- errorData: err.data?.errorData,
941
- reasonCode: err.data?.reasonCode
942
- };
943
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED, {
944
- taskId: this.data.interactionId,
945
- error: error.toString(),
946
- ...taskErrorProps,
947
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
948
- }, ['operational', 'behavioral', 'business']);
949
- throw err;
950
- }
951
- }
952
-
953
- /**
954
- * Consults another agent or queue on an ongoing task for further assistance.
955
- * During consultation, the original customer is typically placed on hold while
956
- * the agent seeks guidance from another agent or queue.
957
- *
958
- * @param consultPayload - Configuration for the consultation containing:
959
- * - to: ID of the agent or queue to consult with
960
- * - destinationType: Type of destination (AGENT, QUEUE, etc.)
961
- * - holdParticipants: Whether to hold other participants (defaults to true)
962
- * @returns Promise<TaskResponse> - Resolves with consultation result
963
- * @throws Error if consultation fails or invalid parameters provided
964
- * @example
965
- * ```typescript
966
- * // Consult with another agent
967
- * const consultPayload = {
968
- * to: 'agentId123',
969
- * destinationType: DESTINATION_TYPE.AGENT,
970
- * holdParticipants: true
971
- * };
972
- * task.consult(consultPayload)
973
- * .then(response => console.log('Consultation started successfully'))
974
- * .catch(error => console.error('Failed to start consultation:', error));
975
- *
976
- * // Consult with a queue
977
- * const queueConsultPayload = {
978
- * to: 'salesQueue123',
979
- * destinationType: DESTINATION_TYPE.QUEUE
980
- * };
981
- * task.consult(queueConsultPayload)
982
- * .then(response => console.log('Queue consultation started'))
983
- * .catch(error => console.error('Failed to start queue consultation:', error));
984
- * ```
985
- */
986
- async consult(consultPayload) {
987
- try {
988
- _loggerProxy.default.info(`Starting consult`, {
989
- module: _constants.TASK_FILE,
990
- method: _constants2.METHODS.CONSULT,
991
- interactionId: this.data.interactionId
992
- });
993
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED]);
994
- const result = await this.contact.consult({
995
- interactionId: this.data.interactionId,
996
- data: consultPayload
997
- });
998
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS, {
999
- taskId: this.data.interactionId,
1000
- destination: consultPayload.to,
1001
- destinationType: consultPayload.destinationType,
1002
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1003
- }, ['operational', 'behavioral', 'business']);
1004
- _loggerProxy.default.log(`Consult started successfully to ${consultPayload.to}`, {
1005
- module: _constants.TASK_FILE,
1006
- method: _constants2.METHODS.CONSULT,
1007
- trackingId: result.trackingId,
1008
- interactionId: this.data.interactionId
1009
- });
1010
- return result;
1011
- } catch (error) {
1012
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT, _constants.TASK_FILE);
1013
- const taskErrorProps = {
1014
- trackingId: err.data?.trackingId,
1015
- errorMessage: err.data?.message,
1016
- errorType: err.data?.errorType,
1017
- errorData: err.data?.errorData,
1018
- reasonCode: err.data?.reasonCode
1019
- };
1020
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED, {
1021
- taskId: this.data.interactionId,
1022
- destination: consultPayload.to,
1023
- destinationType: consultPayload.destinationType,
1024
- error: error.toString(),
1025
- ...taskErrorProps,
1026
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1027
- }, ['operational', 'behavioral', 'business']);
1028
- throw err;
1029
- }
1030
- }
1031
-
1032
- /**
1033
- * Ends an ongoing consultation session for the task.
1034
- * This terminates the consultation while maintaining the original customer connection.
1035
- *
1036
- * @param consultEndPayload - Configuration for ending the consultation containing:
1037
- * - isConsult: Must be true to indicate this is a consultation end
1038
- * - taskId: ID of the task being consulted on
1039
- * - queueId: (Optional) Queue ID if this was a queue consultation
1040
- * - isSecondaryEpDnAgent: (Optional) Indicates if this involves a secondary entry point
1041
- * @returns Promise<TaskResponse> - Resolves when consultation is ended
1042
- * @throws Error if ending consultation fails or invalid parameters provided
1043
- * @example
1044
- * ```typescript
1045
- * // End a direct agent consultation
1046
- * const consultEndPayload = {
1047
- * isConsult: true,
1048
- * taskId: 'task123'
1049
- * };
1050
- * task.endConsult(consultEndPayload)
1051
- * .then(response => console.log('Consultation ended successfully'))
1052
- * .catch(error => console.error('Failed to end consultation:', error));
1053
- *
1054
- * // End a queue consultation
1055
- * const queueConsultEndPayload = {
1056
- * isConsult: true,
1057
- * taskId: 'task123',
1058
- * queueId: 'queue123'
1059
- * };
1060
- * task.endConsult(queueConsultEndPayload)
1061
- * .then(response => console.log('Queue consultation ended'))
1062
- * .catch(error => console.error('Failed to end queue consultation:', error));
1063
- * ```
1064
- */
1065
- async endConsult(consultEndPayload) {
1066
- try {
1067
- _loggerProxy.default.info(`Ending consult`, {
1068
- module: _constants.TASK_FILE,
1069
- method: _constants2.METHODS.END_CONSULT,
1070
- interactionId: this.data.interactionId
1071
- });
1072
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED]);
1073
- const result = await this.contact.consultEnd({
1074
- interactionId: this.data.interactionId,
1075
- data: consultEndPayload
1076
- });
1077
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS, {
1078
- taskId: this.data.interactionId,
1079
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1080
- }, ['operational', 'behavioral', 'business']);
1081
- _loggerProxy.default.log(`Consult ended successfully`, {
1082
- module: _constants.TASK_FILE,
1083
- method: _constants2.METHODS.END_CONSULT,
1084
- trackingId: result.trackingId,
1085
- interactionId: this.data.interactionId
1086
- });
1087
- return result;
1088
- } catch (error) {
1089
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.END_CONSULT, _constants.TASK_FILE);
1090
- const taskErrorProps = {
1091
- trackingId: err.data?.trackingId,
1092
- errorMessage: err.data?.message,
1093
- errorType: err.data?.errorType,
1094
- errorData: err.data?.errorData,
1095
- reasonCode: err.data?.reasonCode
1096
- };
1097
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED, {
1098
- taskId: this.data.interactionId,
1099
- error: error.toString(),
1100
- ...taskErrorProps,
1101
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1102
- }, ['operational', 'behavioral', 'business']);
1103
- throw err;
1104
- }
1105
- }
1106
-
1107
- /**
1108
- * Transfer the task to an agent directly or to a queue.
1109
- * This is a blind transfer that immediately redirects the task to the specified destination.
1110
- *
1111
- * @param transferPayload - Transfer configuration containing:
1112
- * - to: ID of the agent or queue to transfer to
1113
- * - destinationType: Type of destination (AGENT, QUEUE, etc.)
1114
- * @returns Promise<TaskResponse> - Resolves when transfer is completed
1115
- * @throws Error if transfer fails or invalid parameters provided
1116
- * @example
1117
- * ```typescript
1118
- * // Transfer to a queue
1119
- * const queueTransferPayload = {
1120
- * to: 'salesQueue123',
1121
- * destinationType: DESTINATION_TYPE.QUEUE
1122
- * };
1123
- * task.transfer(queueTransferPayload)
1124
- * .then(response => console.log('Task transferred to queue successfully'))
1125
- * .catch(error => console.error('Failed to transfer to queue:', error));
1126
- *
1127
- * // Transfer to an agent
1128
- * const agentTransferPayload = {
1129
- * to: 'agentId123',
1130
- * destinationType: DESTINATION_TYPE.AGENT
1131
- * };
1132
- * task.transfer(agentTransferPayload)
1133
- * .then(response => console.log('Task transferred to agent successfully'))
1134
- * .catch(error => console.error('Failed to transfer to agent:', error));
1135
- * ```
1136
- */
1137
- async transfer(transferPayload) {
1138
- try {
1139
- _loggerProxy.default.info(`Transferring task to ${transferPayload.to}`, {
1140
- module: _constants.TASK_FILE,
1141
- method: _constants2.METHODS.TRANSFER,
1142
- interactionId: this.data.interactionId
1143
- });
1144
- this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED]);
1145
- let result;
1146
- if (transferPayload.destinationType === _types2.DESTINATION_TYPE.QUEUE) {
1147
- result = await this.contact.vteamTransfer({
1148
- interactionId: this.data.interactionId,
1149
- data: transferPayload
1150
- });
1151
- } else {
1152
- result = await this.contact.blindTransfer({
1153
- interactionId: this.data.interactionId,
1154
- data: transferPayload
1155
- });
1156
- }
1157
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, {
1158
- taskId: this.data.interactionId,
1159
- destination: transferPayload.to,
1160
- destinationType: transferPayload.destinationType,
1161
- isConsultTransfer: false,
1162
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1163
- }, ['operational', 'behavioral', 'business']);
1164
- _loggerProxy.default.log(`Task transferred successfully to ${transferPayload.to}`, {
1165
- module: _constants.TASK_FILE,
1166
- method: _constants2.METHODS.TRANSFER,
1167
- trackingId: result.trackingId,
1168
- interactionId: this.data.interactionId
1169
- });
1170
- return result;
1171
- } catch (error) {
1172
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.TRANSFER, _constants.TASK_FILE);
1173
- const taskErrorProps = {
1174
- trackingId: err.data?.trackingId,
1175
- errorMessage: err.data?.message,
1176
- errorType: err.data?.errorType,
1177
- errorData: err.data?.errorData,
1178
- reasonCode: err.data?.reasonCode
1179
- };
1180
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED, {
1181
- taskId: this.data.interactionId,
1182
- destination: transferPayload.to,
1183
- destinationType: transferPayload.destinationType,
1184
- isConsultTransfer: false,
1185
- error: error.toString(),
1186
- ...taskErrorProps,
1187
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1188
- }, ['operational', 'behavioral', 'business']);
1189
- throw err;
1190
- }
1191
- }
1192
-
1193
- /**
1194
- * Transfer the task to the party that was consulted.
1195
- * This completes a consultative transfer where the agent first consulted with the target
1196
- * before transferring the task. For queue consultations, the transfer is automatically
1197
- * directed to the agent who accepted the consultation.
1198
- *
1199
- * @param consultTransferPayload - Configuration for the consultation transfer containing:
1200
- * - to: ID of the agent or queue to transfer to
1201
- * - destinationType: Type of destination (AGENT, QUEUE, etc. from CONSULT_TRANSFER_DESTINATION_TYPE)
1202
- * @returns Promise<TaskResponse> - Resolves when consultation transfer is completed
1203
- * @throws Error if transfer fails, no agent has accepted a queue consultation, or other validation errors
1204
- * @example
1205
- * ```typescript
1206
- * // Complete consultation transfer to an agent
1207
- * const agentConsultTransfer = {
1208
- * to: 'agentId123',
1209
- * destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.AGENT
1210
- * };
1211
- * task.consultTransfer(agentConsultTransfer)
1212
- * .then(response => console.log('Consultation transfer to agent completed'))
1213
- * .catch(error => console.error('Failed to complete agent consultation transfer:', error));
1214
- *
1215
- * // Complete consultation transfer to a queue agent
1216
- * const queueConsultTransfer = {
1217
- * to: 'queue123',
1218
- * destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE
1219
- * };
1220
- * task.consultTransfer(queueConsultTransfer)
1221
- * .then(response => console.log('Consultation transfer to queue agent completed'))
1222
- * .catch(error => console.error('Failed to complete queue consultation transfer:', error));
1223
- * ```
1224
- */
1225
- async consultTransfer(consultTransferPayload) {
1226
- // Get the destination agent ID using custom logic from participants data
1227
- const destAgentId = (0, _Utils.calculateDestAgentId)(this.data.interaction, this.agentId);
1228
-
1229
- // Resolve the target id (queue consult transfers go to the accepted agent)
1230
- if (!destAgentId) {
1231
- throw new Error('No agent has accepted this queue consult yet');
1232
- }
1233
- _loggerProxy.default.info(`Initiating consult transfer to ${consultTransferPayload?.to || destAgentId}`, {
1234
- module: _constants.TASK_FILE,
1235
- method: _constants2.METHODS.CONSULT_TRANSFER,
1236
- interactionId: this.data.interactionId
1237
- });
1238
-
1239
- // Derive destination type from the participant's type property
1240
- const destType = (0, _Utils.calculateDestType)(this.data.interaction, this.agentId);
1241
- // By default we always use the computed destAgentId as the target id
1242
- const consultTransferRequest = {
1243
- to: destAgentId,
1244
- destinationType: destType
1245
- };
1246
- try {
1247
- const result = await this.contact.consultTransfer({
1248
- interactionId: this.data.interactionId,
1249
- data: consultTransferRequest
1250
- });
1251
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, {
1252
- taskId: this.data.interactionId,
1253
- destination: consultTransferRequest.to,
1254
- destinationType: consultTransferRequest.destinationType,
1255
- isConsultTransfer: true,
1256
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
1257
- }, ['operational', 'behavioral', 'business']);
1258
- _loggerProxy.default.log(`Consult transfer completed successfully to ${consultTransferPayload?.to || destAgentId}`, {
1259
- module: _constants.TASK_FILE,
1260
- method: _constants2.METHODS.CONSULT_TRANSFER,
1261
- trackingId: result.trackingId,
1262
- interactionId: this.data.interactionId
1263
- });
1264
- return result;
1265
- } catch (error) {
1266
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT_TRANSFER, _constants.TASK_FILE);
1267
- const taskErrorProps = {
1268
- trackingId: err.data?.trackingId,
1269
- errorMessage: err.data?.message,
1270
- errorType: err.data?.errorType,
1271
- errorData: err.data?.errorData,
1272
- reasonCode: err.data?.reasonCode
1273
- };
1274
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED, {
1275
- taskId: this.data.interactionId,
1276
- destination: destAgentId || '',
1277
- destinationType: destType,
1278
- isConsultTransfer: true,
1279
- error: error.toString(),
1280
- ...taskErrorProps,
1281
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1282
- }, ['operational', 'behavioral', 'business']);
1283
- throw err;
1284
- }
1285
- }
1286
-
1287
- /**
1288
- * Starts a consultation conference by merging the consultation call with the main call
1289
- *
1290
- * Creates a three-way conference between the agent, customer, and consulted party
1291
- * Extracts required consultation data from the current task data
1292
- * On success, emits a `task:conferenceStarted` event
1293
- *
1294
- * @returns Promise<TaskResponse> - Response from the consultation conference API
1295
- * @throws Error if the operation fails or if consultation data is invalid
1296
- *
1297
- * @example
1298
- * ```typescript
1299
- * try {
1300
- * await task.consultConference();
1301
- * console.log('Conference started successfully');
1302
- * } catch (error) {
1303
- * console.error('Failed to start conference:', error);
1304
- * }
1305
- * ```
1306
- */
1307
- async consultConference() {
1308
- // Get the destination agent ID dynamically from participants
1309
- // This handles multi-party conference scenarios, CBT (Capacity Based Team), and EP-DN cases
1310
- const destAgentId = (0, _Utils.calculateDestAgentId)(this.data.interaction, this.agentId);
1311
-
1312
- // Validate that we have a destination agent (for queue consult scenarios)
1313
- if (!destAgentId) {
1314
- throw new Error('No agent has accepted this queue consult yet');
1315
- }
1316
-
1317
- // Get the destination agent ID for fetching destination type
1318
- // This helps determine the correct participant type for CBT (Capacity Based Team) and EP-DN scenarios
1319
- const destAgentType = (0, _Utils.calculateDestType)(this.data.interaction, this.agentId);
1320
-
1321
- // Extract consultation conference data from task data (used in both try and catch)
1322
- const consultationData = {
1323
- agentId: this.agentId,
1324
- to: destAgentId,
1325
- destinationType: destAgentType || this.data.destinationType || 'agent'
1326
- };
1327
- try {
1328
- _loggerProxy.default.info(`Initiating consult conference to ${destAgentId}`, {
1329
- module: _constants.TASK_FILE,
1330
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1331
- interactionId: this.data.interactionId
1332
- });
1333
- const response = await this.contact.consultConference({
1334
- interactionId: this.data.interactionId,
1335
- data: consultationData
1336
- });
1337
-
1338
- // Track success metrics (following consultTransfer pattern)
1339
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_START_SUCCESS, {
1340
- taskId: this.data.interactionId,
1341
- destination: consultationData.to,
1342
- destinationType: consultationData.destinationType,
1343
- agentId: consultationData.agentId,
1344
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1345
- }, ['operational', 'behavioral', 'business']);
1346
- _loggerProxy.default.log(`Consult conference started successfully`, {
1347
- module: _constants.TASK_FILE,
1348
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1349
- interactionId: this.data.interactionId
1350
- });
1351
- return response;
1352
- } catch (error) {
1353
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.CONSULT_CONFERENCE, _constants.TASK_FILE);
1354
- const taskErrorProps = {
1355
- trackingId: err.data?.trackingId,
1356
- errorMessage: err.data?.message,
1357
- errorType: err.data?.errorType,
1358
- errorData: err.data?.errorData,
1359
- reasonCode: err.data?.reasonCode
1360
- };
1361
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_START_FAILED, {
1362
- taskId: this.data.interactionId,
1363
- destination: consultationData.to,
1364
- destinationType: consultationData.destinationType,
1365
- agentId: consultationData.agentId,
1366
- error: error.toString(),
1367
- ...taskErrorProps,
1368
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1369
- }, ['operational', 'behavioral', 'business']);
1370
- _loggerProxy.default.error(`Failed to start consult conference`, {
1371
- module: _constants.TASK_FILE,
1372
- method: _constants2.METHODS.CONSULT_CONFERENCE,
1373
- interactionId: this.data.interactionId
1374
- });
1375
- throw err;
1376
- }
1377
- }
1378
-
1379
- /**
1380
- * Exits the current conference by removing the agent from the conference call
1381
- *
1382
- * Exits the agent from the conference, leaving the customer and consulted party connected
1383
- * On success, emits a `task:conferenceEnded` event
1384
- *
1385
- * @returns Promise<TaskResponse> - Response from the conference exit API
1386
- * @throws Error if the operation fails or if no active conference exists
1387
- *
1388
- * @example
1389
- * ```typescript
1390
- * try {
1391
- * await task.exitConference();
1392
- * console.log('Successfully exited conference');
1393
- * } catch (error) {
1394
- * console.error('Failed to exit conference:', error);
1395
- * }
1396
- * ```
1397
- */
1398
- async exitConference() {
1399
- try {
1400
- _loggerProxy.default.info(`Exiting consult conference`, {
1401
- module: _constants.TASK_FILE,
1402
- method: _constants2.METHODS.EXIT_CONFERENCE,
1403
- interactionId: this.data.interactionId
1404
- });
1405
-
1406
- // Validate that interaction ID exists
1407
- if (!this.data.interactionId) {
1408
- throw new Error('Invalid interaction ID');
1409
- }
1410
- const response = await this.contact.exitConference({
1411
- interactionId: this.data.interactionId
1412
- });
1413
-
1414
- // Track success metrics (following consultTransfer pattern)
1415
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_END_SUCCESS, {
1416
- taskId: this.data.interactionId,
1417
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1418
- }, ['operational', 'behavioral', 'business']);
1419
- _loggerProxy.default.log(`Consult conference exited successfully`, {
1420
- module: _constants.TASK_FILE,
1421
- method: _constants2.METHODS.EXIT_CONFERENCE,
1422
- interactionId: this.data.interactionId
1423
- });
1424
- return response;
1425
- } catch (error) {
1426
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.EXIT_CONFERENCE, _constants.TASK_FILE);
1427
- const taskErrorProps = {
1428
- trackingId: err.data?.trackingId,
1429
- errorMessage: err.data?.message,
1430
- errorType: err.data?.errorType,
1431
- errorData: err.data?.errorData,
1432
- reasonCode: err.data?.reasonCode
1433
- };
1434
-
1435
- // Track failure metrics (following consultTransfer pattern)
1436
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_END_FAILED, {
1437
- taskId: this.data.interactionId,
1438
- error: error.toString(),
1439
- ...taskErrorProps,
1440
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1441
- }, ['operational', 'behavioral', 'business']);
1442
- _loggerProxy.default.error(`Failed to exit consult conference`, {
1443
- module: _constants.TASK_FILE,
1444
- method: _constants2.METHODS.EXIT_CONFERENCE,
1445
- interactionId: this.data.interactionId
1446
- });
1447
- throw err;
1448
- }
1449
- }
1450
-
1451
- /**
1452
- * Transfers the current conference to another agent
1453
- *
1454
- * Moves the entire conference (including all participants) to a new agent,
1455
- * while the current agent exits and goes to wrapup
1456
- * On success, the current agent receives `task:conferenceEnded` event
1457
- *
1458
- * @returns Promise<TaskResponse> - Response from the conference transfer API
1459
- * @throws Error if the operation fails or if no active conference exists
1460
- *
1461
- * @example
1462
- * ```typescript
1463
- * try {
1464
- * await task.transferConference();
1465
- * console.log('Conference transferred successfully');
1466
- * } catch (error) {
1467
- * console.error('Failed to transfer conference:', error);
1468
- * }
1469
- * ```
1470
- */
1471
- async transferConference() {
1472
- try {
1473
- _loggerProxy.default.info(`Transferring conference`, {
1474
- module: _constants.TASK_FILE,
1475
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1476
- interactionId: this.data.interactionId
1477
- });
1478
-
1479
- // Validate that interaction ID exists
1480
- if (!this.data.interactionId) {
1481
- throw new Error('Invalid interaction ID');
1482
- }
1483
- const response = await this.contact.conferenceTransfer({
1484
- interactionId: this.data.interactionId
1485
- });
1486
-
1487
- // Track success metrics (following consultTransfer pattern)
1488
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_SUCCESS, {
1489
- taskId: this.data.interactionId,
1490
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
1491
- }, ['operational', 'behavioral', 'business']);
1492
- _loggerProxy.default.log(`Conference transferred successfully`, {
1493
- module: _constants.TASK_FILE,
1494
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1495
- interactionId: this.data.interactionId
1496
- });
1497
- return response;
1498
- } catch (error) {
1499
- const err = (0, _Utils.generateTaskErrorObject)(error, _constants2.METHODS.TRANSFER_CONFERENCE, _constants.TASK_FILE);
1500
- const taskErrorProps = {
1501
- trackingId: err.data?.trackingId,
1502
- errorMessage: err.data?.message,
1503
- errorType: err.data?.errorType,
1504
- errorData: err.data?.errorData,
1505
- reasonCode: err.data?.reasonCode
1506
- };
1507
-
1508
- // Track failure metrics (following consultTransfer pattern)
1509
- this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_FAILED, {
1510
- taskId: this.data.interactionId,
1511
- error: error.toString(),
1512
- ...taskErrorProps,
1513
- ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
1514
- }, ['operational', 'behavioral', 'business']);
1515
- _loggerProxy.default.error(`Failed to transfer conference`, {
1516
- module: _constants.TASK_FILE,
1517
- method: _constants2.METHODS.TRANSFER_CONFERENCE,
1518
- interactionId: this.data.interactionId
1519
- });
1520
- throw err;
1521
- }
1522
- }
1523
- }
1524
- exports.default = Task;
1525
- //# sourceMappingURL=index.js.map