@webex/contact-center 3.12.0-webex-services-ready.4 → 3.13.0

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 (250) hide show
  1. package/.sdd/manifest.json +24 -13
  2. package/ai-docs/ARCHITECTURE.md +1 -1
  3. package/ai-docs/CONTRACTS.md +19 -3
  4. package/ai-docs/SECURITY.md +1 -1
  5. package/ai-docs/SERVICE_STATE.md +4 -0
  6. package/ai-docs/contact-center-spec.md +50 -6
  7. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  8. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  9. package/dist/cc.js +757 -22
  10. package/dist/cc.js.map +1 -1
  11. package/dist/config.js +7 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/constants.js +23 -2
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.js +34 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/metrics/MetricsManager.js +16 -0
  18. package/dist/metrics/MetricsManager.js.map +1 -1
  19. package/dist/metrics/behavioral-events.js +110 -0
  20. package/dist/metrics/behavioral-events.js.map +1 -1
  21. package/dist/metrics/constants.js +33 -0
  22. package/dist/metrics/constants.js.map +1 -1
  23. package/dist/services/AddressBook.js +18 -15
  24. package/dist/services/AddressBook.js.map +1 -1
  25. package/dist/services/AnswerCallOnWebexService.js +202 -0
  26. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  27. package/dist/services/ApiAiAssistant.js +221 -11
  28. package/dist/services/ApiAiAssistant.js.map +1 -1
  29. package/dist/services/EntryPoint.js +46 -68
  30. package/dist/services/EntryPoint.js.map +1 -1
  31. package/dist/services/Queue.js +27 -22
  32. package/dist/services/Queue.js.map +1 -1
  33. package/dist/services/WebCallingService.js +10 -2
  34. package/dist/services/WebCallingService.js.map +1 -1
  35. package/dist/services/WebexCrossClientService.js +225 -0
  36. package/dist/services/WebexCrossClientService.js.map +1 -0
  37. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  38. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  39. package/dist/services/config/Util.js +46 -46
  40. package/dist/services/config/Util.js.map +1 -1
  41. package/dist/services/config/constants.js +34 -77
  42. package/dist/services/config/constants.js.map +1 -1
  43. package/dist/services/config/index.js +100 -226
  44. package/dist/services/config/index.js.map +1 -1
  45. package/dist/services/config/types.js +51 -18
  46. package/dist/services/config/types.js.map +1 -1
  47. package/dist/services/constants.js +11 -1
  48. package/dist/services/constants.js.map +1 -1
  49. package/dist/services/core/Err.js.map +1 -1
  50. package/dist/services/core/Utils.js +25 -1
  51. package/dist/services/core/Utils.js.map +1 -1
  52. package/dist/services/core/WebexRequest.js +6 -2
  53. package/dist/services/core/WebexRequest.js.map +1 -1
  54. package/dist/services/core/aqm-reqs.js +17 -11
  55. package/dist/services/core/aqm-reqs.js.map +1 -1
  56. package/dist/services/core/constants.js +9 -1
  57. package/dist/services/core/constants.js.map +1 -1
  58. package/dist/services/core/types.js.map +1 -1
  59. package/dist/services/core/websocket/WebSocketManager.js +17 -1
  60. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  61. package/dist/services/task/Task.js +275 -8
  62. package/dist/services/task/Task.js.map +1 -1
  63. package/dist/services/task/TaskFactory.js +11 -6
  64. package/dist/services/task/TaskFactory.js.map +1 -1
  65. package/dist/services/task/TaskManager.js +590 -42
  66. package/dist/services/task/TaskManager.js.map +1 -1
  67. package/dist/services/task/TaskUtils.js +11 -1
  68. package/dist/services/task/TaskUtils.js.map +1 -1
  69. package/dist/services/task/WebexCallingUtils.js +70 -0
  70. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  71. package/dist/services/task/constants.js +14 -2
  72. package/dist/services/task/constants.js.map +1 -1
  73. package/dist/services/task/contact.js +29 -0
  74. package/dist/services/task/contact.js.map +1 -1
  75. package/dist/services/task/digital/Digital.js +4 -3
  76. package/dist/services/task/digital/Digital.js.map +1 -1
  77. package/dist/services/task/state-machine/TaskStateMachine.js +162 -53
  78. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -1
  79. package/dist/services/task/state-machine/actions.js +6 -1
  80. package/dist/services/task/state-machine/actions.js.map +1 -1
  81. package/dist/services/task/state-machine/guards.js +7 -10
  82. package/dist/services/task/state-machine/guards.js.map +1 -1
  83. package/dist/services/task/state-machine/types.js.map +1 -1
  84. package/dist/services/task/state-machine/uiControlsComputer.js +118 -18
  85. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -1
  86. package/dist/services/task/types.js +47 -1
  87. package/dist/services/task/types.js.map +1 -1
  88. package/dist/services/task/voice/Voice.js +477 -17
  89. package/dist/services/task/voice/Voice.js.map +1 -1
  90. package/dist/services/task/voice/WebRTC.js +6 -3
  91. package/dist/services/task/voice/WebRTC.js.map +1 -1
  92. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  93. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  94. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  95. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  96. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  97. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  98. package/dist/services/wxAppTelephonyUtils.js +19 -0
  99. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  100. package/dist/types/cc.d.ts +102 -8
  101. package/dist/types/config.d.ts +7 -0
  102. package/dist/types/constants.d.ts +21 -0
  103. package/dist/types/index.d.ts +34 -15
  104. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  105. package/dist/types/metrics/constants.d.ts +31 -0
  106. package/dist/types/services/AddressBook.d.ts +2 -1
  107. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  108. package/dist/types/services/ApiAiAssistant.d.ts +48 -4
  109. package/dist/types/services/EntryPoint.d.ts +7 -5
  110. package/dist/types/services/Queue.d.ts +5 -3
  111. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  112. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  113. package/dist/types/services/config/Util.d.ts +4 -8
  114. package/dist/types/services/config/constants.d.ts +28 -76
  115. package/dist/types/services/config/index.d.ts +16 -64
  116. package/dist/types/services/config/types.d.ts +146 -173
  117. package/dist/types/services/constants.d.ts +9 -0
  118. package/dist/types/services/core/Err.d.ts +2 -0
  119. package/dist/types/services/core/Utils.d.ts +10 -0
  120. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  121. package/dist/types/services/core/constants.d.ts +7 -0
  122. package/dist/types/services/core/types.d.ts +2 -0
  123. package/dist/types/services/task/Task.d.ts +34 -5
  124. package/dist/types/services/task/TaskFactory.d.ts +4 -2
  125. package/dist/types/services/task/TaskUtils.d.ts +6 -0
  126. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  127. package/dist/types/services/task/constants.d.ts +12 -0
  128. package/dist/types/services/task/contact.d.ts +4 -0
  129. package/dist/types/services/task/digital/Digital.d.ts +4 -3
  130. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +304 -56
  131. package/dist/types/services/task/state-machine/guards.d.ts +6 -5
  132. package/dist/types/services/task/state-machine/types.d.ts +9 -1
  133. package/dist/types/services/task/types.d.ts +192 -5
  134. package/dist/types/services/task/voice/Voice.d.ts +68 -11
  135. package/dist/types/services/task/voice/WebRTC.d.ts +5 -4
  136. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  137. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  138. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  139. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  140. package/dist/types/types.d.ts +80 -13
  141. package/dist/types/utils/PageCache.d.ts +20 -3
  142. package/dist/types.js +54 -8
  143. package/dist/types.js.map +1 -1
  144. package/dist/utils/PageCache.js +19 -5
  145. package/dist/utils/PageCache.js.map +1 -1
  146. package/dist/webex.js +9 -1
  147. package/dist/webex.js.map +1 -1
  148. package/package.json +10 -9
  149. package/src/cc.ts +969 -38
  150. package/src/config.ts +7 -0
  151. package/src/constants.ts +24 -0
  152. package/src/index.ts +39 -10
  153. package/src/metrics/MetricsManager.ts +16 -0
  154. package/src/metrics/ai-docs/metrics-spec.md +138 -21
  155. package/src/metrics/behavioral-events.ts +112 -0
  156. package/src/metrics/constants.ts +36 -0
  157. package/src/services/AddressBook.ts +17 -6
  158. package/src/services/AnswerCallOnWebexService.ts +239 -0
  159. package/src/services/ApiAiAssistant.ts +297 -13
  160. package/src/services/EntryPoint.ts +59 -60
  161. package/src/services/Queue.ts +29 -12
  162. package/src/services/WebCallingService.ts +16 -2
  163. package/src/services/WebexCrossClientService.ts +298 -0
  164. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  165. package/src/services/agent/ai-docs/AGENTS.md +1 -1
  166. package/src/services/agent/ai-docs/agent-spec.md +1 -0
  167. package/src/services/ai-docs/AGENTS.md +10 -10
  168. package/src/services/ai-docs/services-spec.md +25 -5
  169. package/src/services/config/Util.ts +52 -82
  170. package/src/services/config/ai-docs/AGENTS.md +35 -40
  171. package/src/services/config/ai-docs/ARCHITECTURE.md +90 -103
  172. package/src/services/config/ai-docs/config-spec.md +132 -132
  173. package/src/services/config/constants.ts +39 -85
  174. package/src/services/config/index.ts +116 -277
  175. package/src/services/config/types.ts +140 -195
  176. package/src/services/constants.ts +10 -0
  177. package/src/services/core/Err.ts +1 -0
  178. package/src/services/core/Utils.ts +28 -0
  179. package/src/services/core/WebexRequest.ts +3 -1
  180. package/src/services/core/ai-docs/core-spec.md +25 -11
  181. package/src/services/core/aqm-reqs.ts +18 -12
  182. package/src/services/core/constants.ts +8 -0
  183. package/src/services/core/types.ts +33 -1
  184. package/src/services/core/websocket/WebSocketManager.ts +26 -2
  185. package/src/services/task/Task.ts +386 -12
  186. package/src/services/task/TaskFactory.ts +33 -6
  187. package/src/services/task/TaskManager.ts +857 -41
  188. package/src/services/task/TaskUtils.ts +13 -0
  189. package/src/services/task/WebexCallingUtils.ts +136 -0
  190. package/src/services/task/ai-docs/ARCHITECTURE.md +1 -0
  191. package/src/services/task/ai-docs/task-spec.md +190 -8
  192. package/src/services/task/constants.ts +13 -0
  193. package/src/services/task/contact.ts +30 -0
  194. package/src/services/task/digital/Digital.ts +11 -4
  195. package/src/services/task/state-machine/TaskStateMachine.ts +235 -81
  196. package/src/services/task/state-machine/actions.ts +5 -2
  197. package/src/services/task/state-machine/ai-docs/AGENTS.md +6 -4
  198. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +35 -16
  199. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +103 -33
  200. package/src/services/task/state-machine/guards.ts +7 -10
  201. package/src/services/task/state-machine/types.ts +16 -1
  202. package/src/services/task/state-machine/uiControlsComputer.ts +206 -32
  203. package/src/services/task/types.ts +269 -4
  204. package/src/services/task/voice/Voice.ts +625 -17
  205. package/src/services/task/voice/WebRTC.ts +11 -4
  206. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  207. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  208. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  209. package/src/services/wxAppTelephonyUtils.ts +14 -0
  210. package/src/types.ts +108 -13
  211. package/src/utils/AGENTS.md +21 -10
  212. package/src/utils/PageCache.ts +38 -5
  213. package/src/utils/ai-docs/utils-spec.md +21 -11
  214. package/src/webex.js +8 -0
  215. package/test/unit/fixtures/aiSummaryTestUtils.ts +40 -0
  216. package/test/unit/spec/cc.ts +3408 -152
  217. package/test/unit/spec/index.ts +885 -0
  218. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  219. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  220. package/test/unit/spec/services/AddressBook.ts +37 -6
  221. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  222. package/test/unit/spec/services/ApiAiAssistant.ts +269 -8
  223. package/test/unit/spec/services/EntryPoint.ts +87 -40
  224. package/test/unit/spec/services/Queue.ts +123 -12
  225. package/test/unit/spec/services/WebCallingService.ts +38 -0
  226. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  227. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  228. package/test/unit/spec/services/config/Util.ts +501 -0
  229. package/test/unit/spec/services/config/index.ts +313 -543
  230. package/test/unit/spec/services/core/Utils.ts +22 -0
  231. package/test/unit/spec/services/core/WebexRequest.ts +8 -7
  232. package/test/unit/spec/services/core/aqm-reqs.ts +142 -1
  233. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +64 -14
  234. package/test/unit/spec/services/task/Task.ts +2257 -11
  235. package/test/unit/spec/services/task/TaskFactory.ts +56 -2
  236. package/test/unit/spec/services/task/TaskManager.ts +5559 -1493
  237. package/test/unit/spec/services/task/TaskUtils.ts +72 -0
  238. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  239. package/test/unit/spec/services/task/contact.ts +33 -0
  240. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +1501 -92
  241. package/test/unit/spec/services/task/state-machine/guards.ts +210 -8
  242. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +445 -7
  243. package/test/unit/spec/services/task/voice/Voice.ts +1710 -4
  244. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  245. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  246. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  247. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  248. package/typedoc.md +1 -1
  249. package/umd/contact-center.min.js +2 -2
  250. package/umd/contact-center.min.js.map +1 -1
@@ -12,8 +12,11 @@ import {
12
12
  ResumeRecordingPayload,
13
13
  TaskData,
14
14
  TaskResponse,
15
+ DropConferenceParticipantPayload,
15
16
  IVoice,
16
17
  VoiceUIControlOptions,
18
+ TaskToggleMuteOptions,
19
+ TaskTransmitDtmfOptions,
17
20
  TransferPayLoad,
18
21
  ConsultTransferPayLoad,
19
22
  consultConferencePayloadData,
@@ -25,23 +28,84 @@ import Task from '../Task';
25
28
  import LoggerProxy from '../../../logger-proxy';
26
29
  import MetricsManager from '../../../metrics/MetricsManager';
27
30
  import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
28
- import {TaskState, TaskEvent, TaskActionArgs} from '../state-machine';
29
- import {WrapupData} from '../../config/types';
31
+ import {TaskState, TaskEvent, TaskActionArgs, type TaskContext} from '../state-machine';
32
+ import {shouldWrapUpForThisAgent} from '../state-machine/guards';
33
+ import type {WrapupData} from '../../config/types';
34
+ import type ApiAIAssistant from '../../ApiAiAssistant';
30
35
  import {getConsultMediaResourceId, getIsConferenceInProgress} from '../TaskUtils';
36
+ import AnswerCallOnWebexService from '../../AnswerCallOnWebexService';
37
+ import {isWxAppCallNotFoundError} from '../../wxAppTelephonyUtils';
38
+ import {
39
+ getCallingDeviceDetails,
40
+ getWebexCallingCallId,
41
+ resolveWxAppLineOwnerId,
42
+ isWebexAppCallingOffer as wxIsWebexAppCallingOffer,
43
+ isWebexAppInboundCallingOffer as wxIsWebexAppInboundCallingOffer,
44
+ mapWxAppVoiceError,
45
+ runWxAppAccept,
46
+ runWxAppOutdialDecline,
47
+ runWxAppReject,
48
+ runWxAppToggleMute,
49
+ runWxAppTransmitDtmf,
50
+ WxAppVoiceDependencies,
51
+ WxAppVoiceLifecycle,
52
+ } from './wxAppVoiceMethods';
53
+ import {
54
+ logWxAppMercuryMuteSync,
55
+ callIdSuffix,
56
+ type WxAppAcceptReason,
57
+ } from '../../wxAppDiagnosticLogging';
58
+ import {WxAppOfferObservability, WxAppOfferObservabilityContext} from './wxAppOfferObservability';
59
+
60
+ const hasNonemptyPendingWrapUp = (taskData?: TaskData): boolean =>
61
+ Array.isArray(taskData?.agentsPendingWrapUp) && taskData.agentsPendingWrapUp.length > 0;
62
+
63
+ /**
64
+ * Same consulted-non-owner rule as TaskManager leave stamp. Used only for the
65
+ * HTTP exitConference self-exit fallback (shouldWrapUpForThisAgent stays unchanged).
66
+ */
67
+ const isConsultedNonOwner = (taskData: TaskData, fallback?: TaskData): boolean => {
68
+ const isConsulted = taskData.isConsulted ?? fallback?.isConsulted;
69
+ if (isConsulted !== true) {
70
+ return false;
71
+ }
72
+ const owner = taskData.interaction?.owner ?? fallback?.interaction?.owner;
73
+ const selfAgentId = taskData.agentId ?? fallback?.agentId;
74
+
75
+ return Boolean(selfAgentId && owner && owner !== selfAgentId);
76
+ };
31
77
 
32
78
  export default class Voice extends Task implements IVoice {
79
+ private static readonly WXAPP_MUTE_SYNC_RETRY_DELAY_MS = 50;
80
+ private static readonly WXAPP_MUTE_SYNC_MAX_RETRIES = 3;
81
+
82
+ private answerCallOnWebexService?: AnswerCallOnWebexService;
83
+ private enableWxBetterTogether = false;
84
+ private wxAppMuted = false;
85
+ private wxAppAnswerPending = false;
86
+ private wxAppAcceptInFlight = false;
87
+ private wxAppMuteSyncInFlight?: Promise<boolean | undefined>;
88
+ private wxAppMuteToggleTail: Promise<void> = Promise.resolve();
89
+ private wxAppDtmfTail: Promise<void> = Promise.resolve();
90
+ /** Lazy — `super()` may call `updateUiControls` before field initializers run. */
91
+ private wxAppOfferObservability: WxAppOfferObservability | null = null;
92
+ private getUsersubPublished?: () => boolean;
93
+
33
94
  constructor(
34
95
  contact: ReturnType<typeof routingContact>,
35
96
  data: TaskData,
36
97
  callOptions?: VoiceUIControlOptions,
37
98
  wrapupData?: WrapupData,
38
- agentId?: string
99
+ agentId?: string,
100
+ agentName?: string,
101
+ apiAIAssistant?: ApiAIAssistant
39
102
  ) {
40
103
  const resolvedOptions = {
41
104
  isEndTaskEnabled: callOptions?.isEndTaskEnabled ?? true,
42
105
  isEndConsultEnabled: callOptions?.isEndConsultEnabled ?? true,
43
106
  voiceVariant: callOptions?.voiceVariant ?? VOICE_VARIANT.PSTN,
44
107
  isRecordingEnabled: callOptions?.isRecordingEnabled ?? true,
108
+ enableWxBetterTogether: callOptions?.enableWxBetterTogether ?? false,
45
109
  };
46
110
 
47
111
  super(
@@ -49,34 +113,458 @@ export default class Voice extends Task implements IVoice {
49
113
  data,
50
114
  {
51
115
  ...resolvedOptions,
116
+ consultTransferConfig: callOptions?.consultTransferConfig,
52
117
  },
53
118
  wrapupData,
54
- agentId
119
+ agentId,
120
+ agentName,
121
+ apiAIAssistant
55
122
  );
123
+
124
+ this.enableWxBetterTogether = resolvedOptions.enableWxBetterTogether;
125
+ this.answerCallOnWebexService = callOptions?.answerCallOnWebexService;
126
+ this.getUsersubPublished = callOptions?.getUsersubPublished;
127
+ }
128
+
129
+ private getWxAppVoiceDependencies(): WxAppVoiceDependencies {
130
+ return {
131
+ enableWxBetterTogether: this.enableWxBetterTogether,
132
+ answerCallOnWebexService: this.answerCallOnWebexService,
133
+ agentId: this.agentId,
134
+ metricsManager: this.metricsManager,
135
+ getTaskData: () => this.data,
136
+ getTaskState: () => this.stateMachineService?.getSnapshot?.()?.value as TaskState | undefined,
137
+ getWxAppMuted: () => this.wxAppMuted,
138
+ setWxAppMuted: (muted: boolean) => {
139
+ this.wxAppMuted = muted;
140
+ },
141
+ getUsersubPublished: this.getUsersubPublished,
142
+ };
143
+ }
144
+
145
+ /** @deprecated Use {@link Voice.getWxAppVoiceDependencies} */
146
+ private getWxAppVoiceDeps(): WxAppVoiceDependencies {
147
+ return this.getWxAppVoiceDependencies();
148
+ }
149
+
150
+ public isWebexAppCallingOffer(): boolean {
151
+ return wxIsWebexAppCallingOffer(this.getWxAppVoiceDeps());
152
+ }
153
+
154
+ public isWebexAppInboundCallingOffer(): boolean {
155
+ return wxIsWebexAppInboundCallingOffer(this.getWxAppVoiceDeps());
156
+ }
157
+
158
+ private setWxAppAnswerPending(pending: boolean): void {
159
+ this.wxAppAnswerPending = pending;
160
+ this.uiControlConfig = {...this.uiControlConfig, wxAppAnswerPending: pending};
161
+ this.updateUiControls(true);
162
+ }
163
+
164
+ private setWxAppAcceptInFlight(inFlight: boolean): void {
165
+ this.wxAppAcceptInFlight = inFlight;
166
+ this.uiControlConfig = {...this.uiControlConfig, wxAppAcceptInFlight: inFlight};
167
+ this.updateUiControls(true);
168
+ }
169
+
170
+ public setEnableWxBetterTogether(enabled: boolean): void {
171
+ this.enableWxBetterTogether = enabled;
172
+ this.uiControlConfig = {...this.uiControlConfig, enableWxBetterTogether: enabled};
173
+ this.updateUiControls(true);
174
+ }
175
+
176
+ private getOrCreateWxAppOfferObservability(): WxAppOfferObservability {
177
+ if (!this.wxAppOfferObservability) {
178
+ this.wxAppOfferObservability = new WxAppOfferObservability();
179
+ }
180
+
181
+ return this.wxAppOfferObservability;
182
+ }
183
+
184
+ protected updateUiControls(forceEmit = false): void {
185
+ super.updateUiControls(forceEmit);
186
+ this.getOrCreateWxAppOfferObservability().handleUiControlsUpdate(
187
+ this.getWxAppOfferObservabilityContext()
188
+ );
189
+ }
190
+
191
+ /**
192
+ * Re-run OFFERED wxApp diagnostics without emitting UI controls.
193
+ * Used after usersub publish so a pre-publish offer can schedule mismatch grace.
194
+ */
195
+ public refreshWxAppOfferObservability(): void {
196
+ this.getOrCreateWxAppOfferObservability().handleUiControlsUpdate(
197
+ this.getWxAppOfferObservabilityContext()
198
+ );
199
+ }
200
+
201
+ /**
202
+ * Cancel pending participant-mismatch grace timer. Observability only.
203
+ */
204
+ public disposeWxAppOfferObservability(): void {
205
+ this.wxAppOfferObservability?.dispose();
206
+ }
207
+
208
+ private getWxAppOfferObservabilityContext(): WxAppOfferObservabilityContext {
209
+ return {
210
+ getInteractionId: () => this.data.interactionId,
211
+ getTaskState: () => this.stateMachineService?.getSnapshot?.()?.value as TaskState | undefined,
212
+ getAcceptControl: () => this.currentUiControls?.main?.accept,
213
+ getVoiceVariant: () => this.uiControlConfig.voiceVariant ?? VOICE_VARIANT.PSTN,
214
+ isOutdial: () => this.data?.interaction?.outboundType === 'OUTDIAL',
215
+ isWxAppInboundOffer: () => this.isWebexAppInboundCallingOffer(),
216
+ isWxAppCallingOffer: () => this.isWebexAppCallingOffer(),
217
+ getWxAppAcceptInFlight: () => this.wxAppAcceptInFlight,
218
+ getWxAppAnswerPending: () => this.wxAppAnswerPending,
219
+ getEnableWxBetterTogether: () => this.enableWxBetterTogether,
220
+ getUsersubPublished: () => this.getUsersubPublished?.() ?? false,
221
+ getWxAppVoiceDependencies: () => this.getWxAppVoiceDependencies(),
222
+ getMetricsManager: () => this.metricsManager,
223
+ };
224
+ }
225
+
226
+ public applyWxAppMuteStateFromSync(incomingCallId: string, muted: boolean): void {
227
+ if (!this.enableWxBetterTogether) {
228
+ return;
229
+ }
230
+
231
+ const activeCallId = this.getWebexCallingCallId();
232
+ const incomingSuffix = callIdSuffix(incomingCallId);
233
+ const activeSuffix = callIdSuffix(activeCallId);
234
+
235
+ if (!activeCallId || !incomingCallId.endsWith(activeCallId)) {
236
+ logWxAppMercuryMuteSync({
237
+ phase: 'dropped',
238
+ muted,
239
+ callIdSuffix: incomingSuffix,
240
+ interactionId: this.data.interactionId,
241
+ dropReason: !activeCallId ? 'no_active_wxApp_call' : 'call_id_mismatch',
242
+ });
243
+
244
+ return;
245
+ }
246
+
247
+ if (this.wxAppMuted === muted) {
248
+ logWxAppMercuryMuteSync({
249
+ phase: 'dropped',
250
+ muted,
251
+ callIdSuffix: incomingSuffix,
252
+ interactionId: this.data.interactionId,
253
+ dropReason: 'mute_state_unchanged',
254
+ });
255
+
256
+ return;
257
+ }
258
+
259
+ this.wxAppMuted = muted;
260
+ logWxAppMercuryMuteSync({
261
+ phase: 'applied',
262
+ muted,
263
+ callIdSuffix: activeSuffix,
264
+ interactionId: this.data.interactionId,
265
+ });
266
+ this.emit(TASK_EVENTS.TASK_WXAPP_MUTE_STATE_UPDATED, {muted});
267
+ }
268
+
269
+ public getWxAppMuted(): boolean {
270
+ return this.wxAppMuted;
271
+ }
272
+
273
+ private static delay(ms: number): Promise<void> {
274
+ return new Promise((resolve) => {
275
+ setTimeout(resolve, ms);
276
+ });
277
+ }
278
+
279
+ private canRetryWxAppMuteSync(): boolean {
280
+ if (!this.enableWxBetterTogether) {
281
+ return false;
282
+ }
283
+
284
+ return (
285
+ Boolean(getCallingDeviceDetails(this.getWxAppVoiceDeps())?.deviceCallId) &&
286
+ !this.getWebexCallingCallId()
287
+ );
288
+ }
289
+
290
+ private shouldSkipWxAppMuteSync(): boolean {
291
+ if (this.data?.interaction?.isTerminated) {
292
+ return true;
293
+ }
294
+
295
+ return this.isWebexAppCallingOffer() && !this.uiControlConfig?.wxAppAnswerPending;
296
+ }
297
+
298
+ private applyWxAppMuteFromBackfill(callId: string, muted: boolean): void {
299
+ if (!this.enableWxBetterTogether || this.wxAppMuted === muted) {
300
+ return;
301
+ }
302
+
303
+ const activeCallId = this.getWebexCallingCallId();
304
+ if (activeCallId && !callId.endsWith(activeCallId) && !activeCallId.endsWith(callId)) {
305
+ return;
306
+ }
307
+
308
+ this.wxAppMuted = muted;
309
+ this.emit(TASK_EVENTS.TASK_WXAPP_MUTE_STATE_UPDATED, {muted});
310
+ }
311
+
312
+ public async syncWxAppMuteFromCallDetails(retryAttempt = 0): Promise<boolean | undefined> {
313
+ if (!this.enableWxBetterTogether || !this.answerCallOnWebexService) {
314
+ return undefined;
315
+ }
316
+
317
+ if (retryAttempt === 0 && this.shouldSkipWxAppMuteSync()) {
318
+ return undefined;
319
+ }
320
+
321
+ if (retryAttempt === 0 && this.wxAppMuteSyncInFlight) {
322
+ return this.wxAppMuteSyncInFlight;
323
+ }
324
+
325
+ const syncPromise = this.performWxAppMuteSync(retryAttempt);
326
+
327
+ if (retryAttempt === 0) {
328
+ this.wxAppMuteSyncInFlight = syncPromise;
329
+ syncPromise
330
+ .finally(() => {
331
+ if (this.wxAppMuteSyncInFlight === syncPromise) {
332
+ this.wxAppMuteSyncInFlight = undefined;
333
+ }
334
+ })
335
+ .catch(() => undefined);
336
+
337
+ return syncPromise;
338
+ }
339
+
340
+ return syncPromise;
341
+ }
342
+
343
+ private async performWxAppMuteSync(retryAttempt: number): Promise<boolean | undefined> {
344
+ if (this.shouldSkipWxAppMuteSync()) {
345
+ return undefined;
346
+ }
347
+
348
+ let callId = this.getWebexCallingCallId();
349
+ if (!callId) {
350
+ if (retryAttempt < Voice.WXAPP_MUTE_SYNC_MAX_RETRIES && this.canRetryWxAppMuteSync()) {
351
+ await Voice.delay(Voice.WXAPP_MUTE_SYNC_RETRY_DELAY_MS);
352
+
353
+ return this.performWxAppMuteSync(retryAttempt + 1);
354
+ }
355
+
356
+ callId = getCallingDeviceDetails(this.getWxAppVoiceDeps())?.deviceCallId ?? null;
357
+ if (!callId) {
358
+ return undefined;
359
+ }
360
+ }
361
+
362
+ try {
363
+ const lineOwnerId = resolveWxAppLineOwnerId(this.getWxAppVoiceDeps());
364
+ const details = await this.answerCallOnWebexService.getCallDetails({callId, lineOwnerId});
365
+ if (details.muted !== undefined) {
366
+ this.applyWxAppMuteStateFromSync(callId, details.muted);
367
+ if (this.wxAppMuted !== details.muted) {
368
+ this.applyWxAppMuteFromBackfill(callId, details.muted);
369
+ }
370
+
371
+ return details.muted;
372
+ }
373
+
374
+ return this.wxAppMuted;
375
+ } catch (error) {
376
+ if (!isWxAppCallNotFoundError(error)) {
377
+ LoggerProxy.error(`Failed to sync wxApp mute from call details: ${error}`, {
378
+ module: CC_FILE,
379
+ method: METHODS.GET_CALL_DETAILS_ON_WEBEX,
380
+ interactionId: this.data?.interactionId,
381
+ });
382
+ }
383
+
384
+ return undefined;
385
+ }
386
+ }
387
+
388
+ protected onTaskAssigned(): void {
389
+ this.setWxAppAnswerPending(false);
390
+ queueMicrotask(() => {
391
+ this.syncWxAppMuteFromCallDetails().catch(() => undefined);
392
+ });
393
+ }
394
+
395
+ protected onTaskHydrated(): void {
396
+ const state = this.stateMachineService?.getSnapshot?.()?.value as TaskState | undefined;
397
+ const answerStillPending =
398
+ state === TaskState.OFFERED &&
399
+ (this.uiControlConfig?.wxAppAcceptInFlight || this.uiControlConfig?.wxAppAnswerPending);
400
+
401
+ if (!answerStillPending) {
402
+ this.setWxAppAnswerPending(false);
403
+ }
404
+
405
+ this.syncWxAppMuteFromCallDetails().catch(() => undefined);
406
+ }
407
+
408
+ public getCallingDeviceDetails() {
409
+ return getCallingDeviceDetails(this.getWxAppVoiceDeps());
410
+ }
411
+
412
+ public getWebexCallingCallId(): string | null {
413
+ return getWebexCallingCallId(this.getWxAppVoiceDeps());
414
+ }
415
+
416
+ private createWxAppLifecycle(): WxAppVoiceLifecycle {
417
+ return {
418
+ setWxAppAcceptInFlight: (inFlight) => this.setWxAppAcceptInFlight(inFlight),
419
+ setWxAppAnswerPending: (pending) => this.setWxAppAnswerPending(pending),
420
+ resetWxAppMuted: () => {
421
+ this.wxAppMuted = false;
422
+ },
423
+ syncWxAppMuteFromCallDetails: () => this.syncWxAppMuteFromCallDetails(),
424
+ mapWxAppVoiceError: (error, method) => mapWxAppVoiceError(error, method, CC_FILE),
425
+ };
56
426
  }
57
427
 
58
428
  private getStateMachineSnapshot() {
59
429
  return this.stateMachineService?.getSnapshot?.();
60
430
  }
61
431
 
432
+ private getWxAppAcceptReasonForMetrics(): WxAppAcceptReason {
433
+ if (this.wxAppAcceptInFlight) {
434
+ return 'wxApp_accept_in_flight';
435
+ }
436
+
437
+ if (this.wxAppAnswerPending) {
438
+ return 'wxApp_answer_pending';
439
+ }
440
+
441
+ return 'wxApp_offer_ready';
442
+ }
443
+
62
444
  /**
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
445
+ * Accepts the task. Routes to wxApp telephony answer when `enableWxBetterTogether` and wxApp offer.
67
446
  */
68
447
  public async accept(): Promise<TaskResponse> {
69
- super.unsupportedMethodError(METHODS.ACCEPT);
448
+ if (this.enableWxBetterTogether && this.isWebexAppCallingOffer()) {
449
+ await runWxAppAccept(this.getWxAppVoiceDependencies(), this.createWxAppLifecycle(), {
450
+ acceptReason: this.getWxAppAcceptReasonForMetrics(),
451
+ });
452
+
453
+ return Promise.resolve();
454
+ }
455
+
456
+ return super.unsupportedMethodError(METHODS.ACCEPT);
70
457
  }
71
458
 
72
459
  /**
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
460
+ * Declines the task. Routes wxApp inbound to telephony reject; wxApp outdial offer to cancelTask.
77
461
  */
78
462
  public async decline(): Promise<TaskResponse> {
79
- super.unsupportedMethodError(METHODS.REJECT);
463
+ if (this.enableWxBetterTogether && this.isWebexAppInboundCallingOffer()) {
464
+ await runWxAppReject(this.getWxAppVoiceDependencies(), this.createWxAppLifecycle(), {
465
+ acceptReason: this.getWxAppAcceptReasonForMetrics(),
466
+ });
467
+
468
+ return Promise.resolve();
469
+ }
470
+
471
+ const isOutdial = this.data?.interaction?.outboundType === 'OUTDIAL';
472
+ if (!this.enableWxBetterTogether || !isOutdial || !this.isWebexAppCallingOffer()) {
473
+ return super.unsupportedMethodError(METHODS.REJECT);
474
+ }
475
+
476
+ const interactionId = this.data.interactionId;
477
+ LoggerProxy.log(`Declining wxApp outdial task for taskId:${interactionId}`, {
478
+ module: CC_FILE,
479
+ method: METHODS.REJECT,
480
+ interactionId,
481
+ });
482
+
483
+ try {
484
+ this.metricsManager.timeEvent([
485
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
486
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
487
+ ]);
488
+
489
+ const declineAcceptReason = this.wxAppAnswerPending
490
+ ? 'wxApp_answer_pending'
491
+ : 'wxApp_offer_ready';
492
+ this.setWxAppAnswerPending(false);
493
+ const response = await runWxAppOutdialDecline(
494
+ this.getWxAppVoiceDependencies(),
495
+ () => this.contact.cancelTask({interactionId}),
496
+ {acceptReason: declineAcceptReason}
497
+ );
498
+
499
+ this.metricsManager.trackEvent(
500
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
501
+ {
502
+ taskId: interactionId,
503
+ ...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
504
+ },
505
+ ['operational', 'behavioral']
506
+ );
507
+
508
+ return response;
509
+ } catch (error) {
510
+ this.metricsManager.trackEvent(
511
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
512
+ {
513
+ taskId: interactionId,
514
+ error: error.toString(),
515
+ ...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
516
+ (error as any).details || {}
517
+ ),
518
+ },
519
+ ['operational', 'behavioral']
520
+ );
521
+ const {error: detailedError} = getErrorDetails(error, METHODS.REJECT, CC_FILE);
522
+ throw detailedError;
523
+ }
524
+ }
525
+
526
+ /**
527
+ * Toggles mute for wxApp engaged telephony when `enableWxBetterTogether` is active.
528
+ */
529
+ public async toggleMute(options?: TaskToggleMuteOptions): Promise<void> {
530
+ if (this.enableWxBetterTogether && this.getWebexCallingCallId()) {
531
+ const togglePromise = this.wxAppMuteToggleTail
532
+ .catch(() => undefined)
533
+ .then(() =>
534
+ runWxAppToggleMute(this.getWxAppVoiceDependencies(), this.createWxAppLifecycle(), options)
535
+ );
536
+
537
+ this.wxAppMuteToggleTail = togglePromise.catch(() => undefined);
538
+ await togglePromise;
539
+
540
+ return;
541
+ }
542
+
543
+ super.unsupportedMethodError(METHODS.TOGGLE_MUTE);
544
+ }
545
+
546
+ /**
547
+ * Sends in-call DTMF for wxApp engaged telephony when `enableWxBetterTogether` is active.
548
+ */
549
+ public async transmitDtmf(options: TaskTransmitDtmfOptions): Promise<void> {
550
+ if (this.enableWxBetterTogether && this.getWebexCallingCallId()) {
551
+ const dtmfPromise = this.wxAppDtmfTail
552
+ .catch(() => undefined)
553
+ .then(() =>
554
+ runWxAppTransmitDtmf(
555
+ this.getWxAppVoiceDependencies(),
556
+ this.createWxAppLifecycle(),
557
+ options
558
+ )
559
+ );
560
+
561
+ this.wxAppDtmfTail = dtmfPromise.catch(() => undefined);
562
+ await dtmfPromise;
563
+
564
+ return;
565
+ }
566
+
567
+ super.unsupportedMethodError(METHODS.TRANSMIT_DTMF);
80
568
  }
81
569
 
82
570
  /**
@@ -827,6 +1315,99 @@ export default class Voice extends Task implements IVoice {
827
1315
  }
828
1316
  }
829
1317
 
1318
+ /**
1319
+ * Removes another participant from an active conference.
1320
+ * Completion is correlated with ParticipantLeftConference by the AQM request layer.
1321
+ * @param payload - Participant identifier to remove
1322
+ * @returns Promise<TaskResponse>
1323
+ */
1324
+ public async dropConferenceParticipant(
1325
+ payload: DropConferenceParticipantPayload
1326
+ ): Promise<TaskResponse> {
1327
+ // The TypeScript contract requires payload, but the published SDK is also callable from
1328
+ // untyped JavaScript. Keep an explicit runtime boundary check before direct property access.
1329
+ if (!payload) {
1330
+ throw new Error('participantId must be a non-empty string');
1331
+ }
1332
+
1333
+ const {participantId} = payload;
1334
+
1335
+ if (typeof participantId !== 'string' || participantId.trim().length === 0) {
1336
+ throw new Error('participantId must be a non-empty string');
1337
+ }
1338
+
1339
+ const requestInteractionId =
1340
+ this.data.interaction?.mainInteractionId || this.data.interactionId;
1341
+ // taskId identifies the SDK task instance, which can remain child-interaction keyed after
1342
+ // consult/EP-DN flows. requestInteractionId identifies the main interaction sent to AQM.
1343
+
1344
+ LoggerProxy.info('Dropping conference participant', {
1345
+ module: CC_FILE,
1346
+ method: METHODS.DROP_CONFERENCE_PARTICIPANT,
1347
+ interactionId: requestInteractionId,
1348
+ });
1349
+
1350
+ try {
1351
+ this.metricsManager.timeEvent([
1352
+ METRIC_EVENT_NAMES.TASK_CONFERENCE_PARTICIPANT_DROP_SUCCESS,
1353
+ METRIC_EVENT_NAMES.TASK_CONFERENCE_PARTICIPANT_DROP_FAILED,
1354
+ ]);
1355
+
1356
+ const response = await this.contact.dropConferenceParticipant({
1357
+ interactionId: requestInteractionId,
1358
+ participantId,
1359
+ });
1360
+
1361
+ this.metricsManager.trackEvent(
1362
+ METRIC_EVENT_NAMES.TASK_CONFERENCE_PARTICIPANT_DROP_SUCCESS,
1363
+ {
1364
+ taskId: this.data.interactionId,
1365
+ requestInteractionId,
1366
+ ...MetricsManager.getCommonTrackingFieldForAQMResponse(response),
1367
+ agentId: this.agentId,
1368
+ },
1369
+ ['operational', 'behavioral', 'business']
1370
+ );
1371
+
1372
+ LoggerProxy.log('Successfully dropped conference participant', {
1373
+ module: CC_FILE,
1374
+ method: METHODS.DROP_CONFERENCE_PARTICIPANT,
1375
+ trackingId: response?.trackingId,
1376
+ interactionId: requestInteractionId,
1377
+ });
1378
+
1379
+ return response;
1380
+ } catch (error) {
1381
+ const failureTrackingFields = MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
1382
+ error?.details || {}
1383
+ );
1384
+
1385
+ this.metricsManager.trackEvent(
1386
+ METRIC_EVENT_NAMES.TASK_CONFERENCE_PARTICIPANT_DROP_FAILED,
1387
+ {
1388
+ taskId: this.data.interactionId,
1389
+ requestInteractionId,
1390
+ agentId: this.agentId,
1391
+ trackingId: failureTrackingFields.trackingId,
1392
+ notifTrackingId: failureTrackingFields.notifTrackingId,
1393
+ orgId: failureTrackingFields.orgId,
1394
+ failureType: failureTrackingFields.failureType,
1395
+ reasonCode: failureTrackingFields.reasonCode,
1396
+ },
1397
+ ['operational', 'behavioral', 'business']
1398
+ );
1399
+
1400
+ LoggerProxy.error('Failed to drop conference participant', {
1401
+ module: CC_FILE,
1402
+ method: METHODS.DROP_CONFERENCE_PARTICIPANT,
1403
+ trackingId: failureTrackingFields.trackingId,
1404
+ interactionId: requestInteractionId,
1405
+ });
1406
+
1407
+ throw error;
1408
+ }
1409
+ }
1410
+
830
1411
  /**
831
1412
  * Exit from a conference call.
832
1413
  * Per conference-spec.md:
@@ -891,9 +1472,32 @@ export default class Voice extends Task implements IVoice {
891
1472
 
892
1473
  // Send success event to transition state
893
1474
  if (this.stateMachineService) {
1475
+ const responseTaskData = (response?.data ?? {}) as TaskData;
1476
+ const snapshot = this.stateMachineService.getSnapshot();
1477
+ const wrapUpContext = (snapshot?.context ?? {
1478
+ uiControlConfig: this.uiControlConfig,
1479
+ taskData: this.data,
1480
+ }) as TaskContext;
1481
+ const mergedTaskData = {
1482
+ ...this.data,
1483
+ ...responseTaskData,
1484
+ };
1485
+ // Pending-list precedence is response-only; do not keep a cached snapshot list.
1486
+ if (!Object.prototype.hasOwnProperty.call(responseTaskData, 'agentsPendingWrapUp')) {
1487
+ delete mergedTaskData.agentsPendingWrapUp;
1488
+ }
1489
+ let wrapUpRequired = shouldWrapUpForThisAgent(wrapUpContext, mergedTaskData);
1490
+ // Confirmed self-exit: empty/absent response pending matches TaskManager leave stamp.
1491
+ if (!wrapUpRequired && !hasNonemptyPendingWrapUp(responseTaskData)) {
1492
+ wrapUpRequired = !isConsultedNonOwner(mergedTaskData, this.data);
1493
+ }
1494
+
894
1495
  this.stateMachineService.send({
895
1496
  type: TaskEvent.EXIT_CONFERENCE_SUCCESS,
896
- taskData: response.data,
1497
+ taskData: {
1498
+ ...responseTaskData,
1499
+ wrapUpRequired,
1500
+ },
897
1501
  });
898
1502
  }
899
1503
 
@@ -1259,8 +1863,12 @@ export default class Voice extends Task implements IVoice {
1259
1863
  {updateTaskData: true}
1260
1864
  ),
1261
1865
  emitTaskOutdialFailed: ({event}: TaskActionArgs) => {
1262
- if (event && 'taskData' in event && event.taskData) {
1263
- this.updateTaskData(event.taskData as TaskData);
1866
+ const taskData = (event as {taskData?: TaskData})?.taskData;
1867
+ if (taskData) {
1868
+ this.updateTaskData(taskData);
1869
+ }
1870
+ if (taskData?.suppressOutdialFailedPopup) {
1871
+ return;
1264
1872
  }
1265
1873
  const reason = (event as {reason?: string})?.reason || 'Outdial failed';
1266
1874
  this.emit(TASK_EVENTS.TASK_OUTDIAL_FAILED, reason);