@webex/contact-center 3.12.0-next.9 → 3.12.0-task-refactor.2
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 +570 -535
- 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 +372 -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 +263 -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 +377 -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 +579 -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 +422 -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 +303 -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 +542 -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,473 @@
|
|
|
1
|
+
import {createActor} from 'xstate';
|
|
2
|
+
import {
|
|
3
|
+
createTaskStateMachine,
|
|
4
|
+
TaskEvent,
|
|
5
|
+
TaskState,
|
|
6
|
+
} from '../../../../../../src/services/task/state-machine';
|
|
7
|
+
import {createTaskData} from '../taskTestUtils';
|
|
8
|
+
|
|
9
|
+
const createConfig = () => ({
|
|
10
|
+
channelType: 'voice' as const,
|
|
11
|
+
isEndTaskEnabled: true,
|
|
12
|
+
isEndConsultEnabled: true,
|
|
13
|
+
voiceVariant: 'pstn' as const,
|
|
14
|
+
isRecordingEnabled: true,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('Task state machine', () => {
|
|
18
|
+
const startMachine = () => {
|
|
19
|
+
const actor = createActor(createTaskStateMachine(createConfig()));
|
|
20
|
+
actor.start();
|
|
21
|
+
return actor;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('recording state derivation', () => {
|
|
25
|
+
it('captures recording flags from offer payload', () => {
|
|
26
|
+
const service = startMachine();
|
|
27
|
+
const taskData = createTaskData({
|
|
28
|
+
interaction: {
|
|
29
|
+
callProcessingDetails: {
|
|
30
|
+
recordInProgress: true,
|
|
31
|
+
isPaused: false,
|
|
32
|
+
},
|
|
33
|
+
} as any,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
37
|
+
|
|
38
|
+
const snapshot = service.getSnapshot();
|
|
39
|
+
expect(snapshot.context.recordingControlsAvailable).toBe(true);
|
|
40
|
+
expect(snapshot.context.recordingInProgress).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('updates recordingPaused when ASSIGN payload reports pause', () => {
|
|
44
|
+
const service = startMachine();
|
|
45
|
+
const initialTaskData = createTaskData();
|
|
46
|
+
const pausedTaskData = createTaskData({
|
|
47
|
+
interaction: {
|
|
48
|
+
callProcessingDetails: {
|
|
49
|
+
isPaused: true,
|
|
50
|
+
},
|
|
51
|
+
} as any,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData: initialTaskData});
|
|
55
|
+
service.send({type: TaskEvent.ASSIGN, taskData: pausedTaskData});
|
|
56
|
+
|
|
57
|
+
const snapshot = service.getSnapshot();
|
|
58
|
+
expect(snapshot.context.recordingControlsAvailable).toBe(true);
|
|
59
|
+
expect(snapshot.context.recordingInProgress).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('updates recording state when recording started event arrives', () => {
|
|
63
|
+
const service = startMachine();
|
|
64
|
+
const initialTaskData = createTaskData();
|
|
65
|
+
const recordingTaskData = createTaskData({
|
|
66
|
+
interaction: {
|
|
67
|
+
callProcessingDetails: {
|
|
68
|
+
recordingStarted: true,
|
|
69
|
+
recordInProgress: true,
|
|
70
|
+
},
|
|
71
|
+
} as any,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData: initialTaskData});
|
|
75
|
+
service.send({type: TaskEvent.ASSIGN, taskData: initialTaskData});
|
|
76
|
+
service.send({type: TaskEvent.RECORDING_STARTED, taskData: recordingTaskData});
|
|
77
|
+
|
|
78
|
+
const snapshot = service.getSnapshot();
|
|
79
|
+
expect(snapshot.value).toBe(TaskState.CONNECTED);
|
|
80
|
+
expect(snapshot.context.recordingControlsAvailable).toBe(true);
|
|
81
|
+
expect(snapshot.context.recordingInProgress).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('hold and resume flow', () => {
|
|
86
|
+
it('moves through HOLD -> HELD -> CONNECTED on success events', () => {
|
|
87
|
+
const service = startMachine();
|
|
88
|
+
const taskData = createTaskData();
|
|
89
|
+
|
|
90
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
91
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
92
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
93
|
+
|
|
94
|
+
service.send({type: TaskEvent.HOLD_INITIATED, mediaResourceId: taskData.mediaResourceId});
|
|
95
|
+
expect(service.getSnapshot().value).toBe(TaskState.HOLD_INITIATING);
|
|
96
|
+
|
|
97
|
+
service.send({type: TaskEvent.HOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId});
|
|
98
|
+
expect(service.getSnapshot().value).toBe(TaskState.HELD);
|
|
99
|
+
|
|
100
|
+
service.send({type: TaskEvent.UNHOLD_INITIATED, mediaResourceId: taskData.mediaResourceId});
|
|
101
|
+
expect(service.getSnapshot().value).toBe(TaskState.RESUME_INITIATING);
|
|
102
|
+
|
|
103
|
+
service.send({type: TaskEvent.UNHOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId});
|
|
104
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('recording pause/resume events', () => {
|
|
109
|
+
it('toggles recordingPaused flag based on events', () => {
|
|
110
|
+
const service = startMachine();
|
|
111
|
+
const taskData = createTaskData({
|
|
112
|
+
interaction: {
|
|
113
|
+
callProcessingDetails: {recordInProgress: true},
|
|
114
|
+
} as any,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
118
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
119
|
+
expect(service.getSnapshot().context.recordingInProgress).toBe(true);
|
|
120
|
+
|
|
121
|
+
service.send({type: TaskEvent.PAUSE_RECORDING});
|
|
122
|
+
expect(service.getSnapshot().context.recordingInProgress).toBe(false);
|
|
123
|
+
|
|
124
|
+
service.send({type: TaskEvent.RESUME_RECORDING});
|
|
125
|
+
expect(service.getSnapshot().context.recordingInProgress).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('wrap-up and completion flow', () => {
|
|
130
|
+
it('moves from CONNECTED -> WRAPPING_UP -> COMPLETED on END/WRAPUP_COMPLETE', () => {
|
|
131
|
+
const service = startMachine();
|
|
132
|
+
const taskData = createTaskData();
|
|
133
|
+
|
|
134
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
135
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
136
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
137
|
+
|
|
138
|
+
service.send({type: TaskEvent.TASK_WRAPUP});
|
|
139
|
+
expect(service.getSnapshot().value).toBe(TaskState.WRAPPING_UP);
|
|
140
|
+
|
|
141
|
+
service.send({type: TaskEvent.WRAPUP_COMPLETE});
|
|
142
|
+
expect(service.getSnapshot().value).toBe(TaskState.COMPLETED);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('handles CONTACT_ENDED by entering wrapping up before completion', () => {
|
|
146
|
+
const service = startMachine();
|
|
147
|
+
// Primary agent (isConsulted: false) should go to WRAPPING_UP
|
|
148
|
+
const taskData = createTaskData({isConsulted: false} as any);
|
|
149
|
+
|
|
150
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
151
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
152
|
+
|
|
153
|
+
// CONTACT_ENDED event must include taskData for shouldWrapUpForThisAgent check
|
|
154
|
+
service.send({type: TaskEvent.CONTACT_ENDED, taskData});
|
|
155
|
+
expect(service.getSnapshot().value).toBe(TaskState.WRAPPING_UP);
|
|
156
|
+
|
|
157
|
+
service.send({type: TaskEvent.WRAPUP_COMPLETE});
|
|
158
|
+
expect(service.getSnapshot().value).toBe(TaskState.COMPLETED);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('consult and conference flows', () => {
|
|
163
|
+
it('boots from IDLE to CONSULTING on CONSULTING_ACTIVE for split-leg ordering', () => {
|
|
164
|
+
const service = startMachine();
|
|
165
|
+
const taskData = createTaskData({
|
|
166
|
+
consultingAgentId: 'agent-1',
|
|
167
|
+
isConsulted: false,
|
|
168
|
+
interaction: {
|
|
169
|
+
state: 'consulting',
|
|
170
|
+
} as any,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(service.getSnapshot().value).toBe(TaskState.IDLE);
|
|
174
|
+
service.send({
|
|
175
|
+
type: TaskEvent.CONSULTING_ACTIVE,
|
|
176
|
+
consultDestinationAgentJoined: true,
|
|
177
|
+
taskData,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULTING);
|
|
181
|
+
expect(service.getSnapshot().context.consultDestinationAgentJoined).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('tracks consult destination, agent join, and clears on consult end', () => {
|
|
185
|
+
const service = startMachine();
|
|
186
|
+
const taskData = createTaskData();
|
|
187
|
+
|
|
188
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
189
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
190
|
+
|
|
191
|
+
service.send({
|
|
192
|
+
type: TaskEvent.CONSULT,
|
|
193
|
+
destination: 'agent-42',
|
|
194
|
+
destinationType: 'agent',
|
|
195
|
+
});
|
|
196
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULT_INITIATING);
|
|
197
|
+
expect(service.getSnapshot().context.consultInitiator).toBe(true);
|
|
198
|
+
|
|
199
|
+
service.send({type: TaskEvent.CONSULT_SUCCESS});
|
|
200
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULTING);
|
|
201
|
+
|
|
202
|
+
service.send({
|
|
203
|
+
type: TaskEvent.CONSULTING_ACTIVE,
|
|
204
|
+
consultDestinationAgentJoined: true,
|
|
205
|
+
});
|
|
206
|
+
expect(service.getSnapshot().context.consultDestinationAgentJoined).toBe(true);
|
|
207
|
+
|
|
208
|
+
service.send({type: TaskEvent.CONSULT_END});
|
|
209
|
+
const snapshotAfterEnd = service.getSnapshot();
|
|
210
|
+
expect(snapshotAfterEnd.value).toBe(TaskState.HELD);
|
|
211
|
+
expect(snapshotAfterEnd.context.consultDestinationAgentJoined).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('returns to connected when consult ends after switching back to the main leg', () => {
|
|
215
|
+
const service = startMachine();
|
|
216
|
+
const taskData = createTaskData();
|
|
217
|
+
|
|
218
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
219
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
220
|
+
service.send({
|
|
221
|
+
type: TaskEvent.CONSULT,
|
|
222
|
+
destination: 'agent-42',
|
|
223
|
+
destinationType: 'agent',
|
|
224
|
+
});
|
|
225
|
+
service.send({type: TaskEvent.CONSULT_SUCCESS});
|
|
226
|
+
service.send({type: TaskEvent.SWITCH_TO_MAIN_CALL});
|
|
227
|
+
|
|
228
|
+
expect(service.getSnapshot().context.consultCallHeld).toBe(true);
|
|
229
|
+
|
|
230
|
+
service.send({type: TaskEvent.CONSULT_END});
|
|
231
|
+
|
|
232
|
+
const snapshotAfterEnd = service.getSnapshot();
|
|
233
|
+
expect(snapshotAfterEnd.value).toBe(TaskState.CONNECTED);
|
|
234
|
+
expect(snapshotAfterEnd.context.consultCallHeld).toBe(false);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('transitions to conferencing when merge event is received', () => {
|
|
238
|
+
const service = startMachine();
|
|
239
|
+
const taskData = createTaskData({consultingAgentId: 'agent-1'});
|
|
240
|
+
|
|
241
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
242
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
243
|
+
service.send({
|
|
244
|
+
type: TaskEvent.CONSULT,
|
|
245
|
+
destination: 'agent-42',
|
|
246
|
+
destinationType: 'agent',
|
|
247
|
+
});
|
|
248
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULT_INITIATING);
|
|
249
|
+
service.send({type: TaskEvent.CONSULT_SUCCESS, taskData});
|
|
250
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULTING);
|
|
251
|
+
|
|
252
|
+
service.send({type: TaskEvent.MERGE_TO_CONFERENCE});
|
|
253
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONF_INITIATING);
|
|
254
|
+
|
|
255
|
+
service.send({type: TaskEvent.CONFERENCE_START});
|
|
256
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONFERENCING);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('terminates via wrapup when EXIT_CONFERENCE_SUCCESS is received in conferencing', () => {
|
|
260
|
+
const service = startMachine();
|
|
261
|
+
const taskData = createTaskData({
|
|
262
|
+
// shouldWrapUpForThisAgent will return true when owner matches self agent
|
|
263
|
+
interaction: {
|
|
264
|
+
owner: 'agent-1',
|
|
265
|
+
state: 'conference',
|
|
266
|
+
mainInteractionId: 'interaction-1',
|
|
267
|
+
interactionId: 'interaction-1',
|
|
268
|
+
participants: {
|
|
269
|
+
'agent-1': {
|
|
270
|
+
id: 'agent-1',
|
|
271
|
+
pType: 'Agent',
|
|
272
|
+
type: 'Agent',
|
|
273
|
+
hasJoined: true,
|
|
274
|
+
hasLeft: false,
|
|
275
|
+
isInPredial: false,
|
|
276
|
+
},
|
|
277
|
+
c1: {
|
|
278
|
+
id: 'c1',
|
|
279
|
+
pType: 'Customer',
|
|
280
|
+
type: 'Customer',
|
|
281
|
+
hasJoined: true,
|
|
282
|
+
hasLeft: false,
|
|
283
|
+
isInPredial: false,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
media: {
|
|
287
|
+
'interaction-1': {
|
|
288
|
+
mediaResourceId: 'interaction-1',
|
|
289
|
+
mediaType: 'telephony',
|
|
290
|
+
mediaMgr: 'mm',
|
|
291
|
+
participants: ['agent-1', 'c1'],
|
|
292
|
+
mType: 'mainCall',
|
|
293
|
+
isHold: false,
|
|
294
|
+
holdTimestamp: null,
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
} as any,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
301
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
302
|
+
service.send({
|
|
303
|
+
type: TaskEvent.CONSULT,
|
|
304
|
+
destination: 'agent-42',
|
|
305
|
+
destinationType: 'agent',
|
|
306
|
+
});
|
|
307
|
+
service.send({type: TaskEvent.CONSULT_SUCCESS, taskData});
|
|
308
|
+
service.send({type: TaskEvent.MERGE_TO_CONFERENCE});
|
|
309
|
+
service.send({type: TaskEvent.CONFERENCE_START, taskData});
|
|
310
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONFERENCING);
|
|
311
|
+
|
|
312
|
+
service.send({type: TaskEvent.EXIT_CONFERENCE_SUCCESS, taskData});
|
|
313
|
+
expect(service.getSnapshot().value).toBe(TaskState.WRAPPING_UP);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('terminates when EXIT_CONFERENCE_SUCCESS is received in conferencing and wrapup is not required', () => {
|
|
317
|
+
const service = startMachine();
|
|
318
|
+
const taskData = createTaskData({
|
|
319
|
+
isConsulted: true,
|
|
320
|
+
wrapUpRequired: false,
|
|
321
|
+
interaction: {
|
|
322
|
+
owner: 'other-agent',
|
|
323
|
+
state: 'conference',
|
|
324
|
+
mainInteractionId: 'interaction-1',
|
|
325
|
+
interactionId: 'interaction-1',
|
|
326
|
+
participants: {
|
|
327
|
+
'agent-1': {
|
|
328
|
+
id: 'agent-1',
|
|
329
|
+
pType: 'Agent',
|
|
330
|
+
type: 'Agent',
|
|
331
|
+
hasJoined: true,
|
|
332
|
+
hasLeft: false,
|
|
333
|
+
isInPredial: false,
|
|
334
|
+
isWrapUp: false,
|
|
335
|
+
},
|
|
336
|
+
c1: {
|
|
337
|
+
id: 'c1',
|
|
338
|
+
pType: 'Customer',
|
|
339
|
+
type: 'Customer',
|
|
340
|
+
hasJoined: true,
|
|
341
|
+
hasLeft: false,
|
|
342
|
+
isInPredial: false,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
media: {
|
|
346
|
+
'interaction-1': {
|
|
347
|
+
mediaResourceId: 'interaction-1',
|
|
348
|
+
mediaType: 'telephony',
|
|
349
|
+
mediaMgr: 'mm',
|
|
350
|
+
participants: ['agent-1', 'c1'],
|
|
351
|
+
mType: 'mainCall',
|
|
352
|
+
isHold: false,
|
|
353
|
+
holdTimestamp: null,
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
} as any,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
360
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
361
|
+
service.send({
|
|
362
|
+
type: TaskEvent.CONSULT,
|
|
363
|
+
destination: 'agent-42',
|
|
364
|
+
destinationType: 'agent',
|
|
365
|
+
});
|
|
366
|
+
service.send({type: TaskEvent.CONSULT_SUCCESS, taskData});
|
|
367
|
+
service.send({type: TaskEvent.MERGE_TO_CONFERENCE});
|
|
368
|
+
service.send({type: TaskEvent.CONFERENCE_START, taskData});
|
|
369
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONFERENCING);
|
|
370
|
+
|
|
371
|
+
service.send({type: TaskEvent.EXIT_CONFERENCE_SUCCESS, taskData});
|
|
372
|
+
expect(service.getSnapshot().value).toBe(TaskState.TERMINATED);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('returns to CONNECTED when CTQ cancel arrives before queue connects', () => {
|
|
376
|
+
const service = startMachine();
|
|
377
|
+
const taskData = createTaskData();
|
|
378
|
+
|
|
379
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
380
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
381
|
+
|
|
382
|
+
service.send({
|
|
383
|
+
type: TaskEvent.CONSULT,
|
|
384
|
+
destination: 'queue-1',
|
|
385
|
+
destinationType: 'queue',
|
|
386
|
+
});
|
|
387
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULT_INITIATING);
|
|
388
|
+
|
|
389
|
+
service.send({type: TaskEvent.CTQ_CANCEL});
|
|
390
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('returns to CONNECTED when CTQ consult fails', () => {
|
|
394
|
+
const service = startMachine();
|
|
395
|
+
const taskData = createTaskData();
|
|
396
|
+
|
|
397
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
398
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
399
|
+
|
|
400
|
+
service.send({
|
|
401
|
+
type: TaskEvent.CONSULT,
|
|
402
|
+
destination: 'queue-1',
|
|
403
|
+
destinationType: 'queue',
|
|
404
|
+
});
|
|
405
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONSULT_INITIATING);
|
|
406
|
+
|
|
407
|
+
service.send({type: TaskEvent.CONSULT_FAILED, taskData});
|
|
408
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe('failure scenarios', () => {
|
|
413
|
+
it('returns to CONNECTED when HOLD fails', () => {
|
|
414
|
+
const service = startMachine();
|
|
415
|
+
const taskData = createTaskData();
|
|
416
|
+
|
|
417
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
418
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
419
|
+
service.send({type: TaskEvent.HOLD_INITIATED, mediaResourceId: taskData.mediaResourceId});
|
|
420
|
+
expect(service.getSnapshot().value).toBe(TaskState.HOLD_INITIATING);
|
|
421
|
+
|
|
422
|
+
service.send({
|
|
423
|
+
type: TaskEvent.HOLD_FAILED,
|
|
424
|
+
mediaResourceId: taskData.mediaResourceId,
|
|
425
|
+
});
|
|
426
|
+
expect(service.getSnapshot().value).toBe(TaskState.CONNECTED);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('falls back to HELD when UNHOLD fails', () => {
|
|
430
|
+
const service = startMachine();
|
|
431
|
+
const taskData = createTaskData();
|
|
432
|
+
|
|
433
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
434
|
+
service.send({type: TaskEvent.ASSIGN, taskData});
|
|
435
|
+
service.send({type: TaskEvent.HOLD_INITIATED, mediaResourceId: taskData.mediaResourceId});
|
|
436
|
+
service.send({type: TaskEvent.HOLD_SUCCESS, mediaResourceId: taskData.mediaResourceId});
|
|
437
|
+
expect(service.getSnapshot().value).toBe(TaskState.HELD);
|
|
438
|
+
|
|
439
|
+
service.send({type: TaskEvent.UNHOLD_INITIATED, mediaResourceId: taskData.mediaResourceId});
|
|
440
|
+
expect(service.getSnapshot().value).toBe(TaskState.RESUME_INITIATING);
|
|
441
|
+
|
|
442
|
+
service.send({type: TaskEvent.UNHOLD_FAILED, mediaResourceId: taskData.mediaResourceId});
|
|
443
|
+
expect(service.getSnapshot().value).toBe(TaskState.HELD);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
describe('OFFERED state event handlers', () => {
|
|
448
|
+
it('transitions to TERMINATED when customer disconnects before agent answers', () => {
|
|
449
|
+
const service = startMachine();
|
|
450
|
+
const taskData = createTaskData({isConsulted: false});
|
|
451
|
+
|
|
452
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
453
|
+
expect(service.getSnapshot().value).toBe(TaskState.OFFERED);
|
|
454
|
+
|
|
455
|
+
service.send({type: TaskEvent.CONTACT_ENDED, taskData});
|
|
456
|
+
expect(service.getSnapshot().value).toBe(TaskState.TERMINATED);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('transitions to TERMINATED when consulted agent does not answer', () => {
|
|
460
|
+
const service = startMachine();
|
|
461
|
+
const taskData = createTaskData({
|
|
462
|
+
isConsulted: true,
|
|
463
|
+
consultingAgentId: 'agent-1',
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
service.send({type: TaskEvent.TASK_INCOMING, taskData});
|
|
467
|
+
expect(service.getSnapshot().value).toBe(TaskState.OFFERED);
|
|
468
|
+
|
|
469
|
+
service.send({type: TaskEvent.CONSULT_FAILED, taskData});
|
|
470
|
+
expect(service.getSnapshot().value).toBe(TaskState.TERMINATED);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
});
|