@webex/contact-center 3.12.0-next.14 → 3.12.0-next.140

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 (317) hide show
  1. package/.sdd/manifest.json +885 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +59 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +52 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +382 -0
  17. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  18. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  19. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  20. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  21. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  22. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  23. package/ai-docs/patterns/testing-patterns.md +480 -0
  24. package/ai-docs/patterns/typescript-patterns.md +365 -0
  25. package/ai-docs/templates/README.md +102 -0
  26. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  27. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  28. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  29. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  30. package/ai-docs/templates/new-method/00-master.md +80 -0
  31. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  32. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  33. package/ai-docs/templates/new-method/03-tests.md +201 -0
  34. package/ai-docs/templates/new-method/04-validation.md +141 -0
  35. package/ai-docs/templates/new-service/00-master.md +109 -0
  36. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  37. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  38. package/ai-docs/templates/new-service/03-integration.md +178 -0
  39. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  40. package/ai-docs/templates/new-service/05-validation.md +145 -0
  41. package/dist/cc.js +1004 -43
  42. package/dist/cc.js.map +1 -1
  43. package/dist/config.js +13 -0
  44. package/dist/config.js.map +1 -1
  45. package/dist/constants.js +31 -3
  46. package/dist/constants.js.map +1 -1
  47. package/dist/index.js +45 -15
  48. package/dist/index.js.map +1 -1
  49. package/dist/metrics/MetricsManager.js +16 -0
  50. package/dist/metrics/MetricsManager.js.map +1 -1
  51. package/dist/metrics/behavioral-events.js +211 -0
  52. package/dist/metrics/behavioral-events.js.map +1 -1
  53. package/dist/metrics/constants.js +49 -4
  54. package/dist/metrics/constants.js.map +1 -1
  55. package/dist/services/AddressBook.js +18 -15
  56. package/dist/services/AddressBook.js.map +1 -1
  57. package/dist/services/AnswerCallOnWebexService.js +202 -0
  58. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  59. package/dist/services/ApiAiAssistant.js +269 -9
  60. package/dist/services/ApiAiAssistant.js.map +1 -1
  61. package/dist/services/EntryPoint.js +46 -68
  62. package/dist/services/EntryPoint.js.map +1 -1
  63. package/dist/services/Queue.js +27 -22
  64. package/dist/services/Queue.js.map +1 -1
  65. package/dist/services/UserPreference.js +427 -0
  66. package/dist/services/UserPreference.js.map +1 -0
  67. package/dist/services/WebexCrossClientService.js +225 -0
  68. package/dist/services/WebexCrossClientService.js.map +1 -0
  69. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  70. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  71. package/dist/services/config/Util.js +11 -4
  72. package/dist/services/config/Util.js.map +1 -1
  73. package/dist/services/config/constants.js +41 -7
  74. package/dist/services/config/constants.js.map +1 -1
  75. package/dist/services/config/index.js +51 -0
  76. package/dist/services/config/index.js.map +1 -1
  77. package/dist/services/config/types.js +57 -12
  78. package/dist/services/config/types.js.map +1 -1
  79. package/dist/services/core/Err.js.map +1 -1
  80. package/dist/services/core/Utils.js +111 -32
  81. package/dist/services/core/Utils.js.map +1 -1
  82. package/dist/services/core/WebexRequest.js +6 -2
  83. package/dist/services/core/WebexRequest.js.map +1 -1
  84. package/dist/services/core/aqm-reqs.js +28 -14
  85. package/dist/services/core/aqm-reqs.js.map +1 -1
  86. package/dist/services/core/types.js.map +1 -1
  87. package/dist/services/core/websocket/WebSocketManager.js +2 -1
  88. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  89. package/dist/services/core/websocket/types.js.map +1 -1
  90. package/dist/services/index.js +1 -1
  91. package/dist/services/index.js.map +1 -1
  92. package/dist/services/task/Task.js +754 -0
  93. package/dist/services/task/Task.js.map +1 -0
  94. package/dist/services/task/TaskFactory.js +50 -0
  95. package/dist/services/task/TaskFactory.js.map +1 -0
  96. package/dist/services/task/TaskManager.js +1183 -521
  97. package/dist/services/task/TaskManager.js.map +1 -1
  98. package/dist/services/task/TaskUtils.js +211 -27
  99. package/dist/services/task/TaskUtils.js.map +1 -1
  100. package/dist/services/task/WebexCallingUtils.js +70 -0
  101. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  102. package/dist/services/task/constants.js +12 -2
  103. package/dist/services/task/constants.js.map +1 -1
  104. package/dist/services/task/contact.js +29 -0
  105. package/dist/services/task/contact.js.map +1 -1
  106. package/dist/services/task/dialer.js +78 -0
  107. package/dist/services/task/dialer.js.map +1 -1
  108. package/dist/services/task/digital/Digital.js +78 -0
  109. package/dist/services/task/digital/Digital.js.map +1 -0
  110. package/dist/services/task/state-machine/TaskStateMachine.js +982 -0
  111. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  112. package/dist/services/task/state-machine/actions.js +572 -0
  113. package/dist/services/task/state-machine/actions.js.map +1 -0
  114. package/dist/services/task/state-machine/constants.js +161 -0
  115. package/dist/services/task/state-machine/constants.js.map +1 -0
  116. package/dist/services/task/state-machine/guards.js +379 -0
  117. package/dist/services/task/state-machine/guards.js.map +1 -0
  118. package/dist/services/task/state-machine/index.js +53 -0
  119. package/dist/services/task/state-machine/index.js.map +1 -0
  120. package/dist/services/task/state-machine/types.js +54 -0
  121. package/dist/services/task/state-machine/types.js.map +1 -0
  122. package/dist/services/task/state-machine/uiControlsComputer.js +703 -0
  123. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  124. package/dist/services/task/taskDataNormalizer.js +99 -0
  125. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  126. package/dist/services/task/types.js +228 -5
  127. package/dist/services/task/types.js.map +1 -1
  128. package/dist/services/task/voice/Voice.js +1504 -0
  129. package/dist/services/task/voice/Voice.js.map +1 -0
  130. package/dist/services/task/voice/WebRTC.js +152 -0
  131. package/dist/services/task/voice/WebRTC.js.map +1 -0
  132. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  133. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  134. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  135. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  136. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  137. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  138. package/dist/services/wxAppTelephonyUtils.js +19 -0
  139. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  140. package/dist/types/cc.d.ts +193 -6
  141. package/dist/types/config.d.ts +13 -0
  142. package/dist/types/constants.d.ts +29 -1
  143. package/dist/types/index.d.ts +35 -8
  144. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  145. package/dist/types/metrics/constants.d.ts +44 -1
  146. package/dist/types/services/AddressBook.d.ts +2 -1
  147. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  148. package/dist/types/services/ApiAiAssistant.d.ts +56 -5
  149. package/dist/types/services/EntryPoint.d.ts +7 -5
  150. package/dist/types/services/Queue.d.ts +5 -3
  151. package/dist/types/services/UserPreference.d.ts +118 -0
  152. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  153. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  154. package/dist/types/services/config/constants.d.ts +34 -5
  155. package/dist/types/services/config/types.d.ts +199 -12
  156. package/dist/types/services/core/Err.d.ts +6 -0
  157. package/dist/types/services/core/Utils.d.ts +35 -13
  158. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  159. package/dist/types/services/core/types.d.ts +2 -0
  160. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  161. package/dist/types/services/core/websocket/types.d.ts +1 -1
  162. package/dist/types/services/index.d.ts +1 -1
  163. package/dist/types/services/task/Task.d.ts +175 -0
  164. package/dist/types/services/task/TaskFactory.d.ts +13 -0
  165. package/dist/types/services/task/TaskUtils.d.ts +48 -2
  166. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  167. package/dist/types/services/task/constants.d.ts +10 -0
  168. package/dist/types/services/task/contact.d.ts +4 -0
  169. package/dist/types/services/task/dialer.d.ts +30 -0
  170. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  171. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1442 -0
  172. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  173. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  174. package/dist/types/services/task/state-machine/guards.d.ts +103 -0
  175. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  176. package/dist/types/services/task/state-machine/types.d.ts +277 -0
  177. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  178. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  179. package/dist/types/services/task/types.d.ts +682 -66
  180. package/dist/types/services/task/voice/Voice.d.ts +240 -0
  181. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  182. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  183. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  184. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  185. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  186. package/dist/types/types.d.ts +205 -9
  187. package/dist/types/utils/PageCache.d.ts +20 -3
  188. package/dist/types/webex.d.ts +1 -0
  189. package/dist/types.js +162 -4
  190. package/dist/types.js.map +1 -1
  191. package/dist/utils/PageCache.js +19 -5
  192. package/dist/utils/PageCache.js.map +1 -1
  193. package/dist/webex.js +22 -2
  194. package/dist/webex.js.map +1 -1
  195. package/package.json +16 -12
  196. package/src/cc.ts +1330 -117
  197. package/src/config.ts +13 -0
  198. package/src/constants.ts +29 -1
  199. package/src/index.ts +36 -5
  200. package/src/metrics/MetricsManager.ts +16 -0
  201. package/src/metrics/ai-docs/AGENTS.md +350 -0
  202. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  203. package/src/metrics/ai-docs/metrics-spec.md +963 -0
  204. package/src/metrics/behavioral-events.ts +218 -0
  205. package/src/metrics/constants.ts +53 -4
  206. package/src/services/AddressBook.ts +17 -6
  207. package/src/services/AnswerCallOnWebexService.ts +239 -0
  208. package/src/services/ApiAiAssistant.ts +356 -9
  209. package/src/services/EntryPoint.ts +59 -60
  210. package/src/services/Queue.ts +29 -12
  211. package/src/services/UserPreference.ts +509 -0
  212. package/src/services/WebexCrossClientService.ts +298 -0
  213. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  214. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  215. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  216. package/src/services/agent/ai-docs/agent-spec.md +505 -0
  217. package/src/services/ai-docs/AGENTS.md +386 -0
  218. package/src/services/ai-docs/services-spec.md +505 -0
  219. package/src/services/config/Util.ts +12 -3
  220. package/src/services/config/ai-docs/AGENTS.md +255 -0
  221. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  222. package/src/services/config/ai-docs/config-spec.md +686 -0
  223. package/src/services/config/constants.ts +46 -6
  224. package/src/services/config/index.ts +65 -0
  225. package/src/services/config/types.ts +199 -13
  226. package/src/services/core/Err.ts +3 -0
  227. package/src/services/core/Utils.ts +127 -37
  228. package/src/services/core/WebexRequest.ts +3 -1
  229. package/src/services/core/ai-docs/AGENTS.md +381 -0
  230. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  231. package/src/services/core/ai-docs/core-spec.md +787 -0
  232. package/src/services/core/aqm-reqs.ts +30 -15
  233. package/src/services/core/types.ts +2 -0
  234. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  235. package/src/services/core/websocket/types.ts +1 -1
  236. package/src/services/index.ts +1 -1
  237. package/src/services/task/Task.ts +908 -0
  238. package/src/services/task/TaskFactory.ts +61 -0
  239. package/src/services/task/TaskManager.ts +1430 -608
  240. package/src/services/task/TaskUtils.ts +303 -25
  241. package/src/services/task/WebexCallingUtils.ts +136 -0
  242. package/src/services/task/ai-docs/AGENTS.md +457 -0
  243. package/src/services/task/ai-docs/ARCHITECTURE.md +595 -0
  244. package/src/services/task/ai-docs/task-spec.md +1476 -0
  245. package/src/services/task/constants.ts +10 -0
  246. package/src/services/task/contact.ts +30 -0
  247. package/src/services/task/dialer.ts +80 -0
  248. package/src/services/task/digital/Digital.ts +97 -0
  249. package/src/services/task/state-machine/TaskStateMachine.ts +1320 -0
  250. package/src/services/task/state-machine/actions.ts +741 -0
  251. package/src/services/task/state-machine/ai-docs/AGENTS.md +460 -0
  252. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1156 -0
  253. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2247 -0
  254. package/src/services/task/state-machine/constants.ts +172 -0
  255. package/src/services/task/state-machine/guards.ts +442 -0
  256. package/src/services/task/state-machine/index.ts +28 -0
  257. package/src/services/task/state-machine/types.ts +258 -0
  258. package/src/services/task/state-machine/uiControlsComputer.ts +1135 -0
  259. package/src/services/task/taskDataNormalizer.ts +137 -0
  260. package/src/services/task/types.ts +835 -70
  261. package/src/services/task/voice/Voice.ts +1873 -0
  262. package/src/services/task/voice/WebRTC.ts +191 -0
  263. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  264. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  265. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  266. package/src/services/wxAppTelephonyUtils.ts +14 -0
  267. package/src/types.ts +264 -11
  268. package/src/utils/AGENTS.md +289 -0
  269. package/src/utils/PageCache.ts +38 -5
  270. package/src/utils/ai-docs/utils-spec.md +391 -0
  271. package/src/webex.js +10 -0
  272. package/test/unit/spec/cc.ts +2371 -98
  273. package/test/unit/spec/logger-proxy.ts +70 -0
  274. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  275. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  276. package/test/unit/spec/services/AddressBook.ts +37 -6
  277. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  278. package/test/unit/spec/services/ApiAiAssistant.ts +311 -21
  279. package/test/unit/spec/services/EntryPoint.ts +87 -40
  280. package/test/unit/spec/services/Queue.ts +123 -12
  281. package/test/unit/spec/services/UserPreference.ts +401 -0
  282. package/test/unit/spec/services/WebCallingService.ts +7 -1
  283. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  284. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  285. package/test/unit/spec/services/config/Util.ts +129 -0
  286. package/test/unit/spec/services/config/index.ts +97 -29
  287. package/test/unit/spec/services/core/Utils.ts +425 -8
  288. package/test/unit/spec/services/core/WebexRequest.ts +3 -1
  289. package/test/unit/spec/services/core/aqm-reqs.ts +113 -1
  290. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  291. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  292. package/test/unit/spec/services/task/Task.ts +745 -0
  293. package/test/unit/spec/services/task/TaskFactory.ts +99 -0
  294. package/test/unit/spec/services/task/TaskManager.ts +2539 -1490
  295. package/test/unit/spec/services/task/TaskUtils.ts +235 -0
  296. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  297. package/test/unit/spec/services/task/contact.ts +33 -0
  298. package/test/unit/spec/services/task/dialer.ts +190 -0
  299. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  300. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +4060 -0
  301. package/test/unit/spec/services/task/state-machine/guards.ts +839 -0
  302. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  303. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +3101 -0
  304. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  305. package/test/unit/spec/services/task/voice/Voice.ts +2020 -0
  306. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  307. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  308. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  309. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  310. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  311. package/umd/contact-center.min.js +2 -2
  312. package/umd/contact-center.min.js.map +1 -1
  313. package/dist/services/task/index.js +0 -1530
  314. package/dist/services/task/index.js.map +0 -1
  315. package/dist/types/services/task/index.d.ts +0 -650
  316. package/src/services/task/index.ts +0 -1806
  317. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -0,0 +1,191 @@
1
+ import {LocalMicrophoneStream, CALL_EVENT_KEYS} from '@webex/calling';
2
+ import {CC_FILE} from '../../../constants';
3
+ import {getErrorDetails} from '../../core/Utils';
4
+ import routingContact from '../contact';
5
+ import {
6
+ TaskData,
7
+ TaskResponse,
8
+ TASK_EVENTS,
9
+ IWebRTC,
10
+ VoiceUIControlOptions,
11
+ VOICE_VARIANT,
12
+ TaskToggleMuteOptions,
13
+ } from '../types';
14
+ import Voice from './Voice';
15
+ import WebCallingService from '../../WebCallingService';
16
+ import {WrapupData} from '../../config/types';
17
+ import MetricsManager from '../../../metrics/MetricsManager';
18
+ import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
19
+ import LoggerProxy from '../../../logger-proxy';
20
+
21
+ export default class WebRTC extends Voice implements IWebRTC {
22
+ private localAudioStream: LocalMicrophoneStream;
23
+ private webCallingService: WebCallingService;
24
+
25
+ constructor(
26
+ contact: ReturnType<typeof routingContact>,
27
+ webCallingService: WebCallingService,
28
+ data: TaskData,
29
+ callOptions?: VoiceUIControlOptions,
30
+ wrapupData?: WrapupData,
31
+ agentId?: string
32
+ ) {
33
+ const mergedCallOptions: VoiceUIControlOptions = {
34
+ ...callOptions,
35
+ voiceVariant: VOICE_VARIANT.WEBRTC,
36
+ };
37
+
38
+ super(contact, data, mergedCallOptions, wrapupData, agentId);
39
+ this.webCallingService = webCallingService;
40
+ this.registerWebCallListeners();
41
+ }
42
+
43
+ private registerWebCallListeners() {
44
+ this.webCallingService.on(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
45
+ }
46
+
47
+ private handleRemoteMedia = (track: MediaStreamTrack) => {
48
+ this.emit(TASK_EVENTS.TASK_MEDIA, track);
49
+ };
50
+
51
+ /**
52
+ * This method is used to unregister the web call listeners.
53
+ * @returns void
54
+ * @example
55
+ * ```typescript
56
+ * task.unregisterWebCallListeners();
57
+ * ```
58
+ */
59
+ public unregisterWebCallListeners() {
60
+ this.webCallingService.off(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
61
+ }
62
+
63
+ /**
64
+ * This is used for incoming task accept by agent.
65
+ *
66
+ * @returns Promise<TaskResponse>
67
+ * @throws Error
68
+ * @example
69
+ * ```typescript
70
+ * task.accept().then(()=>{}).catch(()=>{})
71
+ * ```
72
+ */
73
+ public async accept(): Promise<TaskResponse> {
74
+ LoggerProxy.log(`Accepting WebRTC task for taskId:${this.data.interactionId}`, {
75
+ module: 'WebRTC',
76
+ method: 'accept',
77
+ });
78
+ try {
79
+ this.metricsManager.timeEvent([
80
+ METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
81
+ METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
82
+ ]);
83
+
84
+ const constraints = {audio: true};
85
+ const localStream = await navigator.mediaDevices.getUserMedia(constraints);
86
+ const audioTrack = localStream.getAudioTracks()[0];
87
+ this.localAudioStream = new LocalMicrophoneStream(new MediaStream([audioTrack]));
88
+ this.webCallingService.answerCall(this.localAudioStream, this.data.interactionId);
89
+
90
+ this.metricsManager.trackEvent(
91
+ METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
92
+ {
93
+ taskId: this.data.interactionId,
94
+ ...MetricsManager.getCommonTrackingFieldForAQMResponse(this.data),
95
+ },
96
+ ['operational', 'behavioral', 'business']
97
+ );
98
+
99
+ return Promise.resolve();
100
+ } catch (error) {
101
+ this.metricsManager.trackEvent(
102
+ METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
103
+ {
104
+ taskId: this.data.interactionId,
105
+ error: error.toString(),
106
+ ...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
107
+ (error as any).details || {}
108
+ ),
109
+ },
110
+ ['operational', 'behavioral', 'business']
111
+ );
112
+ const {error: detailedError} = getErrorDetails(error, 'accept', CC_FILE);
113
+ throw detailedError;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * This is used for the incoming task decline by agent.
119
+ *
120
+ * @returns Promise<TaskResponse>
121
+ * @throws Error
122
+ * @example
123
+ * ```typescript
124
+ * task.decline().then(()=>{}).catch(()=>{})
125
+ * ```
126
+ */
127
+ public async decline(): Promise<TaskResponse> {
128
+ LoggerProxy.log(`Declining WebRTC task for taskId:${this.data.interactionId}`, {
129
+ module: 'WebRTC',
130
+ method: 'decline',
131
+ });
132
+ try {
133
+ this.metricsManager.timeEvent([
134
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
135
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
136
+ ]);
137
+
138
+ this.webCallingService.declineCall(this.data.interactionId);
139
+ this.unregisterWebCallListeners();
140
+
141
+ this.metricsManager.trackEvent(
142
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
143
+ {taskId: this.data.interactionId},
144
+ ['operational', 'behavioral']
145
+ );
146
+
147
+ return Promise.resolve();
148
+ } catch (error) {
149
+ this.metricsManager.trackEvent(
150
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
151
+ {
152
+ taskId: this.data.interactionId,
153
+ error: error.toString(),
154
+ ...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
155
+ (error as any).details || {}
156
+ ),
157
+ },
158
+ ['operational', 'behavioral']
159
+ );
160
+ const {error: detailedError} = getErrorDetails(error, 'decline', CC_FILE);
161
+ throw detailedError;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * This is used for the placing the call in mute or unmute by the agent.
167
+ *
168
+ * @throws Error
169
+ * @example
170
+ * ```typescript
171
+ * task.toggleMute().then(()=>{}).catch(()=>{})
172
+ * ```
173
+ */
174
+ public async toggleMute(options?: TaskToggleMuteOptions) {
175
+ if (options) {
176
+ // parameter intentionally unused — WebRTC toggles from local stream state
177
+ }
178
+ LoggerProxy.log(`Toggling mute WebRTC task for taskId:${this.data.interactionId}`, {
179
+ module: 'WebRTC',
180
+ method: 'toggleMute',
181
+ });
182
+ try {
183
+ this.webCallingService.muteUnmuteCall(this.localAudioStream);
184
+
185
+ return Promise.resolve();
186
+ } catch (error) {
187
+ const {error: detailedError} = getErrorDetails(error, 'mute', CC_FILE);
188
+ throw detailedError;
189
+ }
190
+ }
191
+ }
@@ -0,0 +1,204 @@
1
+ import MetricsManager from '../../../metrics/MetricsManager';
2
+ import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
3
+ import {
4
+ deriveWxAppAcceptReason,
5
+ logWxAppOfferDecision,
6
+ logWxAppOfferParticipantMismatch,
7
+ WxAppAcceptReason,
8
+ } from '../../wxAppDiagnosticLogging';
9
+ import {TaskState} from '../state-machine';
10
+ import {VoiceVariant, VOICE_VARIANT} from '../types';
11
+ import {
12
+ getCallingDeviceDetails,
13
+ getWxAppParticipantDiagnostics,
14
+ WxAppVoiceDependencies,
15
+ } from './wxAppVoiceMethods';
16
+
17
+ /** Defer mismatch WARN/metric so transient WS ordering gaps (~200–300 ms) do not false-alarm. */
18
+ export const WXAPP_PARTICIPANT_MISMATCH_GRACE_MS = 500;
19
+
20
+ export type WxAppOfferObservabilityContext = {
21
+ getInteractionId: () => string;
22
+ getTaskState: () => TaskState | undefined;
23
+ getAcceptControl: () => {isVisible: boolean; isEnabled: boolean} | undefined;
24
+ getVoiceVariant: () => VoiceVariant;
25
+ isOutdial: () => boolean;
26
+ isWxAppInboundOffer: () => boolean;
27
+ isWxAppCallingOffer: () => boolean;
28
+ getWxAppAcceptInFlight: () => boolean;
29
+ getWxAppAnswerPending: () => boolean;
30
+ getEnableWxBetterTogether: () => boolean;
31
+ getUsersubPublished: () => boolean;
32
+ getWxAppVoiceDependencies: () => WxAppVoiceDependencies;
33
+ getMetricsManager: () => MetricsManager;
34
+ };
35
+
36
+ /**
37
+ * OFFERED-state wxApp offer diagnostics: acceptReason logging and deferred participant mismatch.
38
+ * Invoked from Voice.updateUiControls — observability only.
39
+ */
40
+ export class WxAppOfferObservability {
41
+ private lastLoggedWxAppAcceptReason?: WxAppAcceptReason;
42
+ private lastLoggedWxAppParticipantMismatch = false;
43
+ private wxAppParticipantMismatchGraceTimer?: ReturnType<typeof setTimeout>;
44
+ private disposed = false;
45
+
46
+ public handleUiControlsUpdate(ctx: WxAppOfferObservabilityContext): void {
47
+ if (this.disposed) {
48
+ return;
49
+ }
50
+
51
+ if (!ctx.getEnableWxBetterTogether()) {
52
+ this.cancelGraceTimer();
53
+
54
+ return;
55
+ }
56
+
57
+ const state = ctx.getTaskState();
58
+ if (state !== TaskState.OFFERED) {
59
+ this.cancelGraceTimer();
60
+
61
+ return;
62
+ }
63
+
64
+ const accept = ctx.getAcceptControl();
65
+ if (!accept?.isVisible) {
66
+ return;
67
+ }
68
+
69
+ const deps = ctx.getWxAppVoiceDependencies();
70
+ const isOutdial = ctx.isOutdial();
71
+ const isWxAppInboundOffer = ctx.isWxAppInboundOffer();
72
+ const isWxAppOutdialOffer = ctx.isWxAppCallingOffer() && isOutdial;
73
+ const deviceDetails = getCallingDeviceDetails(deps);
74
+ const participantDiagnostics = getWxAppParticipantDiagnostics(deps);
75
+ const usersubPublished = ctx.getUsersubPublished();
76
+ const acceptReason = deriveWxAppAcceptReason({
77
+ isWxAppInboundOffer,
78
+ isWxAppOutdialOffer,
79
+ isWebrtc: ctx.getVoiceVariant() === VOICE_VARIANT.WEBRTC,
80
+ isOutdial,
81
+ wxAppAcceptInFlight: ctx.getWxAppAcceptInFlight(),
82
+ wxAppAnswerPending: ctx.getWxAppAnswerPending(),
83
+ enableWxBetterTogether: ctx.getEnableWxBetterTogether(),
84
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
85
+ });
86
+
87
+ if (acceptReason !== this.lastLoggedWxAppAcceptReason) {
88
+ this.lastLoggedWxAppAcceptReason = acceptReason;
89
+
90
+ logWxAppOfferDecision({
91
+ interactionId: ctx.getInteractionId(),
92
+ acceptVisible: accept.isVisible,
93
+ acceptEnabled: accept.isEnabled,
94
+ acceptReason,
95
+ wxAppParticipantDeviceType:
96
+ deviceDetails?.deviceType ?? participantDiagnostics.participantDeviceType,
97
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
98
+ hasDeviceId: participantDiagnostics.hasDeviceId,
99
+ usersubPublished,
100
+ });
101
+ }
102
+
103
+ if (participantDiagnostics.hasValidWxAppParticipant || !usersubPublished) {
104
+ this.cancelGraceTimer();
105
+ } else if (!ctx.isOutdial() && !this.lastLoggedWxAppParticipantMismatch) {
106
+ this.scheduleGraceTimer(ctx);
107
+ }
108
+ }
109
+
110
+ public dispose(): void {
111
+ this.disposed = true;
112
+ this.cancelGraceTimer();
113
+ }
114
+
115
+ private cancelGraceTimer(): void {
116
+ if (this.wxAppParticipantMismatchGraceTimer !== undefined) {
117
+ clearTimeout(this.wxAppParticipantMismatchGraceTimer);
118
+ this.wxAppParticipantMismatchGraceTimer = undefined;
119
+ }
120
+ }
121
+
122
+ private scheduleGraceTimer(ctx: WxAppOfferObservabilityContext): void {
123
+ if (
124
+ this.disposed ||
125
+ this.lastLoggedWxAppParticipantMismatch ||
126
+ this.wxAppParticipantMismatchGraceTimer !== undefined
127
+ ) {
128
+ return;
129
+ }
130
+
131
+ this.wxAppParticipantMismatchGraceTimer = setTimeout(() => {
132
+ this.wxAppParticipantMismatchGraceTimer = undefined;
133
+ this.emitParticipantMismatchIfStillNeeded(ctx);
134
+ }, WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
135
+ }
136
+
137
+ private emitParticipantMismatchIfStillNeeded(ctx: WxAppOfferObservabilityContext): void {
138
+ if (
139
+ this.disposed ||
140
+ !ctx.getEnableWxBetterTogether() ||
141
+ this.lastLoggedWxAppParticipantMismatch
142
+ ) {
143
+ return;
144
+ }
145
+
146
+ if (ctx.isOutdial()) {
147
+ return;
148
+ }
149
+
150
+ if (ctx.getTaskState() !== TaskState.OFFERED) {
151
+ return;
152
+ }
153
+
154
+ const accept = ctx.getAcceptControl();
155
+ if (!accept?.isVisible) {
156
+ return;
157
+ }
158
+
159
+ const deps = ctx.getWxAppVoiceDependencies();
160
+ const participantDiagnostics = getWxAppParticipantDiagnostics(deps);
161
+ const usersubPublished = ctx.getUsersubPublished();
162
+
163
+ if (!usersubPublished || participantDiagnostics.hasValidWxAppParticipant) {
164
+ return;
165
+ }
166
+
167
+ const isOutdial = ctx.isOutdial();
168
+ const acceptReason = deriveWxAppAcceptReason({
169
+ isWxAppInboundOffer: ctx.isWxAppInboundOffer(),
170
+ isWxAppOutdialOffer: ctx.isWxAppCallingOffer() && isOutdial,
171
+ isWebrtc: ctx.getVoiceVariant() === VOICE_VARIANT.WEBRTC,
172
+ isOutdial,
173
+ wxAppAcceptInFlight: ctx.getWxAppAcceptInFlight(),
174
+ wxAppAnswerPending: ctx.getWxAppAnswerPending(),
175
+ enableWxBetterTogether: ctx.getEnableWxBetterTogether(),
176
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
177
+ });
178
+
179
+ this.lastLoggedWxAppParticipantMismatch = true;
180
+
181
+ logWxAppOfferParticipantMismatch({
182
+ interactionId: ctx.getInteractionId(),
183
+ usersubPublished,
184
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
185
+ hasDeviceId: participantDiagnostics.hasDeviceId,
186
+ participantDeviceType: participantDiagnostics.participantDeviceType,
187
+ acceptVisible: accept.isVisible,
188
+ acceptEnabled: accept.isEnabled,
189
+ acceptReason,
190
+ });
191
+
192
+ ctx.getMetricsManager().trackEvent(
193
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
194
+ {
195
+ taskId: ctx.getInteractionId(),
196
+ usersubPublished,
197
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
198
+ hasDeviceId: participantDiagnostics.hasDeviceId,
199
+ acceptReason,
200
+ },
201
+ ['operational', 'behavioral']
202
+ );
203
+ }
204
+ }