@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.
- package/AGENTS.md +438 -0
- package/ai-docs/README.md +131 -0
- package/ai-docs/RULES.md +455 -0
- package/ai-docs/patterns/event-driven-patterns.md +485 -0
- package/ai-docs/patterns/testing-patterns.md +480 -0
- package/ai-docs/patterns/typescript-patterns.md +365 -0
- package/ai-docs/templates/README.md +102 -0
- package/ai-docs/templates/documentation/create-agents-md.md +240 -0
- package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
- package/ai-docs/templates/existing-service/bug-fix.md +254 -0
- package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
- package/ai-docs/templates/new-method/00-master.md +80 -0
- package/ai-docs/templates/new-method/01-requirements.md +232 -0
- package/ai-docs/templates/new-method/02-implementation.md +295 -0
- package/ai-docs/templates/new-method/03-tests.md +201 -0
- package/ai-docs/templates/new-method/04-validation.md +141 -0
- package/ai-docs/templates/new-service/00-master.md +109 -0
- package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
- package/ai-docs/templates/new-service/02-code-generation.md +346 -0
- package/ai-docs/templates/new-service/03-integration.md +178 -0
- package/ai-docs/templates/new-service/04-test-generation.md +205 -0
- package/ai-docs/templates/new-service/05-validation.md +145 -0
- package/dist/cc.js +65 -123
- package/dist/cc.js.map +1 -1
- package/dist/constants.js +13 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/metrics/behavioral-events.js +26 -13
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +7 -6
- package/dist/metrics/constants.js.map +1 -1
- package/dist/services/ApiAiAssistant.js +0 -3
- package/dist/services/ApiAiAssistant.js.map +1 -1
- package/dist/services/config/Util.js +2 -3
- package/dist/services/config/Util.js.map +1 -1
- package/dist/services/config/types.js +16 -14
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/constants.js +0 -1
- package/dist/services/constants.js.map +1 -1
- package/dist/services/core/Err.js.map +1 -1
- package/dist/services/core/Utils.js +79 -55
- package/dist/services/core/Utils.js.map +1 -1
- package/dist/services/core/aqm-reqs.js +17 -92
- package/dist/services/core/aqm-reqs.js.map +1 -1
- package/dist/services/core/websocket/WebSocketManager.js +5 -25
- package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
- package/dist/services/core/websocket/types.js.map +1 -1
- package/dist/services/index.js +1 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/task/Task.js +644 -0
- package/dist/services/task/Task.js.map +1 -0
- package/dist/services/task/TaskFactory.js +45 -0
- package/dist/services/task/TaskFactory.js.map +1 -0
- package/dist/services/task/TaskManager.js +556 -532
- package/dist/services/task/TaskManager.js.map +1 -1
- package/dist/services/task/TaskUtils.js +132 -28
- package/dist/services/task/TaskUtils.js.map +1 -1
- package/dist/services/task/constants.js +7 -6
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/dialer.js +0 -51
- package/dist/services/task/dialer.js.map +1 -1
- package/dist/services/task/digital/Digital.js +77 -0
- package/dist/services/task/digital/Digital.js.map +1 -0
- package/dist/services/task/state-machine/TaskStateMachine.js +634 -0
- package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
- package/dist/services/task/state-machine/actions.js +366 -0
- package/dist/services/task/state-machine/actions.js.map +1 -0
- package/dist/services/task/state-machine/constants.js +139 -0
- package/dist/services/task/state-machine/constants.js.map +1 -0
- package/dist/services/task/state-machine/guards.js +256 -0
- package/dist/services/task/state-machine/guards.js.map +1 -0
- package/dist/services/task/state-machine/index.js +53 -0
- package/dist/services/task/state-machine/index.js.map +1 -0
- package/dist/services/task/state-machine/types.js +54 -0
- package/dist/services/task/state-machine/types.js.map +1 -0
- package/dist/services/task/state-machine/uiControlsComputer.js +369 -0
- package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
- package/dist/services/task/taskDataNormalizer.js +99 -0
- package/dist/services/task/taskDataNormalizer.js.map +1 -0
- package/dist/services/task/types.js +157 -18
- package/dist/services/task/types.js.map +1 -1
- package/dist/services/task/voice/Voice.js +1031 -0
- package/dist/services/task/voice/Voice.js.map +1 -0
- package/dist/services/task/voice/WebRTC.js +149 -0
- package/dist/services/task/voice/WebRTC.js.map +1 -0
- package/dist/types/cc.d.ts +4 -33
- package/dist/types/constants.d.ts +13 -2
- package/dist/types/index.d.ts +11 -5
- package/dist/types/metrics/constants.d.ts +5 -3
- package/dist/types/services/ApiAiAssistant.d.ts +1 -1
- package/dist/types/services/config/types.d.ts +97 -25
- package/dist/types/services/core/Err.d.ts +0 -2
- package/dist/types/services/core/Utils.d.ts +25 -23
- package/dist/types/services/core/aqm-reqs.d.ts +0 -49
- package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -1
- package/dist/types/services/core/websocket/connection-service.d.ts +0 -1
- package/dist/types/services/core/websocket/types.d.ts +1 -1
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/services/task/Task.d.ts +146 -0
- package/dist/types/services/task/TaskFactory.d.ts +12 -0
- package/dist/types/services/task/TaskUtils.d.ts +39 -8
- package/dist/types/services/task/constants.d.ts +5 -4
- package/dist/types/services/task/dialer.d.ts +0 -15
- package/dist/types/services/task/digital/Digital.d.ts +22 -0
- package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +906 -0
- package/dist/types/services/task/state-machine/actions.d.ts +8 -0
- package/dist/types/services/task/state-machine/constants.d.ts +91 -0
- package/dist/types/services/task/state-machine/guards.d.ts +78 -0
- package/dist/types/services/task/state-machine/index.d.ts +13 -0
- package/dist/types/services/task/state-machine/types.d.ts +256 -0
- package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
- package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
- package/dist/types/services/task/types.d.ts +539 -88
- package/dist/types/services/task/voice/Voice.d.ts +183 -0
- package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
- package/dist/types/types.d.ts +68 -0
- package/dist/types/webex.d.ts +1 -0
- package/dist/types.js +70 -0
- package/dist/types.js.map +1 -1
- package/dist/webex.js +14 -2
- package/dist/webex.js.map +1 -1
- package/package.json +14 -11
- package/src/cc.ts +91 -177
- package/src/constants.ts +13 -2
- package/src/index.ts +14 -5
- package/src/metrics/ai-docs/AGENTS.md +348 -0
- package/src/metrics/ai-docs/ARCHITECTURE.md +336 -0
- package/src/metrics/behavioral-events.ts +28 -14
- package/src/metrics/constants.ts +7 -8
- package/src/services/ApiAiAssistant.ts +2 -4
- package/src/services/agent/ai-docs/AGENTS.md +238 -0
- package/src/services/agent/ai-docs/ARCHITECTURE.md +302 -0
- package/src/services/ai-docs/AGENTS.md +384 -0
- package/src/services/config/Util.ts +2 -3
- package/src/services/config/ai-docs/AGENTS.md +253 -0
- package/src/services/config/ai-docs/ARCHITECTURE.md +424 -0
- package/src/services/config/types.ts +108 -20
- package/src/services/constants.ts +0 -1
- package/src/services/core/Err.ts +0 -1
- package/src/services/core/Utils.ts +90 -67
- package/src/services/core/ai-docs/AGENTS.md +379 -0
- package/src/services/core/ai-docs/ARCHITECTURE.md +696 -0
- package/src/services/core/aqm-reqs.ts +22 -100
- package/src/services/core/websocket/WebSocketManager.ts +4 -23
- package/src/services/core/websocket/types.ts +1 -1
- package/src/services/index.ts +1 -2
- package/src/services/task/Task.ts +785 -0
- package/src/services/task/TaskFactory.ts +55 -0
- package/src/services/task/TaskManager.ts +567 -633
- package/src/services/task/TaskUtils.ts +175 -31
- package/src/services/task/ai-docs/AGENTS.md +448 -0
- package/src/services/task/ai-docs/ARCHITECTURE.md +573 -0
- package/src/services/task/constants.ts +5 -4
- package/src/services/task/dialer.ts +1 -56
- package/src/services/task/digital/Digital.ts +95 -0
- package/src/services/task/state-machine/TaskStateMachine.ts +793 -0
- package/src/services/task/state-machine/actions.ts +409 -0
- package/src/services/task/state-machine/ai-docs/AGENTS.md +495 -0
- package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1135 -0
- package/src/services/task/state-machine/constants.ts +150 -0
- package/src/services/task/state-machine/guards.ts +295 -0
- package/src/services/task/state-machine/index.ts +28 -0
- package/src/services/task/state-machine/types.ts +228 -0
- package/src/services/task/state-machine/uiControlsComputer.ts +529 -0
- package/src/services/task/taskDataNormalizer.ts +137 -0
- package/src/services/task/types.ts +641 -95
- package/src/services/task/voice/Voice.ts +1255 -0
- package/src/services/task/voice/WebRTC.ts +187 -0
- package/src/types.ts +88 -5
- package/src/utils/AGENTS.md +276 -0
- package/src/webex.js +2 -0
- package/test/unit/spec/cc.ts +59 -142
- package/test/unit/spec/logger-proxy.ts +70 -0
- package/test/unit/spec/services/ApiAiAssistant.ts +17 -0
- package/test/unit/spec/services/config/index.ts +26 -55
- package/test/unit/spec/services/core/Utils.ts +103 -52
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +48 -112
- package/test/unit/spec/services/core/websocket/connection-service.ts +5 -4
- package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
- package/test/unit/spec/services/task/Task.ts +416 -0
- package/test/unit/spec/services/task/TaskFactory.ts +62 -0
- package/test/unit/spec/services/task/TaskManager.ts +781 -1735
- package/test/unit/spec/services/task/TaskUtils.ts +125 -0
- package/test/unit/spec/services/task/dialer.ts +112 -198
- package/test/unit/spec/services/task/digital/Digital.ts +105 -0
- package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +473 -0
- package/test/unit/spec/services/task/state-machine/guards.ts +288 -0
- package/test/unit/spec/services/task/state-machine/types.ts +18 -0
- package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +147 -0
- package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
- package/test/unit/spec/services/task/voice/Voice.ts +587 -0
- package/test/unit/spec/services/task/voice/WebRTC.ts +242 -0
- package/umd/contact-center.min.js +2 -2
- package/umd/contact-center.min.js.map +1 -1
- package/dist/services/task/index.js +0 -1525
- package/dist/services/task/index.js.map +0 -1
- package/dist/types/services/task/index.d.ts +0 -650
- package/src/services/task/index.ts +0 -1801
- package/test/unit/spec/services/task/index.ts +0 -2184
|
@@ -0,0 +1,1255 @@
|
|
|
1
|
+
import {CC_FILE, METHODS} from '../../../constants';
|
|
2
|
+
import {
|
|
3
|
+
buildConsultConferenceParamData,
|
|
4
|
+
calculateDestAgentId,
|
|
5
|
+
calculateDestType,
|
|
6
|
+
getErrorDetails,
|
|
7
|
+
} from '../../core/Utils';
|
|
8
|
+
import routingContact from '../contact';
|
|
9
|
+
import {
|
|
10
|
+
ConsultPayload,
|
|
11
|
+
ConsultEndPayload,
|
|
12
|
+
ResumeRecordingPayload,
|
|
13
|
+
TaskData,
|
|
14
|
+
TaskResponse,
|
|
15
|
+
IVoice,
|
|
16
|
+
VoiceUIControlOptions,
|
|
17
|
+
TransferPayLoad,
|
|
18
|
+
ConsultTransferPayLoad,
|
|
19
|
+
consultConferencePayloadData,
|
|
20
|
+
CONSULT_TRANSFER_DESTINATION_TYPE,
|
|
21
|
+
TASK_EVENTS,
|
|
22
|
+
VOICE_VARIANT,
|
|
23
|
+
} from '../types';
|
|
24
|
+
import Task from '../Task';
|
|
25
|
+
import LoggerProxy from '../../../logger-proxy';
|
|
26
|
+
import MetricsManager from '../../../metrics/MetricsManager';
|
|
27
|
+
import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
|
|
28
|
+
import {TaskState, TaskEvent} from '../state-machine';
|
|
29
|
+
import {WrapupData} from '../../config/types';
|
|
30
|
+
import {getConsultMediaResourceId, getIsConferenceInProgress} from '../TaskUtils';
|
|
31
|
+
|
|
32
|
+
export default class Voice extends Task implements IVoice {
|
|
33
|
+
constructor(
|
|
34
|
+
contact: ReturnType<typeof routingContact>,
|
|
35
|
+
data: TaskData,
|
|
36
|
+
callOptions?: VoiceUIControlOptions,
|
|
37
|
+
wrapupData?: WrapupData,
|
|
38
|
+
agentId?: string
|
|
39
|
+
) {
|
|
40
|
+
const resolvedOptions = {
|
|
41
|
+
isEndTaskEnabled: callOptions?.isEndTaskEnabled ?? true,
|
|
42
|
+
isEndConsultEnabled: callOptions?.isEndConsultEnabled ?? true,
|
|
43
|
+
voiceVariant: callOptions?.voiceVariant ?? VOICE_VARIANT.PSTN,
|
|
44
|
+
isRecordingEnabled: callOptions?.isRecordingEnabled ?? true,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
super(
|
|
48
|
+
contact,
|
|
49
|
+
data,
|
|
50
|
+
{
|
|
51
|
+
...resolvedOptions,
|
|
52
|
+
},
|
|
53
|
+
wrapupData,
|
|
54
|
+
agentId
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private getStateMachineSnapshot() {
|
|
59
|
+
return this.stateMachineService?.getSnapshot?.();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This method is used to accept the task.
|
|
64
|
+
* It is expected to be overridden by child classes.
|
|
65
|
+
* @returns Promise<TaskResponse>
|
|
66
|
+
* @throws Error
|
|
67
|
+
*/
|
|
68
|
+
public async accept(): Promise<TaskResponse> {
|
|
69
|
+
super.unsupportedMethodError(METHODS.ACCEPT);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* This method is used to decline the task.
|
|
74
|
+
* It is expected to be overridden by child classes.
|
|
75
|
+
* @returns Promise<TaskResponse>
|
|
76
|
+
* @throws Error
|
|
77
|
+
*/
|
|
78
|
+
public async decline(): Promise<TaskResponse> {
|
|
79
|
+
super.unsupportedMethodError(METHODS.REJECT);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* This is used to hold the task.
|
|
84
|
+
* @returns Promise<TaskResponse>
|
|
85
|
+
* @throws Error
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* task.hold().then(()=>{}).catch(()=>{})
|
|
89
|
+
* ```
|
|
90
|
+
* */
|
|
91
|
+
public async hold(): Promise<TaskResponse> {
|
|
92
|
+
return this.holdResume();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* This is used to resume the task.
|
|
97
|
+
* @returns Promise<TaskResponse>
|
|
98
|
+
* @throws Error
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* task.resume().then(()=>{}).catch(()=>{})
|
|
102
|
+
* ```
|
|
103
|
+
* */
|
|
104
|
+
public async resume(): Promise<TaskResponse> {
|
|
105
|
+
return this.holdResume();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* This is used to hold or resume the task.
|
|
110
|
+
* @param isHeld: boolean - true to hold the task, false to resume it
|
|
111
|
+
* @returns Promise<TaskResponse>
|
|
112
|
+
* @throws Error
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* task.holdResume(isHeld: true).then(()=>{}).catch(()=>{})
|
|
116
|
+
* ```
|
|
117
|
+
* */
|
|
118
|
+
public async holdResume(): Promise<TaskResponse> {
|
|
119
|
+
/*
|
|
120
|
+
Determine if the task is being held or resumed based on the media resource state
|
|
121
|
+
If the media resource is not found, default to resuming the task
|
|
122
|
+
*/
|
|
123
|
+
const snapshot = this.getStateMachineSnapshot();
|
|
124
|
+
const snapshotState = snapshot?.value as TaskState | undefined;
|
|
125
|
+
const mainInteractionId = this.data.interaction?.mainInteractionId || this.data.interactionId;
|
|
126
|
+
const mainMediaResource =
|
|
127
|
+
this.data.interaction?.media?.[mainInteractionId]?.mediaResourceId ||
|
|
128
|
+
this.data.mediaResourceId;
|
|
129
|
+
const mediaHoldState =
|
|
130
|
+
this.data.interaction?.media?.[mainInteractionId]?.isHold ??
|
|
131
|
+
this.data.interaction.media?.[mainMediaResource]?.isHold;
|
|
132
|
+
let shouldHold = !(mediaHoldState ?? false);
|
|
133
|
+
if (snapshotState === TaskState.HELD) {
|
|
134
|
+
shouldHold = false;
|
|
135
|
+
} else if (snapshotState === TaskState.CONNECTED) {
|
|
136
|
+
shouldHold = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Validate operation is allowed in current state
|
|
140
|
+
const state = snapshot;
|
|
141
|
+
if (state) {
|
|
142
|
+
const currentState = state.value as TaskState;
|
|
143
|
+
if (shouldHold) {
|
|
144
|
+
if (!state.matches(TaskState.CONNECTED)) {
|
|
145
|
+
const error = new Error(`Cannot hold call in current state: ${currentState}`);
|
|
146
|
+
LoggerProxy.error('Hold operation not allowed', {
|
|
147
|
+
module: CC_FILE,
|
|
148
|
+
method: METHODS.HOLD_RESUME,
|
|
149
|
+
interactionId: this.data.interactionId,
|
|
150
|
+
});
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
} else if (!state.matches(TaskState.HELD)) {
|
|
154
|
+
const error = new Error(`Cannot resume call in current state: ${currentState}`);
|
|
155
|
+
LoggerProxy.error('Resume operation not allowed', {
|
|
156
|
+
module: CC_FILE,
|
|
157
|
+
method: METHODS.HOLD_RESUME,
|
|
158
|
+
interactionId: this.data.interactionId,
|
|
159
|
+
});
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Send initiating event to transition to intermediate state
|
|
165
|
+
if (this.stateMachineService) {
|
|
166
|
+
const initiatingEvent = shouldHold ? TaskEvent.HOLD_INITIATED : TaskEvent.UNHOLD_INITIATED;
|
|
167
|
+
this.stateMachineService.send({
|
|
168
|
+
type: initiatingEvent,
|
|
169
|
+
mediaResourceId: mainMediaResource,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
LoggerProxy.info(`${shouldHold ? 'Holding' : 'Resuming'} task`, {
|
|
174
|
+
module: CC_FILE,
|
|
175
|
+
method: METHODS.HOLD_RESUME,
|
|
176
|
+
interactionId: this.data.interactionId,
|
|
177
|
+
});
|
|
178
|
+
const [successEvt, failedEvt] = shouldHold
|
|
179
|
+
? [METRIC_EVENT_NAMES.TASK_HOLD_SUCCESS, METRIC_EVENT_NAMES.TASK_HOLD_FAILED]
|
|
180
|
+
: [METRIC_EVENT_NAMES.TASK_RESUME_SUCCESS, METRIC_EVENT_NAMES.TASK_RESUME_FAILED];
|
|
181
|
+
|
|
182
|
+
this.metricsManager.timeEvent([successEvt, failedEvt]);
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
let response: TaskResponse;
|
|
186
|
+
if (shouldHold) {
|
|
187
|
+
response = await this.contact.hold({
|
|
188
|
+
interactionId: this.data.interactionId,
|
|
189
|
+
data: {mediaResourceId: mainMediaResource},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Send success event to complete the transition
|
|
193
|
+
if (this.stateMachineService) {
|
|
194
|
+
this.stateMachineService.send({
|
|
195
|
+
type: TaskEvent.HOLD_SUCCESS,
|
|
196
|
+
mediaResourceId: mainMediaResource,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.metricsManager.trackEvent(
|
|
201
|
+
successEvt,
|
|
202
|
+
{
|
|
203
|
+
taskId: this.data.interactionId,
|
|
204
|
+
mediaResourceId: mainMediaResource,
|
|
205
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
206
|
+
},
|
|
207
|
+
['operational', 'behavioral']
|
|
208
|
+
);
|
|
209
|
+
LoggerProxy.log(`Task placed on hold successfully`, {
|
|
210
|
+
module: CC_FILE,
|
|
211
|
+
method: METHODS.HOLD_RESUME,
|
|
212
|
+
trackingId: response.trackingId,
|
|
213
|
+
interactionId: this.data.interactionId,
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
response = await this.contact.unHold({
|
|
217
|
+
interactionId: this.data.interactionId,
|
|
218
|
+
data: {mediaResourceId: mainMediaResource},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Send success event to complete the transition
|
|
222
|
+
if (this.stateMachineService) {
|
|
223
|
+
this.stateMachineService.send({
|
|
224
|
+
type: TaskEvent.UNHOLD_SUCCESS,
|
|
225
|
+
mediaResourceId: mainMediaResource,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
this.metricsManager.trackEvent(
|
|
230
|
+
successEvt,
|
|
231
|
+
{
|
|
232
|
+
taskId: this.data.interactionId,
|
|
233
|
+
mainInteractionId,
|
|
234
|
+
mediaResourceId: mainMediaResource,
|
|
235
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
236
|
+
},
|
|
237
|
+
['operational', 'behavioral']
|
|
238
|
+
);
|
|
239
|
+
LoggerProxy.log(`Task resumed successfully`, {
|
|
240
|
+
module: CC_FILE,
|
|
241
|
+
method: METHODS.HOLD_RESUME,
|
|
242
|
+
trackingId: response.trackingId,
|
|
243
|
+
interactionId: this.data.interactionId,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return response;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
const failureEvent = shouldHold ? TaskEvent.HOLD_FAILED : TaskEvent.UNHOLD_FAILED;
|
|
250
|
+
this.stateMachineService.send({
|
|
251
|
+
type: failureEvent,
|
|
252
|
+
reason: error.toString(),
|
|
253
|
+
mediaResourceId: this.data.mediaResourceId,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const {error: detailedError} = getErrorDetails(error, 'holdResume', CC_FILE);
|
|
257
|
+
this.metricsManager.trackEvent(
|
|
258
|
+
failedEvt,
|
|
259
|
+
shouldHold
|
|
260
|
+
? {
|
|
261
|
+
taskId: this.data.interactionId,
|
|
262
|
+
mediaResourceId: this.data.mediaResourceId,
|
|
263
|
+
error: error.toString(),
|
|
264
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
265
|
+
}
|
|
266
|
+
: {
|
|
267
|
+
taskId: this.data.interactionId,
|
|
268
|
+
error: error.toString(),
|
|
269
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
270
|
+
},
|
|
271
|
+
['operational', 'behavioral']
|
|
272
|
+
);
|
|
273
|
+
throw detailedError;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* This is used to pause the call recording
|
|
279
|
+
* @returns Promise<TaskResponse>
|
|
280
|
+
* @throws Error
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* task.pauseRecording().then(()=>{}).catch(()=>{});
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
public async pauseRecording(): Promise<TaskResponse> {
|
|
287
|
+
// Validate recording is active
|
|
288
|
+
const state = this.getStateMachineSnapshot();
|
|
289
|
+
if (state) {
|
|
290
|
+
const {recordingControlsAvailable, recordingInProgress} = state.context as {
|
|
291
|
+
recordingControlsAvailable?: boolean;
|
|
292
|
+
recordingInProgress?: boolean;
|
|
293
|
+
};
|
|
294
|
+
const recordingActive = Boolean(recordingControlsAvailable && recordingInProgress);
|
|
295
|
+
if (!recordingActive) {
|
|
296
|
+
const error = new Error('Recording is not active or already paused');
|
|
297
|
+
LoggerProxy.error('Pause recording operation not allowed', {
|
|
298
|
+
module: CC_FILE,
|
|
299
|
+
method: 'pauseRecording',
|
|
300
|
+
interactionId: this.data.interactionId,
|
|
301
|
+
});
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
LoggerProxy.info(`Pausing recording`, {
|
|
308
|
+
module: CC_FILE,
|
|
309
|
+
method: 'pauseRecording',
|
|
310
|
+
interactionId: this.data.interactionId,
|
|
311
|
+
});
|
|
312
|
+
this.metricsManager.timeEvent([
|
|
313
|
+
METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS,
|
|
314
|
+
METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED,
|
|
315
|
+
]);
|
|
316
|
+
const result = await this.contact.pauseRecording({interactionId: this.data.interactionId});
|
|
317
|
+
this.metricsManager.trackEvent(
|
|
318
|
+
METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_SUCCESS,
|
|
319
|
+
{
|
|
320
|
+
taskId: this.data.interactionId,
|
|
321
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(result),
|
|
322
|
+
},
|
|
323
|
+
['operational', 'behavioral', 'business']
|
|
324
|
+
);
|
|
325
|
+
LoggerProxy.log(`Recording paused successfully`, {
|
|
326
|
+
module: CC_FILE,
|
|
327
|
+
method: 'pauseRecording',
|
|
328
|
+
trackingId: result.trackingId,
|
|
329
|
+
interactionId: this.data.interactionId,
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
return result;
|
|
333
|
+
} catch (error) {
|
|
334
|
+
const {error: detailedError} = getErrorDetails(error, 'pauseRecording', CC_FILE);
|
|
335
|
+
this.metricsManager.trackEvent(
|
|
336
|
+
METRIC_EVENT_NAMES.TASK_PAUSE_RECORDING_FAILED,
|
|
337
|
+
{
|
|
338
|
+
taskId: this.data.interactionId,
|
|
339
|
+
error: error.toString(),
|
|
340
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
341
|
+
},
|
|
342
|
+
['operational', 'behavioral', 'business']
|
|
343
|
+
);
|
|
344
|
+
throw detailedError;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* This is used to pause the call recording
|
|
350
|
+
* @param resumeRecordingPayload
|
|
351
|
+
* @returns Promise<TaskResponse>
|
|
352
|
+
* @throws Error
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* task.resumeRecording(resumeRecordingPayload).then(()=>{}).catch(()=>{});
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
public async resumeRecording(
|
|
359
|
+
resumeRecordingPayload?: ResumeRecordingPayload
|
|
360
|
+
): Promise<TaskResponse> {
|
|
361
|
+
// Validate recording is paused
|
|
362
|
+
const state = this.getStateMachineSnapshot();
|
|
363
|
+
if (state) {
|
|
364
|
+
const {recordingControlsAvailable, recordingInProgress} = state.context as {
|
|
365
|
+
recordingControlsAvailable?: boolean;
|
|
366
|
+
recordingInProgress?: boolean;
|
|
367
|
+
};
|
|
368
|
+
const recordingPaused = Boolean(recordingControlsAvailable && !recordingInProgress);
|
|
369
|
+
if (!recordingPaused) {
|
|
370
|
+
const error = new Error('Recording is not paused');
|
|
371
|
+
LoggerProxy.error('Resume recording operation not allowed', {
|
|
372
|
+
module: CC_FILE,
|
|
373
|
+
method: 'resumeRecording',
|
|
374
|
+
interactionId: this.data.interactionId,
|
|
375
|
+
});
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
LoggerProxy.info(`Resuming recording`, {
|
|
382
|
+
module: CC_FILE,
|
|
383
|
+
method: 'resumeRecording',
|
|
384
|
+
interactionId: this.data.interactionId,
|
|
385
|
+
});
|
|
386
|
+
this.metricsManager.timeEvent([
|
|
387
|
+
METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS,
|
|
388
|
+
METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED,
|
|
389
|
+
]);
|
|
390
|
+
resumeRecordingPayload ??= {autoResumed: false};
|
|
391
|
+
|
|
392
|
+
const result = await this.contact.resumeRecording({
|
|
393
|
+
interactionId: this.data.interactionId,
|
|
394
|
+
data: resumeRecordingPayload,
|
|
395
|
+
});
|
|
396
|
+
this.metricsManager.trackEvent(
|
|
397
|
+
METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_SUCCESS,
|
|
398
|
+
{
|
|
399
|
+
taskId: this.data.interactionId,
|
|
400
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(result),
|
|
401
|
+
},
|
|
402
|
+
['operational', 'behavioral', 'business']
|
|
403
|
+
);
|
|
404
|
+
LoggerProxy.log(`Recording resumed successfully`, {
|
|
405
|
+
module: CC_FILE,
|
|
406
|
+
method: 'resumeRecording',
|
|
407
|
+
trackingId: result.trackingId,
|
|
408
|
+
interactionId: this.data.interactionId,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
return result;
|
|
412
|
+
} catch (error) {
|
|
413
|
+
const {error: detailedError} = getErrorDetails(error, 'resumeRecording', CC_FILE);
|
|
414
|
+
this.metricsManager.trackEvent(
|
|
415
|
+
METRIC_EVENT_NAMES.TASK_RESUME_RECORDING_FAILED,
|
|
416
|
+
{
|
|
417
|
+
taskId: this.data.interactionId,
|
|
418
|
+
error: error.toString(),
|
|
419
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
420
|
+
},
|
|
421
|
+
['operational', 'behavioral', 'business']
|
|
422
|
+
);
|
|
423
|
+
throw detailedError;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* This is used to consult the task
|
|
429
|
+
* @param consultPayload
|
|
430
|
+
* @returns Promise<TaskResponse>
|
|
431
|
+
* @throws Error
|
|
432
|
+
* @example
|
|
433
|
+
* ```typescript
|
|
434
|
+
* const consultPayload = {
|
|
435
|
+
* destination: 'myBuddyAgentId',
|
|
436
|
+
* destinationType: DESTINATION_TYPE.AGENT,
|
|
437
|
+
* }
|
|
438
|
+
* task.consult(consultPayload).then(()=>{}).catch(()=>{});
|
|
439
|
+
* ```
|
|
440
|
+
* */
|
|
441
|
+
public async consult(consultPayload?: ConsultPayload): Promise<TaskResponse> {
|
|
442
|
+
// Validate consult is allowed
|
|
443
|
+
const state = this.getStateMachineSnapshot();
|
|
444
|
+
const canConsult =
|
|
445
|
+
state &&
|
|
446
|
+
(state.matches(TaskState.CONNECTED) ||
|
|
447
|
+
state.matches(TaskState.HELD) ||
|
|
448
|
+
state.matches(TaskState.CONFERENCING));
|
|
449
|
+
|
|
450
|
+
if (!canConsult) {
|
|
451
|
+
const currentState = state?.value as TaskState;
|
|
452
|
+
const error = new Error(`Cannot initiate consult in ${currentState} state`);
|
|
453
|
+
LoggerProxy.error('Consult operation not allowed', {
|
|
454
|
+
module: CC_FILE,
|
|
455
|
+
method: 'consult',
|
|
456
|
+
interactionId: this.data.interactionId,
|
|
457
|
+
});
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Send initiating event to transition to CONSULT_INITIATING state
|
|
462
|
+
if (this.stateMachineService) {
|
|
463
|
+
this.stateMachineService.send({
|
|
464
|
+
type: TaskEvent.CONSULT,
|
|
465
|
+
destination: consultPayload.to,
|
|
466
|
+
destinationType: consultPayload.destinationType,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const requestInteractionId =
|
|
471
|
+
this.data.interaction?.mainInteractionId || this.data.interactionId;
|
|
472
|
+
|
|
473
|
+
try {
|
|
474
|
+
LoggerProxy.info(`Starting consult`, {
|
|
475
|
+
module: CC_FILE,
|
|
476
|
+
method: 'consult',
|
|
477
|
+
interactionId: requestInteractionId,
|
|
478
|
+
});
|
|
479
|
+
this.metricsManager.timeEvent([
|
|
480
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS,
|
|
481
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED,
|
|
482
|
+
]);
|
|
483
|
+
const result = await this.contact.consult({
|
|
484
|
+
interactionId: requestInteractionId,
|
|
485
|
+
data: consultPayload,
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// Send success event to transition to CONSULTING state
|
|
489
|
+
if (this.stateMachineService) {
|
|
490
|
+
this.stateMachineService.send({
|
|
491
|
+
type: TaskEvent.CONSULT_SUCCESS,
|
|
492
|
+
taskData: result.data,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
this.metricsManager.trackEvent(
|
|
497
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_START_SUCCESS,
|
|
498
|
+
{
|
|
499
|
+
taskId: this.data.interactionId,
|
|
500
|
+
requestInteractionId,
|
|
501
|
+
destination: consultPayload.to,
|
|
502
|
+
destinationType: consultPayload.destinationType,
|
|
503
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(result),
|
|
504
|
+
},
|
|
505
|
+
['operational', 'behavioral', 'business']
|
|
506
|
+
);
|
|
507
|
+
LoggerProxy.log(`Consult successfully initiated to ${consultPayload.to}`, {
|
|
508
|
+
module: CC_FILE,
|
|
509
|
+
method: 'consult',
|
|
510
|
+
trackingId: result.trackingId,
|
|
511
|
+
interactionId: requestInteractionId,
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
return result;
|
|
515
|
+
} catch (error) {
|
|
516
|
+
this.stateMachineService.send({
|
|
517
|
+
type: TaskEvent.CONSULT_FAILED,
|
|
518
|
+
reason: error.toString(),
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const {error: detailedError} = getErrorDetails(error, 'consult', CC_FILE);
|
|
522
|
+
this.metricsManager.trackEvent(
|
|
523
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_START_FAILED,
|
|
524
|
+
{
|
|
525
|
+
taskId: this.data.interactionId,
|
|
526
|
+
requestInteractionId,
|
|
527
|
+
destination: consultPayload.to,
|
|
528
|
+
destinationType: consultPayload.destinationType,
|
|
529
|
+
error: error.toString(),
|
|
530
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
531
|
+
},
|
|
532
|
+
['operational', 'behavioral', 'business']
|
|
533
|
+
);
|
|
534
|
+
throw detailedError;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* This is used to end the consult session on the task.
|
|
540
|
+
* @param consultEndPayload - Payload indicating consult end flags and identifiers
|
|
541
|
+
* @returns Promise<TaskResponse>
|
|
542
|
+
* @throws Error
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* task.endConsult({
|
|
546
|
+
* isConsult: true,
|
|
547
|
+
* queueId: 'myQueueId',
|
|
548
|
+
* taskId: 'taskId',
|
|
549
|
+
* });
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
public async endConsult(consultEndPayload?: ConsultEndPayload): Promise<TaskResponse> {
|
|
553
|
+
const requestInteractionId =
|
|
554
|
+
this.data.interaction?.mainInteractionId || this.data.interactionId;
|
|
555
|
+
|
|
556
|
+
try {
|
|
557
|
+
LoggerProxy.info(`Ending consult`, {
|
|
558
|
+
module: CC_FILE,
|
|
559
|
+
method: 'endConsult',
|
|
560
|
+
interactionId: requestInteractionId,
|
|
561
|
+
});
|
|
562
|
+
this.metricsManager.timeEvent([
|
|
563
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS,
|
|
564
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED,
|
|
565
|
+
]);
|
|
566
|
+
const result = await this.contact.consultEnd({
|
|
567
|
+
interactionId: requestInteractionId,
|
|
568
|
+
data: consultEndPayload,
|
|
569
|
+
});
|
|
570
|
+
this.metricsManager.trackEvent(
|
|
571
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_END_SUCCESS,
|
|
572
|
+
{
|
|
573
|
+
taskId: this.data.interactionId,
|
|
574
|
+
requestInteractionId,
|
|
575
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(result),
|
|
576
|
+
},
|
|
577
|
+
['operational', 'behavioral', 'business']
|
|
578
|
+
);
|
|
579
|
+
LoggerProxy.log(`Consult ended successfully`, {
|
|
580
|
+
module: CC_FILE,
|
|
581
|
+
method: 'endConsult',
|
|
582
|
+
trackingId: result.trackingId,
|
|
583
|
+
interactionId: this.data.interactionId,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
return result;
|
|
587
|
+
} catch (error) {
|
|
588
|
+
const {error: detailedError} = getErrorDetails(error, 'endConsult', CC_FILE);
|
|
589
|
+
this.metricsManager.trackEvent(
|
|
590
|
+
METRIC_EVENT_NAMES.TASK_CONSULT_END_FAILED,
|
|
591
|
+
{
|
|
592
|
+
taskId: this.data.interactionId,
|
|
593
|
+
requestInteractionId,
|
|
594
|
+
error: error.toString(),
|
|
595
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
596
|
+
},
|
|
597
|
+
['operational', 'behavioral', 'business']
|
|
598
|
+
);
|
|
599
|
+
throw detailedError;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* This is used to transfer the task.
|
|
605
|
+
* @param payload - Transfer payload
|
|
606
|
+
* @returns Promise<TaskResponse>
|
|
607
|
+
* @throws Error
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* task.transfer({
|
|
611
|
+
* to: 'destinationId',
|
|
612
|
+
* destinationType: DESTINATION_TYPE.AGENT,
|
|
613
|
+
* consult: true, // Optional, if true will perform a consult transfer else blind transfer
|
|
614
|
+
* });
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
public async transfer(payload: TransferPayLoad): Promise<TaskResponse> {
|
|
618
|
+
try {
|
|
619
|
+
LoggerProxy.info(`Transferring task to ${payload.to}`, {
|
|
620
|
+
module: CC_FILE,
|
|
621
|
+
method: METHODS.TRANSFER_CALL,
|
|
622
|
+
interactionId: this.data.interactionId,
|
|
623
|
+
});
|
|
624
|
+
this.metricsManager.timeEvent([
|
|
625
|
+
METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS,
|
|
626
|
+
METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED,
|
|
627
|
+
]);
|
|
628
|
+
|
|
629
|
+
// consult transfer path
|
|
630
|
+
if (this.data.interaction.state === 'consulting') {
|
|
631
|
+
const normalizedDestinationType =
|
|
632
|
+
payload.destinationType === 'Agent' || payload.destinationType === 'Queue'
|
|
633
|
+
? (payload.destinationType.toLowerCase() as ConsultTransferPayLoad['destinationType'])
|
|
634
|
+
: payload.destinationType;
|
|
635
|
+
let consultPayload: ConsultTransferPayLoad = {
|
|
636
|
+
to: payload.to,
|
|
637
|
+
destinationType: normalizedDestinationType,
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
if (normalizedDestinationType === CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE) {
|
|
641
|
+
const consultContext = this.getStateMachineSnapshot()?.context;
|
|
642
|
+
const destAgent = consultContext?.consultDestinationAgentId || this.data.destAgentId;
|
|
643
|
+
if (!destAgent) {
|
|
644
|
+
throw new Error('No agent has accepted this queue consult yet');
|
|
645
|
+
}
|
|
646
|
+
consultPayload = {
|
|
647
|
+
to: destAgent,
|
|
648
|
+
destinationType: CONSULT_TRANSFER_DESTINATION_TYPE.AGENT,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const result = await this.contact.consultTransfer({
|
|
653
|
+
interactionId: this.data.interactionId,
|
|
654
|
+
data: consultPayload,
|
|
655
|
+
});
|
|
656
|
+
this.metricsManager.trackEvent(
|
|
657
|
+
METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS,
|
|
658
|
+
{
|
|
659
|
+
taskId: this.data.interactionId,
|
|
660
|
+
destination: consultPayload.to,
|
|
661
|
+
destinationType: consultPayload.destinationType,
|
|
662
|
+
isConsultTransfer: true,
|
|
663
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(result),
|
|
664
|
+
},
|
|
665
|
+
['operational', 'behavioral', 'business']
|
|
666
|
+
);
|
|
667
|
+
LoggerProxy.log(`Consult transfer completed successfully to ${consultPayload.to}`, {
|
|
668
|
+
module: CC_FILE,
|
|
669
|
+
method: METHODS.TRANSFER_CALL,
|
|
670
|
+
trackingId: result.trackingId,
|
|
671
|
+
interactionId: this.data.interactionId,
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
return result;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// standard blind transfer
|
|
678
|
+
return await super.transfer({
|
|
679
|
+
to: payload.to,
|
|
680
|
+
destinationType: payload.destinationType,
|
|
681
|
+
});
|
|
682
|
+
} catch (err) {
|
|
683
|
+
const {error: detailedError} = getErrorDetails(err, METHODS.TRANSFER_CALL, CC_FILE);
|
|
684
|
+
this.metricsManager.trackEvent(
|
|
685
|
+
METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED,
|
|
686
|
+
{
|
|
687
|
+
taskId: this.data.interactionId,
|
|
688
|
+
destination: payload.to,
|
|
689
|
+
destinationType: payload.destinationType,
|
|
690
|
+
isConsultTransfer: this.data.interaction.state === 'consulting',
|
|
691
|
+
error: err.toString(),
|
|
692
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(err.details || {}),
|
|
693
|
+
},
|
|
694
|
+
['operational', 'behavioral', 'business']
|
|
695
|
+
);
|
|
696
|
+
throw detailedError;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Start a consult conference, merging main and consult calls.
|
|
702
|
+
*/
|
|
703
|
+
public async consultConference(): Promise<TaskResponse> {
|
|
704
|
+
const derivedDestAgentId =
|
|
705
|
+
this.data.interaction && this.data.agentId
|
|
706
|
+
? calculateDestAgentId(this.data.interaction, this.data.agentId)
|
|
707
|
+
: '';
|
|
708
|
+
const derivedDestType =
|
|
709
|
+
this.data.interaction && this.data.agentId
|
|
710
|
+
? calculateDestType(this.data.interaction, this.data.agentId)
|
|
711
|
+
: '';
|
|
712
|
+
|
|
713
|
+
const consultationData: consultConferencePayloadData = {
|
|
714
|
+
agentId: this.data.agentId,
|
|
715
|
+
destinationType:
|
|
716
|
+
this.getStateMachineSnapshot()?.context?.consultDestinationType ||
|
|
717
|
+
this.data.destinationType ||
|
|
718
|
+
derivedDestType ||
|
|
719
|
+
'agent',
|
|
720
|
+
destAgentId:
|
|
721
|
+
this.getStateMachineSnapshot()?.context?.consultDestinationAgentId ||
|
|
722
|
+
this.data.destAgentId ||
|
|
723
|
+
derivedDestAgentId,
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// Send state machine event to transition to CONF_INITIATING
|
|
727
|
+
if (this.stateMachineService) {
|
|
728
|
+
this.stateMachineService.send({
|
|
729
|
+
type: TaskEvent.MERGE_TO_CONFERENCE,
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
try {
|
|
734
|
+
if (!consultationData.destAgentId) {
|
|
735
|
+
throw new Error('Unable to determine consult destination for conference');
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
LoggerProxy.info(`Initiating consult conference to ${consultationData.destAgentId}`, {
|
|
739
|
+
module: CC_FILE,
|
|
740
|
+
method: METHODS.CONSULT_CONFERENCE,
|
|
741
|
+
interactionId: this.data.interactionId,
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
const paramsDataForConferenceV2 = buildConsultConferenceParamData(
|
|
745
|
+
consultationData,
|
|
746
|
+
this.data.interactionId
|
|
747
|
+
);
|
|
748
|
+
|
|
749
|
+
const response = await this.contact.consultConference({
|
|
750
|
+
interactionId: paramsDataForConferenceV2.interactionId,
|
|
751
|
+
data: paramsDataForConferenceV2.data,
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
// Send success event to transition to CONFERENCING
|
|
755
|
+
if (this.stateMachineService) {
|
|
756
|
+
this.stateMachineService.send({
|
|
757
|
+
type: TaskEvent.CONFERENCE_START,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
this.metricsManager.trackEvent(
|
|
762
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_START_SUCCESS,
|
|
763
|
+
{
|
|
764
|
+
taskId: this.data.interactionId,
|
|
765
|
+
destination: paramsDataForConferenceV2.data.to,
|
|
766
|
+
destinationType: paramsDataForConferenceV2.data.destinationType,
|
|
767
|
+
agentId: paramsDataForConferenceV2.data.agentId,
|
|
768
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
769
|
+
},
|
|
770
|
+
['operational', 'behavioral', 'business']
|
|
771
|
+
);
|
|
772
|
+
|
|
773
|
+
LoggerProxy.log(`Consult conference started successfully`, {
|
|
774
|
+
module: CC_FILE,
|
|
775
|
+
method: METHODS.CONSULT_CONFERENCE,
|
|
776
|
+
interactionId: this.data.interactionId,
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
return response;
|
|
780
|
+
} catch (error) {
|
|
781
|
+
// Send failure event to revert state
|
|
782
|
+
if (this.stateMachineService) {
|
|
783
|
+
this.stateMachineService.send({
|
|
784
|
+
type: TaskEvent.CONFERENCE_FAILED,
|
|
785
|
+
reason: error.toString(),
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const {error: detailedError} = getErrorDetails(error, METHODS.CONSULT_CONFERENCE, CC_FILE);
|
|
790
|
+
|
|
791
|
+
const failedParamsData = buildConsultConferenceParamData(
|
|
792
|
+
consultationData,
|
|
793
|
+
this.data.interactionId
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
this.metricsManager.trackEvent(
|
|
797
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_START_FAILED,
|
|
798
|
+
{
|
|
799
|
+
taskId: this.data.interactionId,
|
|
800
|
+
destination: failedParamsData.data.to,
|
|
801
|
+
destinationType: failedParamsData.data.destinationType,
|
|
802
|
+
agentId: failedParamsData.data.agentId,
|
|
803
|
+
error: error.toString(),
|
|
804
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
805
|
+
},
|
|
806
|
+
['operational', 'behavioral', 'business']
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
LoggerProxy.error(`Failed to start consult conference`, {
|
|
810
|
+
module: CC_FILE,
|
|
811
|
+
method: METHODS.CONSULT_CONFERENCE,
|
|
812
|
+
interactionId: this.data.interactionId,
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
throw detailedError;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Exit from a conference call.
|
|
821
|
+
* Per conference-spec.md:
|
|
822
|
+
* - Primary agent exits to wrapup
|
|
823
|
+
* - Non-primary agent exits to available/connected
|
|
824
|
+
* - Other participants continue the call
|
|
825
|
+
*
|
|
826
|
+
* @returns Promise<TaskResponse>
|
|
827
|
+
* @throws Error if not in conference or exit fails
|
|
828
|
+
* @example
|
|
829
|
+
* ```typescript
|
|
830
|
+
* task.exitConference().then(() => {}).catch(() => {});
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
public async exitConference(): Promise<TaskResponse> {
|
|
834
|
+
// Validate we're in conference state OR conference is in progress per task data
|
|
835
|
+
// This handles cases where:
|
|
836
|
+
// 1. State machine is in CONFERENCING state
|
|
837
|
+
// 2. State machine is in CONNECTED but conference is active (e.g., ownership transferred)
|
|
838
|
+
const state = this.getStateMachineSnapshot();
|
|
839
|
+
const isConferencingState = state?.matches(TaskState.CONFERENCING);
|
|
840
|
+
|
|
841
|
+
const isConferenceInProgressFromData = this.data ? getIsConferenceInProgress(this.data) : false;
|
|
842
|
+
|
|
843
|
+
if (!state || (!isConferencingState && !isConferenceInProgressFromData)) {
|
|
844
|
+
const currentState = state?.value as TaskState;
|
|
845
|
+
const error = new Error(`Cannot exit conference in ${currentState} state`);
|
|
846
|
+
LoggerProxy.error('Exit conference operation not allowed', {
|
|
847
|
+
module: CC_FILE,
|
|
848
|
+
method: 'exitConference',
|
|
849
|
+
interactionId: this.data.interactionId,
|
|
850
|
+
});
|
|
851
|
+
throw error;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// Send state machine event
|
|
855
|
+
if (this.stateMachineService) {
|
|
856
|
+
this.stateMachineService.send({
|
|
857
|
+
type: TaskEvent.EXIT_CONFERENCE,
|
|
858
|
+
agentId: this.data.agentId,
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
const requestInteractionId =
|
|
863
|
+
this.data.interaction?.mainInteractionId || this.data.interactionId;
|
|
864
|
+
|
|
865
|
+
try {
|
|
866
|
+
LoggerProxy.info(`Exiting conference`, {
|
|
867
|
+
module: CC_FILE,
|
|
868
|
+
method: 'exitConference',
|
|
869
|
+
interactionId: requestInteractionId,
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
this.metricsManager.timeEvent([
|
|
873
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_SUCCESS,
|
|
874
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_FAILED,
|
|
875
|
+
]);
|
|
876
|
+
|
|
877
|
+
const response = await this.contact.exitConference({
|
|
878
|
+
interactionId: requestInteractionId,
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
// Send success event to transition state
|
|
882
|
+
if (this.stateMachineService) {
|
|
883
|
+
this.stateMachineService.send({
|
|
884
|
+
type: TaskEvent.EXIT_CONFERENCE_SUCCESS,
|
|
885
|
+
taskData: response.data,
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
this.metricsManager.trackEvent(
|
|
890
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_SUCCESS,
|
|
891
|
+
{
|
|
892
|
+
taskId: this.data.interactionId,
|
|
893
|
+
requestInteractionId,
|
|
894
|
+
agentId: this.data.agentId,
|
|
895
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
896
|
+
},
|
|
897
|
+
['operational', 'behavioral', 'business']
|
|
898
|
+
);
|
|
899
|
+
|
|
900
|
+
LoggerProxy.log(`Successfully exited conference`, {
|
|
901
|
+
module: CC_FILE,
|
|
902
|
+
method: 'exitConference',
|
|
903
|
+
trackingId: response.trackingId,
|
|
904
|
+
interactionId: requestInteractionId,
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
return response;
|
|
908
|
+
} catch (error) {
|
|
909
|
+
// Send failure event
|
|
910
|
+
if (this.stateMachineService) {
|
|
911
|
+
this.stateMachineService.send({
|
|
912
|
+
type: TaskEvent.EXIT_CONFERENCE_FAILED,
|
|
913
|
+
reason: error.toString(),
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const {error: detailedError} = getErrorDetails(error, 'exitConference', CC_FILE);
|
|
918
|
+
this.metricsManager.trackEvent(
|
|
919
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_EXIT_FAILED,
|
|
920
|
+
{
|
|
921
|
+
taskId: this.data.interactionId,
|
|
922
|
+
requestInteractionId,
|
|
923
|
+
agentId: this.data.agentId,
|
|
924
|
+
error: error.toString(),
|
|
925
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
926
|
+
},
|
|
927
|
+
['operational', 'behavioral', 'business']
|
|
928
|
+
);
|
|
929
|
+
|
|
930
|
+
LoggerProxy.error(`Failed to exit conference`, {
|
|
931
|
+
module: CC_FILE,
|
|
932
|
+
method: 'exitConference',
|
|
933
|
+
interactionId: requestInteractionId,
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
throw detailedError;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* Transfer the conference to another participant.
|
|
942
|
+
* Per conference-spec.md: Only primary agent can transfer conference.
|
|
943
|
+
* After transfer, the transferring agent exits to wrapup.
|
|
944
|
+
*
|
|
945
|
+
* @returns Promise<TaskResponse>
|
|
946
|
+
* @throws Error if not in conference or transfer fails
|
|
947
|
+
* @example
|
|
948
|
+
* ```typescript
|
|
949
|
+
* task.transferConference().then(() => {}).catch(() => {});
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
public async transferConference(): Promise<TaskResponse> {
|
|
953
|
+
// Validate we're in conference or consulting state
|
|
954
|
+
// CONSULTING is allowed because agent can transfer conference while consulting
|
|
955
|
+
// (transfers ownership to the consulted agent)
|
|
956
|
+
const state = this.getStateMachineSnapshot();
|
|
957
|
+
const isValidState =
|
|
958
|
+
state && (state.matches(TaskState.CONFERENCING) || state.matches(TaskState.CONSULTING));
|
|
959
|
+
if (!isValidState) {
|
|
960
|
+
const currentState = state?.value as TaskState;
|
|
961
|
+
const error = new Error(`Cannot transfer conference in ${currentState} state`);
|
|
962
|
+
LoggerProxy.error('Transfer conference operation not allowed', {
|
|
963
|
+
module: CC_FILE,
|
|
964
|
+
method: 'transferConference',
|
|
965
|
+
interactionId: this.data.interactionId,
|
|
966
|
+
});
|
|
967
|
+
throw error;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// Send state machine event
|
|
971
|
+
if (this.stateMachineService) {
|
|
972
|
+
this.stateMachineService.send({
|
|
973
|
+
type: TaskEvent.TRANSFER_CONFERENCE,
|
|
974
|
+
agentId: this.data.agentId,
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
const requestInteractionId =
|
|
979
|
+
this.data.interaction?.mainInteractionId || this.data.interactionId;
|
|
980
|
+
|
|
981
|
+
try {
|
|
982
|
+
LoggerProxy.info(`Transferring conference`, {
|
|
983
|
+
module: CC_FILE,
|
|
984
|
+
method: 'transferConference',
|
|
985
|
+
interactionId: requestInteractionId,
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
this.metricsManager.timeEvent([
|
|
989
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_SUCCESS,
|
|
990
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_FAILED,
|
|
991
|
+
]);
|
|
992
|
+
|
|
993
|
+
const response = await this.contact.conferenceTransfer({
|
|
994
|
+
interactionId: requestInteractionId,
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
// Send success event to transition state
|
|
998
|
+
if (this.stateMachineService) {
|
|
999
|
+
this.stateMachineService.send({
|
|
1000
|
+
type: TaskEvent.TRANSFER_CONFERENCE_SUCCESS,
|
|
1001
|
+
taskData: response.data,
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
this.metricsManager.trackEvent(
|
|
1006
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_SUCCESS,
|
|
1007
|
+
{
|
|
1008
|
+
taskId: this.data.interactionId,
|
|
1009
|
+
requestInteractionId,
|
|
1010
|
+
agentId: this.data.agentId,
|
|
1011
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
1012
|
+
},
|
|
1013
|
+
['operational', 'behavioral', 'business']
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
LoggerProxy.log(`Successfully transferred conference`, {
|
|
1017
|
+
module: CC_FILE,
|
|
1018
|
+
method: 'transferConference',
|
|
1019
|
+
trackingId: response.trackingId,
|
|
1020
|
+
interactionId: requestInteractionId,
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
return response;
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
// Send failure event
|
|
1026
|
+
if (this.stateMachineService) {
|
|
1027
|
+
this.stateMachineService.send({
|
|
1028
|
+
type: TaskEvent.TRANSFER_CONFERENCE_FAILED,
|
|
1029
|
+
reason: error.toString(),
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
const {error: detailedError} = getErrorDetails(error, 'transferConference', CC_FILE);
|
|
1034
|
+
this.metricsManager.trackEvent(
|
|
1035
|
+
METRIC_EVENT_NAMES.TASK_CONFERENCE_TRANSFER_FAILED,
|
|
1036
|
+
{
|
|
1037
|
+
taskId: this.data.interactionId,
|
|
1038
|
+
requestInteractionId,
|
|
1039
|
+
agentId: this.data.agentId,
|
|
1040
|
+
error: error.toString(),
|
|
1041
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
1042
|
+
},
|
|
1043
|
+
['operational', 'behavioral', 'business']
|
|
1044
|
+
);
|
|
1045
|
+
|
|
1046
|
+
LoggerProxy.error(`Failed to transfer conference`, {
|
|
1047
|
+
module: CC_FILE,
|
|
1048
|
+
method: 'transferConference',
|
|
1049
|
+
interactionId: requestInteractionId,
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
throw detailedError;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Toggle between consult call and main call during consulting.
|
|
1058
|
+
* If on consult leg (consultCallHeld = false), switches to main call by holding consult.
|
|
1059
|
+
* If on main call (consultCallHeld = true), switches to consult by resuming consult.
|
|
1060
|
+
*
|
|
1061
|
+
* @returns Promise<TaskResponse>
|
|
1062
|
+
* @throws Error if not in CONSULTING state or no consult media resource
|
|
1063
|
+
* @example
|
|
1064
|
+
* ```typescript
|
|
1065
|
+
* await task.switchCall();
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
public async switchCall(): Promise<TaskResponse> {
|
|
1069
|
+
// Validate we're in CONSULTING state
|
|
1070
|
+
const state = this.getStateMachineSnapshot();
|
|
1071
|
+
if (!state?.matches(TaskState.CONSULTING)) {
|
|
1072
|
+
const currentState = state?.value as TaskState;
|
|
1073
|
+
const error = new Error(`Cannot switch call in ${currentState} state`);
|
|
1074
|
+
LoggerProxy.error('Switch call operation not allowed', {
|
|
1075
|
+
module: CC_FILE,
|
|
1076
|
+
method: 'switchCall',
|
|
1077
|
+
interactionId: this.data.interactionId,
|
|
1078
|
+
});
|
|
1079
|
+
throw error;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// Validate we have a consult media resource
|
|
1083
|
+
const consultMediaResourceId = getConsultMediaResourceId(
|
|
1084
|
+
this.data.interaction,
|
|
1085
|
+
this.data.consultMediaResourceId,
|
|
1086
|
+
this.data.agentId
|
|
1087
|
+
);
|
|
1088
|
+
if (!consultMediaResourceId) {
|
|
1089
|
+
const error = new Error('No consult media resource available');
|
|
1090
|
+
LoggerProxy.error('Switch call failed - no consult media resource', {
|
|
1091
|
+
module: CC_FILE,
|
|
1092
|
+
method: 'switchCall',
|
|
1093
|
+
interactionId: this.data.interactionId,
|
|
1094
|
+
});
|
|
1095
|
+
throw error;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
const context = state.context;
|
|
1099
|
+
const isOnConsultLeg = !context.consultCallHeld;
|
|
1100
|
+
|
|
1101
|
+
// Determine direction and send appropriate state machine event
|
|
1102
|
+
const targetEvent = isOnConsultLeg
|
|
1103
|
+
? TaskEvent.SWITCH_TO_MAIN_CALL
|
|
1104
|
+
: TaskEvent.SWITCH_TO_CONSULT;
|
|
1105
|
+
const revertEvent = isOnConsultLeg
|
|
1106
|
+
? TaskEvent.SWITCH_TO_CONSULT
|
|
1107
|
+
: TaskEvent.SWITCH_TO_MAIN_CALL;
|
|
1108
|
+
|
|
1109
|
+
if (this.stateMachineService) {
|
|
1110
|
+
this.stateMachineService.send({type: targetEvent});
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
this.metricsManager.timeEvent([
|
|
1114
|
+
METRIC_EVENT_NAMES.TASK_SWITCH_CALL_SUCCESS,
|
|
1115
|
+
METRIC_EVENT_NAMES.TASK_SWITCH_CALL_FAILED,
|
|
1116
|
+
]);
|
|
1117
|
+
|
|
1118
|
+
try {
|
|
1119
|
+
if (isOnConsultLeg) {
|
|
1120
|
+
const response = await this.contact.unHold({
|
|
1121
|
+
interactionId: this.data.interactionId,
|
|
1122
|
+
data: {mediaResourceId: this.data.mediaResourceId},
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
this.metricsManager.trackEvent(
|
|
1126
|
+
METRIC_EVENT_NAMES.TASK_SWITCH_CALL_SUCCESS,
|
|
1127
|
+
{
|
|
1128
|
+
taskId: this.data.interactionId,
|
|
1129
|
+
direction: 'toMainCall',
|
|
1130
|
+
mediaResourceId: consultMediaResourceId,
|
|
1131
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
1132
|
+
},
|
|
1133
|
+
['operational', 'behavioral']
|
|
1134
|
+
);
|
|
1135
|
+
|
|
1136
|
+
LoggerProxy.log(`Switched to main call successfully`, {
|
|
1137
|
+
module: CC_FILE,
|
|
1138
|
+
method: 'switchCall',
|
|
1139
|
+
trackingId: response.trackingId,
|
|
1140
|
+
interactionId: this.data.interactionId,
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
return response;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
const response = await this.contact.hold({
|
|
1147
|
+
interactionId: this.data.interactionId,
|
|
1148
|
+
data: {mediaResourceId: this.data.mediaResourceId},
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
this.metricsManager.trackEvent(
|
|
1152
|
+
METRIC_EVENT_NAMES.TASK_SWITCH_CALL_SUCCESS,
|
|
1153
|
+
{
|
|
1154
|
+
taskId: this.data.interactionId,
|
|
1155
|
+
direction: 'toConsultCall',
|
|
1156
|
+
mediaResourceId: consultMediaResourceId,
|
|
1157
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
|
|
1158
|
+
},
|
|
1159
|
+
['operational', 'behavioral']
|
|
1160
|
+
);
|
|
1161
|
+
|
|
1162
|
+
LoggerProxy.log(`Switched to consult call successfully`, {
|
|
1163
|
+
module: CC_FILE,
|
|
1164
|
+
method: 'switchCall',
|
|
1165
|
+
trackingId: response.trackingId,
|
|
1166
|
+
interactionId: this.data.interactionId,
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
return response;
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
if (this.stateMachineService) {
|
|
1172
|
+
this.stateMachineService.send({type: revertEvent});
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
this.metricsManager.trackEvent(
|
|
1176
|
+
METRIC_EVENT_NAMES.TASK_SWITCH_CALL_FAILED,
|
|
1177
|
+
{
|
|
1178
|
+
taskId: this.data.interactionId,
|
|
1179
|
+
direction: isOnConsultLeg ? 'toMainCall' : 'toConsultCall',
|
|
1180
|
+
mediaResourceId: consultMediaResourceId,
|
|
1181
|
+
error: error.toString(),
|
|
1182
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(error.details || {}),
|
|
1183
|
+
},
|
|
1184
|
+
['operational', 'behavioral']
|
|
1185
|
+
);
|
|
1186
|
+
|
|
1187
|
+
const {error: detailedError} = getErrorDetails(error, 'switchCall', CC_FILE);
|
|
1188
|
+
LoggerProxy.error(`Failed to switch call`, {
|
|
1189
|
+
module: CC_FILE,
|
|
1190
|
+
method: 'switchCall',
|
|
1191
|
+
interactionId: this.data.interactionId,
|
|
1192
|
+
});
|
|
1193
|
+
throw detailedError;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
protected override getChannelSpecificActionOverrides() {
|
|
1198
|
+
const baseOverrides = super.getChannelSpecificActionOverrides();
|
|
1199
|
+
|
|
1200
|
+
return {
|
|
1201
|
+
...baseOverrides,
|
|
1202
|
+
emitTaskHold: this.createEmitSelfAction(TASK_EVENTS.TASK_HOLD, {updateTaskData: true}),
|
|
1203
|
+
emitTaskResume: this.createEmitSelfAction(TASK_EVENTS.TASK_RESUME, {updateTaskData: true}),
|
|
1204
|
+
emitTaskRecordingStarted: this.createEmitSelfAction(TASK_EVENTS.TASK_RECORDING_STARTED, {
|
|
1205
|
+
updateTaskData: true,
|
|
1206
|
+
}),
|
|
1207
|
+
emitTaskRecordingPaused: this.createEmitSelfAction(TASK_EVENTS.TASK_RECORDING_PAUSED, {
|
|
1208
|
+
updateTaskData: true,
|
|
1209
|
+
}),
|
|
1210
|
+
emitTaskRecordingPauseFailed: this.createEmitSelfAction(
|
|
1211
|
+
TASK_EVENTS.TASK_RECORDING_PAUSE_FAILED,
|
|
1212
|
+
{updateTaskData: true}
|
|
1213
|
+
),
|
|
1214
|
+
emitTaskRecordingResumed: this.createEmitSelfAction(TASK_EVENTS.TASK_RECORDING_RESUMED, {
|
|
1215
|
+
updateTaskData: true,
|
|
1216
|
+
}),
|
|
1217
|
+
emitTaskRecordingResumeFailed: this.createEmitSelfAction(
|
|
1218
|
+
TASK_EVENTS.TASK_RECORDING_RESUME_FAILED,
|
|
1219
|
+
{updateTaskData: true}
|
|
1220
|
+
),
|
|
1221
|
+
// Conference event emitters
|
|
1222
|
+
emitTaskParticipantJoined: this.createEmitSelfAction(TASK_EVENTS.TASK_PARTICIPANT_JOINED, {
|
|
1223
|
+
updateTaskData: true,
|
|
1224
|
+
}),
|
|
1225
|
+
emitTaskParticipantLeft: this.createEmitSelfAction(TASK_EVENTS.TASK_PARTICIPANT_LEFT, {
|
|
1226
|
+
updateTaskData: true,
|
|
1227
|
+
}),
|
|
1228
|
+
emitTaskConferenceStarted: this.createEmitSelfAction(TASK_EVENTS.TASK_CONFERENCE_STARTED, {
|
|
1229
|
+
updateTaskData: true,
|
|
1230
|
+
}),
|
|
1231
|
+
emitTaskConferenceEnded: this.createEmitSelfAction(TASK_EVENTS.TASK_CONFERENCE_ENDED, {
|
|
1232
|
+
updateTaskData: true,
|
|
1233
|
+
}),
|
|
1234
|
+
emitTaskConferenceFailed: this.createEmitSelfAction(TASK_EVENTS.TASK_CONFERENCE_FAILED, {
|
|
1235
|
+
updateTaskData: true,
|
|
1236
|
+
}),
|
|
1237
|
+
emitTaskExitConference: this.createEmitSelfAction(TASK_EVENTS.TASK_EXIT_CONFERENCE, {
|
|
1238
|
+
updateTaskData: false,
|
|
1239
|
+
}),
|
|
1240
|
+
emitTaskTransferConference: this.createEmitSelfAction(TASK_EVENTS.TASK_TRANSFER_CONFERENCE, {
|
|
1241
|
+
updateTaskData: false,
|
|
1242
|
+
}),
|
|
1243
|
+
emitTaskSwitchCall: this.createEmitSelfAction(TASK_EVENTS.TASK_SWITCH_CALL, {
|
|
1244
|
+
updateTaskData: false,
|
|
1245
|
+
}),
|
|
1246
|
+
emitTaskTransferConferenceFailed: this.createEmitSelfAction(
|
|
1247
|
+
TASK_EVENTS.TASK_CONFERENCE_TRANSFER_FAILED,
|
|
1248
|
+
{updateTaskData: true}
|
|
1249
|
+
),
|
|
1250
|
+
emitTaskOutdialFailed: this.createEmitSelfAction(TASK_EVENTS.TASK_OUTDIAL_FAILED, {
|
|
1251
|
+
updateTaskData: true,
|
|
1252
|
+
}),
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
}
|