@webex/contact-center 3.12.0-llmrefactor.1 → 3.12.0-llmrefactor.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.sdd/manifest.json +7 -5
  2. package/ai-docs/ARCHITECTURE.md +1 -1
  3. package/ai-docs/CONTRACTS.md +8 -3
  4. package/ai-docs/SECURITY.md +1 -1
  5. package/ai-docs/contact-center-spec.md +22 -4
  6. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  7. package/dist/cc.js +544 -12
  8. package/dist/cc.js.map +1 -1
  9. package/dist/config.js +7 -0
  10. package/dist/config.js.map +1 -1
  11. package/dist/constants.js +10 -2
  12. package/dist/constants.js.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/metrics/MetricsManager.js +16 -0
  15. package/dist/metrics/MetricsManager.js.map +1 -1
  16. package/dist/metrics/behavioral-events.js +104 -0
  17. package/dist/metrics/behavioral-events.js.map +1 -1
  18. package/dist/metrics/constants.js +18 -0
  19. package/dist/metrics/constants.js.map +1 -1
  20. package/dist/services/AddressBook.js +18 -15
  21. package/dist/services/AddressBook.js.map +1 -1
  22. package/dist/services/AnswerCallOnWebexService.js +202 -0
  23. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  24. package/dist/services/EntryPoint.js +46 -68
  25. package/dist/services/EntryPoint.js.map +1 -1
  26. package/dist/services/Queue.js +27 -22
  27. package/dist/services/Queue.js.map +1 -1
  28. package/dist/services/WebexCrossClientService.js +222 -0
  29. package/dist/services/WebexCrossClientService.js.map +1 -0
  30. package/dist/services/WxAppTelephonyMercurySync.js +108 -0
  31. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  32. package/dist/services/config/Util.js +3 -0
  33. package/dist/services/config/Util.js.map +1 -1
  34. package/dist/services/config/constants.js +10 -6
  35. package/dist/services/config/constants.js.map +1 -1
  36. package/dist/services/config/types.js +4 -0
  37. package/dist/services/config/types.js.map +1 -1
  38. package/dist/services/core/Err.js.map +1 -1
  39. package/dist/services/core/WebexRequest.js +6 -2
  40. package/dist/services/core/WebexRequest.js.map +1 -1
  41. package/dist/services/core/aqm-reqs.js +28 -14
  42. package/dist/services/core/aqm-reqs.js.map +1 -1
  43. package/dist/services/core/types.js.map +1 -1
  44. package/dist/services/task/Task.js +73 -7
  45. package/dist/services/task/Task.js.map +1 -1
  46. package/dist/services/task/TaskFactory.js +8 -4
  47. package/dist/services/task/TaskFactory.js.map +1 -1
  48. package/dist/services/task/TaskManager.js +490 -21
  49. package/dist/services/task/TaskManager.js.map +1 -1
  50. package/dist/services/task/WebexCallingUtils.js +70 -0
  51. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  52. package/dist/services/task/constants.js +4 -1
  53. package/dist/services/task/constants.js.map +1 -1
  54. package/dist/services/task/contact.js +29 -0
  55. package/dist/services/task/contact.js.map +1 -1
  56. package/dist/services/task/digital/Digital.js +3 -2
  57. package/dist/services/task/digital/Digital.js.map +1 -1
  58. package/dist/services/task/state-machine/TaskStateMachine.js +162 -53
  59. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -1
  60. package/dist/services/task/state-machine/actions.js +6 -1
  61. package/dist/services/task/state-machine/actions.js.map +1 -1
  62. package/dist/services/task/state-machine/guards.js +7 -10
  63. package/dist/services/task/state-machine/guards.js.map +1 -1
  64. package/dist/services/task/state-machine/types.js.map +1 -1
  65. package/dist/services/task/state-machine/uiControlsComputer.js +118 -18
  66. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -1
  67. package/dist/services/task/types.js +16 -1
  68. package/dist/services/task/types.js.map +1 -1
  69. package/dist/services/task/voice/Voice.js +456 -15
  70. package/dist/services/task/voice/Voice.js.map +1 -1
  71. package/dist/services/task/voice/WebRTC.js +4 -1
  72. package/dist/services/task/voice/WebRTC.js.map +1 -1
  73. package/dist/services/task/voice/wxAppVoiceMethods.js +354 -0
  74. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  75. package/dist/services/wxAppDiagnosticLogging.js +122 -0
  76. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  77. package/dist/services/wxAppTelephonyUtils.js +19 -0
  78. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  79. package/dist/types/cc.d.ts +78 -4
  80. package/dist/types/config.d.ts +7 -0
  81. package/dist/types/constants.d.ts +8 -0
  82. package/dist/types/index.d.ts +3 -1
  83. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  84. package/dist/types/metrics/constants.d.ts +17 -0
  85. package/dist/types/services/AddressBook.d.ts +2 -1
  86. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  87. package/dist/types/services/EntryPoint.d.ts +7 -5
  88. package/dist/types/services/Queue.d.ts +5 -3
  89. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  90. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  91. package/dist/types/services/config/constants.d.ts +8 -5
  92. package/dist/types/services/config/types.d.ts +17 -4
  93. package/dist/types/services/core/Err.d.ts +2 -0
  94. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  95. package/dist/types/services/core/types.d.ts +2 -0
  96. package/dist/types/services/task/Task.d.ts +20 -2
  97. package/dist/types/services/task/TaskFactory.d.ts +2 -1
  98. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  99. package/dist/types/services/task/constants.d.ts +3 -0
  100. package/dist/types/services/task/contact.d.ts +4 -0
  101. package/dist/types/services/task/digital/Digital.d.ts +2 -2
  102. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +304 -56
  103. package/dist/types/services/task/state-machine/guards.d.ts +6 -5
  104. package/dist/types/services/task/state-machine/types.d.ts +9 -1
  105. package/dist/types/services/task/types.d.ts +81 -4
  106. package/dist/types/services/task/voice/Voice.d.ts +52 -9
  107. package/dist/types/services/task/voice/WebRTC.d.ts +2 -2
  108. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +55 -0
  109. package/dist/types/services/wxAppDiagnosticLogging.d.ts +51 -0
  110. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  111. package/dist/types/types.d.ts +14 -8
  112. package/dist/types/utils/PageCache.d.ts +20 -3
  113. package/dist/types.js +7 -2
  114. package/dist/types.js.map +1 -1
  115. package/dist/utils/PageCache.js +19 -5
  116. package/dist/utils/PageCache.js.map +1 -1
  117. package/dist/webex.js +1 -1
  118. package/package.json +8 -8
  119. package/src/cc.ts +657 -12
  120. package/src/config.ts +7 -0
  121. package/src/constants.ts +8 -0
  122. package/src/index.ts +2 -0
  123. package/src/metrics/MetricsManager.ts +16 -0
  124. package/src/metrics/ai-docs/metrics-spec.md +78 -10
  125. package/src/metrics/behavioral-events.ts +106 -0
  126. package/src/metrics/constants.ts +20 -0
  127. package/src/services/AddressBook.ts +17 -6
  128. package/src/services/AnswerCallOnWebexService.ts +239 -0
  129. package/src/services/EntryPoint.ts +59 -60
  130. package/src/services/Queue.ts +29 -12
  131. package/src/services/WebexCrossClientService.ts +293 -0
  132. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  133. package/src/services/agent/ai-docs/agent-spec.md +1 -0
  134. package/src/services/ai-docs/AGENTS.md +10 -10
  135. package/src/services/ai-docs/services-spec.md +6 -1
  136. package/src/services/config/Util.ts +3 -0
  137. package/src/services/config/ai-docs/AGENTS.md +1 -1
  138. package/src/services/config/ai-docs/ARCHITECTURE.md +2 -2
  139. package/src/services/config/ai-docs/config-spec.md +6 -0
  140. package/src/services/config/constants.ts +10 -6
  141. package/src/services/config/types.ts +16 -4
  142. package/src/services/core/Err.ts +1 -0
  143. package/src/services/core/WebexRequest.ts +3 -1
  144. package/src/services/core/ai-docs/core-spec.md +5 -1
  145. package/src/services/core/aqm-reqs.ts +30 -15
  146. package/src/services/core/types.ts +2 -0
  147. package/src/services/task/Task.ts +79 -8
  148. package/src/services/task/TaskFactory.ts +8 -3
  149. package/src/services/task/TaskManager.ts +716 -17
  150. package/src/services/task/WebexCallingUtils.ts +136 -0
  151. package/src/services/task/ai-docs/ARCHITECTURE.md +1 -0
  152. package/src/services/task/ai-docs/task-spec.md +156 -3
  153. package/src/services/task/constants.ts +3 -0
  154. package/src/services/task/contact.ts +30 -0
  155. package/src/services/task/digital/Digital.ts +4 -2
  156. package/src/services/task/state-machine/TaskStateMachine.ts +235 -81
  157. package/src/services/task/state-machine/actions.ts +5 -2
  158. package/src/services/task/state-machine/ai-docs/AGENTS.md +6 -4
  159. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +35 -16
  160. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +103 -33
  161. package/src/services/task/state-machine/guards.ts +7 -10
  162. package/src/services/task/state-machine/types.ts +16 -1
  163. package/src/services/task/state-machine/uiControlsComputer.ts +206 -32
  164. package/src/services/task/types.ts +114 -4
  165. package/src/services/task/voice/Voice.ts +595 -14
  166. package/src/services/task/voice/WebRTC.ts +5 -1
  167. package/src/services/task/voice/wxAppVoiceMethods.ts +516 -0
  168. package/src/services/wxAppDiagnosticLogging.ts +174 -0
  169. package/src/services/wxAppTelephonyUtils.ts +14 -0
  170. package/src/types.ts +33 -9
  171. package/src/utils/AGENTS.md +21 -10
  172. package/src/utils/PageCache.ts +38 -5
  173. package/src/utils/ai-docs/utils-spec.md +21 -11
  174. package/test/unit/spec/cc.ts +1522 -19
  175. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  176. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  177. package/test/unit/spec/services/AddressBook.ts +37 -6
  178. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  179. package/test/unit/spec/services/EntryPoint.ts +87 -40
  180. package/test/unit/spec/services/Queue.ts +123 -12
  181. package/test/unit/spec/services/WebexCrossClientService.ts +467 -0
  182. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  183. package/test/unit/spec/services/config/Util.ts +85 -0
  184. package/test/unit/spec/services/core/WebexRequest.ts +3 -1
  185. package/test/unit/spec/services/core/aqm-reqs.ts +113 -1
  186. package/test/unit/spec/services/task/Task.ts +274 -6
  187. package/test/unit/spec/services/task/TaskFactory.ts +39 -2
  188. package/test/unit/spec/services/task/TaskManager.ts +1717 -9
  189. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  190. package/test/unit/spec/services/task/contact.ts +33 -0
  191. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1485 -109
  192. package/test/unit/spec/services/task/state-machine/guards.ts +210 -8
  193. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +445 -7
  194. package/test/unit/spec/services/task/voice/Voice.ts +1412 -0
  195. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +603 -0
  196. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +143 -0
  197. package/umd/contact-center.min.js +2 -2
  198. package/umd/contact-center.min.js.map +1 -1
@@ -334,6 +334,28 @@ describe('AqmReqs', () => {
334
334
  });
335
335
 
336
336
  describe('Event tests', () => {
337
+ const participantDropConfig = (participantId: string, timeout?: number | 'disabled') => ({
338
+ host: 'fake-host',
339
+ url: `/v1/tasks/interaction/conference/participants/${participantId}/drop`,
340
+ data: {},
341
+ timeout,
342
+ redactSensitiveLogs: true,
343
+ err: (error: any) => error,
344
+ notifSuccess: {
345
+ bind: {
346
+ type: 'RoutingMessage',
347
+ data: {type: 'ParticipantLeftConference', interactionId: 'interaction'},
348
+ },
349
+ },
350
+ notifFail: {
351
+ bind: {
352
+ type: 'RoutingMessage',
353
+ data: {type: 'ParticipantDropConferenceFailed'},
354
+ },
355
+ errId: 'Service.aqm.task.dropConferenceParticipant' as const,
356
+ },
357
+ });
358
+
337
359
  it('should handle onMessage events', async () => {
338
360
  webexRequestInstance.request.mockResolvedValueOnce(mockWebexRequestResolvedValue);
339
361
 
@@ -564,5 +586,95 @@ describe('AqmReqs', () => {
564
586
  const result = await promise;
565
587
  expect(result).toEqual(eventData);
566
588
  });
589
+
590
+ it('redacts sensitive routing failure payloads from logs', async () => {
591
+ const participantId = '+1/failure-secret';
592
+ webexRequestInstance.request.mockResolvedValueOnce(mockWebexRequestResolvedValue);
593
+ const promise = aqm['createPromise'](participantDropConfig(participantId, 'disabled'));
594
+
595
+ webSocketManagerInstance.emit(
596
+ 'message',
597
+ JSON.stringify({
598
+ type: 'RoutingMessage',
599
+ data: {type: 'ParticipantDropConferenceFailed', participantId},
600
+ })
601
+ );
602
+
603
+ await expect(promise).rejects.toBeDefined();
604
+ expect(LoggerProxy.log).toHaveBeenCalledTimes(1);
605
+ expect(LoggerProxy.log).toHaveBeenCalledWith(
606
+ 'Routing request failed (sensitive details redacted)',
607
+ expect.objectContaining({module: AQM_REQS_FILE})
608
+ );
609
+ expect(JSON.stringify((LoggerProxy.log as jest.Mock).mock.calls)).not.toContain(participantId);
610
+ expect(aqm['pendingRequests']).toEqual({});
611
+ });
612
+
613
+ it('resolves a correlated participant-left event and clears its binds', async () => {
614
+ jest.useFakeTimers();
615
+ (global.window as any).setTimeout = global.setTimeout;
616
+
617
+ try {
618
+ const participantId = '+1/success-secret';
619
+ webexRequestInstance.request.mockResolvedValueOnce(mockWebexRequestResolvedValue);
620
+ const promise = aqm['createPromise'](participantDropConfig(participantId));
621
+ const eventData = {
622
+ type: 'RoutingMessage',
623
+ data: {type: 'ParticipantLeftConference', interactionId: 'interaction'},
624
+ };
625
+
626
+ webSocketManagerInstance.emit('message', JSON.stringify(eventData));
627
+
628
+ await expect(promise).resolves.toEqual(eventData);
629
+ expect(aqm['pendingRequests']).toEqual({});
630
+ } finally {
631
+ jest.useRealTimers();
632
+ (global.window as any).setTimeout = global.setTimeout;
633
+ }
634
+ });
635
+
636
+ it('clears participant Drop binds after an HTTP failure without logging sensitive data', async () => {
637
+ jest.useFakeTimers();
638
+ (global.window as any).setTimeout = global.setTimeout;
639
+
640
+ try {
641
+ const participantId = '+1/http-secret';
642
+ const httpFailure = {headers: {Authorization: 'Bearer secret'}};
643
+ webexRequestInstance.request.mockRejectedValueOnce(httpFailure);
644
+ const promise = aqm['createPromise'](participantDropConfig(participantId));
645
+
646
+ await expect(promise).rejects.toBe(httpFailure);
647
+ expect(aqm['pendingRequests']).toEqual({});
648
+ expect(JSON.stringify([
649
+ (LoggerProxy.log as jest.Mock).mock.calls,
650
+ (LoggerProxy.error as jest.Mock).mock.calls,
651
+ ])).not.toContain(participantId);
652
+ expect(httpFailure.headers.Authorization).toBe('*');
653
+ } finally {
654
+ jest.useRealTimers();
655
+ (global.window as any).setTimeout = global.setTimeout;
656
+ }
657
+ });
658
+
659
+ it('uses the default timeout without logging a sensitive request URL', async () => {
660
+ jest.useFakeTimers();
661
+ (global.window as any).setTimeout = global.setTimeout;
662
+
663
+ try {
664
+ const participantId = '+1/timeout-secret';
665
+ webexRequestInstance.request.mockResolvedValueOnce(mockWebexRequestResolvedValue);
666
+ const promise = aqm['createPromise'](participantDropConfig(participantId));
667
+ const rejection = expect(promise).rejects.toBeDefined();
668
+
669
+ jest.advanceTimersByTime(20000);
670
+
671
+ await rejection;
672
+ expect(JSON.stringify((LoggerProxy.error as jest.Mock).mock.calls)).not.toContain(participantId);
673
+ expect(aqm['pendingRequests']).toEqual({});
674
+ } finally {
675
+ jest.useRealTimers();
676
+ (global.window as any).setTimeout = global.setTimeout;
677
+ }
678
+ });
567
679
  });
568
- });
680
+ });
@@ -4,19 +4,27 @@ import {
4
4
  DESTINATION_TYPE,
5
5
  TASK_EVENTS,
6
6
  TASK_CHANNEL_TYPE,
7
+ TransferPayLoad,
7
8
  VOICE_VARIANT,
8
9
  } from '../../../../../src/services/task/types';
9
10
  import {TaskEvent} from '../../../../../src/services/task/state-machine';
11
+ import {ENTRY_POINT_TRANSFER_DESTINATION_TYPE} from '../../../../../src/services/task/constants';
10
12
  import LoggerProxy from '../../../../../src/logger-proxy';
11
13
  import {createTaskData} from './taskTestUtils';
12
14
 
13
15
  class DummyTask extends Task {
14
- constructor(contact: any, data: TaskData) {
15
- super(contact, data, {
16
- channelType: 'voice',
17
- isEndTaskEnabled: true,
18
- isEndConsultEnabled: true,
19
- });
16
+ constructor(contact: any, data: TaskData, wrapupData?: any, agentId?: string) {
17
+ super(
18
+ contact,
19
+ data,
20
+ {
21
+ channelType: 'voice',
22
+ isEndTaskEnabled: true,
23
+ isEndConsultEnabled: true,
24
+ },
25
+ wrapupData,
26
+ agentId
27
+ );
20
28
  }
21
29
 
22
30
  public accept() {
@@ -24,6 +32,20 @@ class DummyTask extends Task {
24
32
  }
25
33
  }
26
34
 
35
+ class ConferenceTask extends DummyTask {
36
+ protected override getChannelSpecificActionOverrides() {
37
+ return {
38
+ ...super.getChannelSpecificActionOverrides(),
39
+ emitTaskParticipantLeft: this.createEmitSelfAction(TASK_EVENTS.TASK_PARTICIPANT_LEFT, {
40
+ updateTaskData: true,
41
+ }),
42
+ emitTaskConferenceEnded: this.createEmitSelfAction(TASK_EVENTS.TASK_CONFERENCE_ENDED, {
43
+ updateTaskData: true,
44
+ }),
45
+ };
46
+ }
47
+ }
48
+
27
49
  class SpyAcceptTask extends Task {
28
50
  public acceptMock: jest.Mock;
29
51
 
@@ -234,6 +256,68 @@ describe('Task (base class)', () => {
234
256
  expect(emitSpy).not.toHaveBeenCalledWith(TASK_EVENTS.TASK_WRAPUP, task);
235
257
  });
236
258
 
259
+ it('starts auto wrap-up only when wrapUpRequired is true and profile autoWrapup is enabled', () => {
260
+ const wrapUpProps = {
261
+ autoWrapup: true,
262
+ autoWrapupInterval: 25000,
263
+ wrapUpReasonList: [{id: 'code-1', name: 'Default', isDefault: true, isSystem: false}],
264
+ };
265
+ const enabled = new DummyTask(
266
+ dummyContact,
267
+ createTaskData({wrapUpRequired: false}) as TaskData,
268
+ {wrapUpProps},
269
+ 'agent-1'
270
+ );
271
+
272
+ expect(enabled.autoWrapup).toBeUndefined();
273
+ try {
274
+ enabled.updateTaskData(createTaskData({wrapUpRequired: true}) as TaskData);
275
+ expect(enabled.autoWrapup).toBeDefined();
276
+
277
+ const disabled = new DummyTask(
278
+ dummyContact,
279
+ createTaskData({wrapUpRequired: false}) as TaskData,
280
+ {wrapUpProps: {...wrapUpProps, autoWrapup: false}},
281
+ 'agent-1'
282
+ );
283
+ disabled.updateTaskData(createTaskData({wrapUpRequired: true}) as TaskData);
284
+ expect(disabled.autoWrapup).toBeUndefined();
285
+ } finally {
286
+ enabled.cancelAutoWrapupTimer();
287
+ }
288
+ });
289
+
290
+ it('calls contact.wrapup when the auto wrap-up timer elapses after wrapUpRequired is stamped', async () => {
291
+ const wrapUpProps = {
292
+ autoWrapup: true,
293
+ autoWrapupInterval: 1000,
294
+ wrapUpReasonList: [{id: 'code-1', name: 'Default', isDefault: true, isSystem: false}],
295
+ };
296
+ const contact = {wrapup: jest.fn().mockResolvedValue({result: 'wrap'})};
297
+ const wrappingTask = new DummyTask(
298
+ contact,
299
+ createTaskData({wrapUpRequired: false}) as TaskData,
300
+ {wrapUpProps},
301
+ 'agent-1'
302
+ );
303
+
304
+ jest.useFakeTimers();
305
+ try {
306
+ wrappingTask.updateTaskData(createTaskData({wrapUpRequired: true}) as TaskData);
307
+ expect(wrappingTask.autoWrapup).toBeDefined();
308
+
309
+ jest.advanceTimersByTime(1000);
310
+
311
+ expect(contact.wrapup).toHaveBeenCalledWith({
312
+ interactionId: 'interaction-1',
313
+ data: {wrapUpReason: 'Default', auxCodeId: 'code-1'},
314
+ });
315
+ } finally {
316
+ wrappingTask.cancelAutoWrapupTimer();
317
+ jest.useRealTimers();
318
+ }
319
+ });
320
+
237
321
  it('throws for unsupported voice operations in the base class', async () => {
238
322
  const fullData = createTaskData();
239
323
  const voiceTask = new DummyTask(dummyContact, fullData);
@@ -246,6 +330,7 @@ describe('Task (base class)', () => {
246
330
  () => voiceTask.endConsult({} as any),
247
331
  () => voiceTask.consultTransfer({} as any),
248
332
  () => voiceTask.consultConference(),
333
+ () => voiceTask.dropConferenceParticipant({participantId: 'participant-id'}),
249
334
  () => voiceTask.exitConference(),
250
335
  () => voiceTask.transferConference(),
251
336
  () => voiceTask.toggleMute(),
@@ -273,6 +358,171 @@ describe('Task (base class)', () => {
273
358
  expect((voiceTask.data as any).foo).toBe('new');
274
359
  });
275
360
 
361
+ it('syncs owner changes and emits task:hydrate without changing task state', () => {
362
+ const originalData = createTaskData({
363
+ interaction: {owner: 'agent-1'} as any,
364
+ });
365
+ const voiceTask = new DummyTask(dummyContact, originalData);
366
+ const hydrateHandler = jest.fn();
367
+
368
+ voiceTask.stateMachineService?.send({
369
+ type: TaskEvent.TASK_INCOMING,
370
+ taskData: originalData,
371
+ });
372
+ voiceTask.stateMachineService?.send({type: TaskEvent.ASSIGN, taskData: originalData});
373
+ const stateBeforeOwnerChange = voiceTask.stateMachineService?.getSnapshot().value;
374
+ voiceTask.on(TASK_EVENTS.TASK_HYDRATE, hydrateHandler);
375
+
376
+ const updatedData = createTaskData({
377
+ interaction: {owner: 'agent-2'} as any,
378
+ });
379
+ voiceTask.sendStateMachineEvent({
380
+ type: TaskEvent.CONTACT_OWNER_CHANGED,
381
+ taskData: updatedData,
382
+ });
383
+
384
+ expect(voiceTask.data.interaction.owner).toBe('agent-2');
385
+ expect(hydrateHandler).toHaveBeenCalledWith(voiceTask);
386
+ expect(voiceTask.stateMachineService?.getSnapshot().value).toBe(stateBeforeOwnerChange);
387
+ });
388
+
389
+ it('synchronizes the roster from PARTICIPANT_LEAVE without an unrelated state transition', () => {
390
+ const conferenceData = createTaskData({
391
+ agentId: 'agent-1',
392
+ interactionId: 'interaction-1',
393
+ interaction: {
394
+ state: 'conference',
395
+ owner: 'agent-1',
396
+ interactionId: 'interaction-1',
397
+ mainInteractionId: 'interaction-1',
398
+ participants: {
399
+ 'agent-1': {id: 'agent-1', pType: 'Agent', hasLeft: false},
400
+ 'agent-2': {id: 'agent-2', pType: 'Agent', hasLeft: false},
401
+ 'agent-3': {id: 'agent-3', pType: 'Agent', hasLeft: false},
402
+ customer: {id: 'customer', pType: 'Customer', hasLeft: false},
403
+ },
404
+ media: {
405
+ 'interaction-1': {
406
+ mediaResourceId: 'interaction-1',
407
+ mType: 'mainCall',
408
+ participants: ['agent-1', 'agent-2', 'agent-3', 'customer'],
409
+ isHold: false,
410
+ },
411
+ },
412
+ } as any,
413
+ });
414
+ const voiceTask = new ConferenceTask(dummyContact, conferenceData);
415
+ const participantLeftHandler = jest.fn();
416
+
417
+ voiceTask.sendStateMachineEvent({type: TaskEvent.TASK_INCOMING, taskData: conferenceData});
418
+ voiceTask.sendStateMachineEvent({type: TaskEvent.ASSIGN, taskData: conferenceData});
419
+ voiceTask.sendStateMachineEvent({type: TaskEvent.CONFERENCE_START, taskData: conferenceData});
420
+ const conferenceState = voiceTask.stateMachineService?.getSnapshot().value;
421
+ voiceTask.on(TASK_EVENTS.TASK_PARTICIPANT_LEFT, participantLeftHandler);
422
+
423
+ const updatedData = createTaskData({
424
+ ...conferenceData,
425
+ participantId: 'agent-2',
426
+ interaction: {
427
+ ...conferenceData.interaction,
428
+ participants: {
429
+ 'agent-1': {id: 'agent-1', pType: 'Agent', hasLeft: false},
430
+ 'agent-3': {id: 'agent-3', pType: 'Agent', hasLeft: false},
431
+ customer: {id: 'customer', pType: 'Customer', hasLeft: false},
432
+ },
433
+ media: {
434
+ 'interaction-1': {
435
+ ...conferenceData.interaction.media['interaction-1'],
436
+ participants: ['agent-1', 'agent-3', 'customer'],
437
+ },
438
+ },
439
+ } as any,
440
+ });
441
+
442
+ voiceTask.sendStateMachineEvent({
443
+ type: TaskEvent.PARTICIPANT_LEAVE,
444
+ taskData: updatedData,
445
+ participantId: 'agent-2',
446
+ });
447
+
448
+ expect(voiceTask.data.interaction.participants['agent-2']).toBeUndefined();
449
+ expect(participantLeftHandler).toHaveBeenCalledWith(voiceTask);
450
+ expect(voiceTask.stateMachineService?.getSnapshot().value).toBe(conferenceState);
451
+ });
452
+
453
+ it('keeps the conference participant controls after the customer leaves', () => {
454
+ const conferenceData = createTaskData({
455
+ agentId: 'agent-1',
456
+ interactionId: 'interaction-1',
457
+ isConferenceInProgress: true,
458
+ isConferencing: true,
459
+ interaction: {
460
+ state: 'conference',
461
+ mediaType: 'telephony',
462
+ owner: 'agent-1',
463
+ interactionId: 'interaction-1',
464
+ mainInteractionId: 'interaction-1',
465
+ callProcessingDetails: {isConferencing: true},
466
+ participants: {
467
+ 'agent-1': {id: 'agent-1', pType: 'Agent', hasLeft: false},
468
+ 'agent-2': {id: 'agent-2', pType: 'Agent', hasLeft: false},
469
+ customer: {id: 'customer', pType: 'Customer', hasLeft: false},
470
+ },
471
+ media: {
472
+ 'interaction-1': {
473
+ mediaResourceId: 'interaction-1',
474
+ mType: 'mainCall',
475
+ participants: ['agent-1', 'agent-2', 'customer'],
476
+ isHold: false,
477
+ },
478
+ },
479
+ } as any,
480
+ });
481
+ const voiceTask = new ConferenceTask(dummyContact, conferenceData);
482
+ const participantLeftHandler = jest.fn();
483
+ const conferenceEndedHandler = jest.fn();
484
+
485
+ voiceTask.sendStateMachineEvent({type: TaskEvent.TASK_INCOMING, taskData: conferenceData});
486
+ voiceTask.sendStateMachineEvent({type: TaskEvent.ASSIGN, taskData: conferenceData});
487
+ voiceTask.sendStateMachineEvent({type: TaskEvent.CONFERENCE_START, taskData: conferenceData});
488
+ voiceTask.on(TASK_EVENTS.TASK_PARTICIPANT_LEFT, participantLeftHandler);
489
+ voiceTask.on(TASK_EVENTS.TASK_CONFERENCE_ENDED, conferenceEndedHandler);
490
+
491
+ const customerLeftData = createTaskData({
492
+ ...conferenceData,
493
+ participantId: 'customer',
494
+ interaction: {
495
+ ...conferenceData.interaction,
496
+ participants: {
497
+ 'agent-1': {id: 'agent-1', pType: 'Agent', hasLeft: false},
498
+ 'agent-2': {id: 'agent-2', pType: 'Agent', hasLeft: false},
499
+ },
500
+ media: {
501
+ 'interaction-1': {
502
+ ...conferenceData.interaction.media['interaction-1'],
503
+ participants: ['agent-1', 'agent-2'],
504
+ },
505
+ },
506
+ } as any,
507
+ });
508
+
509
+ voiceTask.sendStateMachineEvent({
510
+ type: TaskEvent.PARTICIPANT_LEAVE,
511
+ taskData: customerLeftData,
512
+ participantId: 'customer',
513
+ });
514
+
515
+ expect(voiceTask.data.interaction.participants.customer).toBeUndefined();
516
+ expect(voiceTask.data.interaction.participants['agent-2']).toBeDefined();
517
+ expect(voiceTask.stateMachineService?.getSnapshot().value).toBe('CONFERENCING');
518
+ expect(voiceTask.uiControls.main.exitConference).toEqual({
519
+ isVisible: true,
520
+ isEnabled: true,
521
+ });
522
+ expect(participantLeftHandler).toHaveBeenCalledWith(voiceTask);
523
+ expect(conferenceEndedHandler).not.toHaveBeenCalled();
524
+ });
525
+
276
526
  it('stopStateMachine clears state snapshot access', () => {
277
527
  const fullData = createTaskData();
278
528
  const voiceTask = new DummyTask(dummyContact, fullData);
@@ -398,6 +648,24 @@ describe('Task common methods', () => {
398
648
  expect(result).toEqual({result: 'vt'});
399
649
  });
400
650
 
651
+ it('transfer uses vteamTransfer with the backend destination type for entry-point destinations', async () => {
652
+ const payload: TransferPayLoad = {
653
+ to: 'entry-point-1',
654
+ destinationType: DESTINATION_TYPE.ENTRYPOINT,
655
+ };
656
+ const result = await task.transfer(payload);
657
+
658
+ expect(contact.vteamTransfer).toHaveBeenCalledWith({
659
+ interactionId: taskData.interactionId,
660
+ data: {
661
+ to: payload.to,
662
+ destinationType: ENTRY_POINT_TRANSFER_DESTINATION_TYPE,
663
+ },
664
+ });
665
+ expect(contact.blindTransfer).not.toHaveBeenCalled();
666
+ expect(result).toEqual({result: 'vt'});
667
+ });
668
+
401
669
  it('end invokes contact.end and returns its response', async () => {
402
670
  const result = await task.end();
403
671
  expect(contact.end).toHaveBeenCalledWith({
@@ -1,6 +1,10 @@
1
1
  import 'jsdom-global/register';
2
2
  import TaskFactory from '../../../../../src/services/task/TaskFactory';
3
- import {MEDIA_CHANNEL, TaskData} from '../../../../../src/services/task/types';
3
+ import {
4
+ CONSULT_TRANSFER_DESTINATION_TYPE,
5
+ MEDIA_CHANNEL,
6
+ TaskData,
7
+ } from '../../../../../src/services/task/types';
4
8
  import {LoginOption} from '../../../../../src/types';
5
9
  import WebCallingService from '../../../../../src/services/WebCallingService';
6
10
  import {ConfigFlags} from '../../../../../src/types';
@@ -18,7 +22,7 @@ describe('TaskFactory', () => {
18
22
  loginOption,
19
23
  on: jest.fn(),
20
24
  off: jest.fn?.(),
21
- } as unknown) as WebCallingService;
25
+ } as unknown as WebCallingService);
22
26
 
23
27
  const configFlags: ConfigFlags = {
24
28
  isEndTaskEnabled: true,
@@ -59,4 +63,37 @@ describe('TaskFactory', () => {
59
63
  const t2 = TaskFactory.createTask(dummyContact, svcExt, data, configFlags);
60
64
  expect(t2.constructor.name).toBe('Voice');
61
65
  });
66
+
67
+ it('passes consult/transfer destination policy into created tasks', () => {
68
+ const svc = makeSvc(LoginOption.EXTENSION);
69
+ const data = {
70
+ ...baseData,
71
+ interaction: {
72
+ mediaType: MEDIA_CHANNEL.TELEPHONY,
73
+ contactDirection: {type: 'INBOUND'},
74
+ },
75
+ } as TaskData;
76
+ const task = TaskFactory.createTask(dummyContact, svc, data, {
77
+ ...configFlags,
78
+ consultTransfer: {
79
+ allowConsultToQueue: true,
80
+ accessQueue: 'ALL',
81
+ accessEntryPoint: 'NONE',
82
+ accessBuddyTeam: 'ALL',
83
+ },
84
+ });
85
+
86
+ expect(task.uiControls.consultTransferDestinations).toEqual({
87
+ consult: [
88
+ CONSULT_TRANSFER_DESTINATION_TYPE.AGENT,
89
+ CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE,
90
+ CONSULT_TRANSFER_DESTINATION_TYPE.DIALNUMBER,
91
+ ],
92
+ transfer: [
93
+ CONSULT_TRANSFER_DESTINATION_TYPE.AGENT,
94
+ CONSULT_TRANSFER_DESTINATION_TYPE.QUEUE,
95
+ CONSULT_TRANSFER_DESTINATION_TYPE.DIALNUMBER,
96
+ ],
97
+ });
98
+ });
62
99
  });