@webex/contact-center 3.12.0-next.13 → 3.12.0-next.130

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 (312) hide show
  1. package/.sdd/manifest.json +884 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +53 -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 +971 -42
  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 +205 -0
  52. package/dist/metrics/behavioral-events.js.map +1 -1
  53. package/dist/metrics/constants.js +48 -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 +222 -0
  68. package/dist/services/WebexCrossClientService.js.map +1 -0
  69. package/dist/services/WxAppTelephonyMercurySync.js +108 -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 +49 -0
  95. package/dist/services/task/TaskFactory.js.map +1 -0
  96. package/dist/services/task/TaskManager.js +1172 -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 +1485 -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/wxAppVoiceMethods.js +354 -0
  133. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  134. package/dist/services/wxAppDiagnosticLogging.js +122 -0
  135. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  136. package/dist/services/wxAppTelephonyUtils.js +19 -0
  137. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  138. package/dist/types/cc.d.ts +193 -6
  139. package/dist/types/config.d.ts +13 -0
  140. package/dist/types/constants.d.ts +29 -1
  141. package/dist/types/index.d.ts +35 -8
  142. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  143. package/dist/types/metrics/constants.d.ts +43 -1
  144. package/dist/types/services/AddressBook.d.ts +2 -1
  145. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  146. package/dist/types/services/ApiAiAssistant.d.ts +56 -5
  147. package/dist/types/services/EntryPoint.d.ts +7 -5
  148. package/dist/types/services/Queue.d.ts +5 -3
  149. package/dist/types/services/UserPreference.d.ts +118 -0
  150. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  151. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  152. package/dist/types/services/config/constants.d.ts +34 -5
  153. package/dist/types/services/config/types.d.ts +197 -12
  154. package/dist/types/services/core/Err.d.ts +6 -0
  155. package/dist/types/services/core/Utils.d.ts +35 -13
  156. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  157. package/dist/types/services/core/types.d.ts +2 -0
  158. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  159. package/dist/types/services/core/websocket/types.d.ts +1 -1
  160. package/dist/types/services/index.d.ts +1 -1
  161. package/dist/types/services/task/Task.d.ts +175 -0
  162. package/dist/types/services/task/TaskFactory.d.ts +13 -0
  163. package/dist/types/services/task/TaskUtils.d.ts +48 -2
  164. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  165. package/dist/types/services/task/constants.d.ts +10 -0
  166. package/dist/types/services/task/contact.d.ts +4 -0
  167. package/dist/types/services/task/dialer.d.ts +30 -0
  168. package/dist/types/services/task/digital/Digital.d.ts +22 -0
  169. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1442 -0
  170. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  171. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  172. package/dist/types/services/task/state-machine/guards.d.ts +103 -0
  173. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  174. package/dist/types/services/task/state-machine/types.d.ts +277 -0
  175. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  176. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  177. package/dist/types/services/task/types.d.ts +680 -66
  178. package/dist/types/services/task/voice/Voice.d.ts +227 -0
  179. package/dist/types/services/task/voice/WebRTC.d.ts +53 -0
  180. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +55 -0
  181. package/dist/types/services/wxAppDiagnosticLogging.d.ts +51 -0
  182. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  183. package/dist/types/types.d.ts +205 -9
  184. package/dist/types/utils/PageCache.d.ts +20 -3
  185. package/dist/types/webex.d.ts +1 -0
  186. package/dist/types.js +162 -4
  187. package/dist/types.js.map +1 -1
  188. package/dist/utils/PageCache.js +19 -5
  189. package/dist/utils/PageCache.js.map +1 -1
  190. package/dist/webex.js +22 -2
  191. package/dist/webex.js.map +1 -1
  192. package/package.json +16 -12
  193. package/src/cc.ts +1289 -112
  194. package/src/config.ts +13 -0
  195. package/src/constants.ts +29 -1
  196. package/src/index.ts +36 -5
  197. package/src/metrics/MetricsManager.ts +16 -0
  198. package/src/metrics/ai-docs/AGENTS.md +350 -0
  199. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  200. package/src/metrics/ai-docs/metrics-spec.md +921 -0
  201. package/src/metrics/behavioral-events.ts +212 -0
  202. package/src/metrics/constants.ts +52 -4
  203. package/src/services/AddressBook.ts +17 -6
  204. package/src/services/AnswerCallOnWebexService.ts +239 -0
  205. package/src/services/ApiAiAssistant.ts +356 -9
  206. package/src/services/EntryPoint.ts +59 -60
  207. package/src/services/Queue.ts +29 -12
  208. package/src/services/UserPreference.ts +509 -0
  209. package/src/services/WebexCrossClientService.ts +293 -0
  210. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  211. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  212. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  213. package/src/services/agent/ai-docs/agent-spec.md +505 -0
  214. package/src/services/ai-docs/AGENTS.md +386 -0
  215. package/src/services/ai-docs/services-spec.md +505 -0
  216. package/src/services/config/Util.ts +12 -3
  217. package/src/services/config/ai-docs/AGENTS.md +255 -0
  218. package/src/services/config/ai-docs/ARCHITECTURE.md +426 -0
  219. package/src/services/config/ai-docs/config-spec.md +686 -0
  220. package/src/services/config/constants.ts +46 -6
  221. package/src/services/config/index.ts +65 -0
  222. package/src/services/config/types.ts +197 -13
  223. package/src/services/core/Err.ts +3 -0
  224. package/src/services/core/Utils.ts +127 -37
  225. package/src/services/core/WebexRequest.ts +3 -1
  226. package/src/services/core/ai-docs/AGENTS.md +381 -0
  227. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  228. package/src/services/core/ai-docs/core-spec.md +787 -0
  229. package/src/services/core/aqm-reqs.ts +30 -15
  230. package/src/services/core/types.ts +2 -0
  231. package/src/services/core/websocket/WebSocketManager.ts +2 -0
  232. package/src/services/core/websocket/types.ts +1 -1
  233. package/src/services/index.ts +1 -1
  234. package/src/services/task/Task.ts +908 -0
  235. package/src/services/task/TaskFactory.ts +60 -0
  236. package/src/services/task/TaskManager.ts +1419 -608
  237. package/src/services/task/TaskUtils.ts +303 -25
  238. package/src/services/task/WebexCallingUtils.ts +136 -0
  239. package/src/services/task/ai-docs/AGENTS.md +457 -0
  240. package/src/services/task/ai-docs/ARCHITECTURE.md +595 -0
  241. package/src/services/task/ai-docs/task-spec.md +1474 -0
  242. package/src/services/task/constants.ts +10 -0
  243. package/src/services/task/contact.ts +30 -0
  244. package/src/services/task/dialer.ts +80 -0
  245. package/src/services/task/digital/Digital.ts +97 -0
  246. package/src/services/task/state-machine/TaskStateMachine.ts +1320 -0
  247. package/src/services/task/state-machine/actions.ts +741 -0
  248. package/src/services/task/state-machine/ai-docs/AGENTS.md +460 -0
  249. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1156 -0
  250. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2247 -0
  251. package/src/services/task/state-machine/constants.ts +172 -0
  252. package/src/services/task/state-machine/guards.ts +442 -0
  253. package/src/services/task/state-machine/index.ts +28 -0
  254. package/src/services/task/state-machine/types.ts +258 -0
  255. package/src/services/task/state-machine/uiControlsComputer.ts +1135 -0
  256. package/src/services/task/taskDataNormalizer.ts +137 -0
  257. package/src/services/task/types.ts +819 -70
  258. package/src/services/task/voice/Voice.ts +1851 -0
  259. package/src/services/task/voice/WebRTC.ts +191 -0
  260. package/src/services/task/voice/wxAppVoiceMethods.ts +516 -0
  261. package/src/services/wxAppDiagnosticLogging.ts +174 -0
  262. package/src/services/wxAppTelephonyUtils.ts +14 -0
  263. package/src/types.ts +262 -11
  264. package/src/utils/AGENTS.md +289 -0
  265. package/src/utils/PageCache.ts +38 -5
  266. package/src/utils/ai-docs/utils-spec.md +391 -0
  267. package/src/webex.js +10 -0
  268. package/test/unit/spec/cc.ts +2210 -119
  269. package/test/unit/spec/logger-proxy.ts +70 -0
  270. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  271. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  272. package/test/unit/spec/services/AddressBook.ts +37 -6
  273. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  274. package/test/unit/spec/services/ApiAiAssistant.ts +311 -21
  275. package/test/unit/spec/services/EntryPoint.ts +87 -40
  276. package/test/unit/spec/services/Queue.ts +123 -12
  277. package/test/unit/spec/services/UserPreference.ts +401 -0
  278. package/test/unit/spec/services/WebCallingService.ts +7 -1
  279. package/test/unit/spec/services/WebexCrossClientService.ts +467 -0
  280. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  281. package/test/unit/spec/services/config/Util.ts +129 -0
  282. package/test/unit/spec/services/config/index.ts +97 -29
  283. package/test/unit/spec/services/core/Utils.ts +425 -8
  284. package/test/unit/spec/services/core/WebexRequest.ts +3 -1
  285. package/test/unit/spec/services/core/aqm-reqs.ts +113 -1
  286. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +66 -40
  287. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  288. package/test/unit/spec/services/task/Task.ts +745 -0
  289. package/test/unit/spec/services/task/TaskFactory.ts +99 -0
  290. package/test/unit/spec/services/task/TaskManager.ts +2518 -1494
  291. package/test/unit/spec/services/task/TaskUtils.ts +235 -0
  292. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  293. package/test/unit/spec/services/task/contact.ts +33 -0
  294. package/test/unit/spec/services/task/dialer.ts +190 -0
  295. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  296. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +4060 -0
  297. package/test/unit/spec/services/task/state-machine/guards.ts +839 -0
  298. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  299. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +3101 -0
  300. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  301. package/test/unit/spec/services/task/voice/Voice.ts +2061 -0
  302. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  303. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +603 -0
  304. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +143 -0
  305. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  306. package/umd/contact-center.min.js +2 -2
  307. package/umd/contact-center.min.js.map +1 -1
  308. package/dist/services/task/index.js +0 -1525
  309. package/dist/services/task/index.js.map +0 -1
  310. package/dist/types/services/task/index.d.ts +0 -650
  311. package/src/services/task/index.ts +0 -1801
  312. package/test/unit/spec/services/task/index.ts +0 -2184
@@ -0,0 +1,754 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _events = require("events");
8
+ var _xstate = require("xstate");
9
+ var _types = require("./types");
10
+ var _constants = require("./constants");
11
+ var _constants2 = require("../../constants");
12
+ var _Utils = require("../core/Utils");
13
+ var _MetricsManager = _interopRequireDefault(require("../../metrics/MetricsManager"));
14
+ var _constants3 = require("../../metrics/constants");
15
+ var _loggerProxy = _interopRequireDefault(require("../../logger-proxy"));
16
+ var _stateMachine = require("./state-machine");
17
+ var _uiControlsComputer = require("./state-machine/uiControlsComputer");
18
+ var _AutoWrapup = _interopRequireDefault(require("./AutoWrapup"));
19
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
+ class Task extends _events.EventEmitter {
21
+ constructor(contact, data, uiControlConfig, wrapupData, agentId) {
22
+ super();
23
+ this.contact = contact;
24
+ this.data = data;
25
+ const channelType = uiControlConfig.channelType ?? Task.resolveChannelType(data);
26
+ // Include agentId in the config for ownership checks (transfer conference)
27
+ this.uiControlConfig = {
28
+ ...uiControlConfig,
29
+ channelType,
30
+ agentId
31
+ };
32
+ this.wrapupData = wrapupData;
33
+ this.agentId = agentId;
34
+ this.metricsManager = _MetricsManager.default.getInstance();
35
+ this.webCallMap = {};
36
+ this.currentUiControls = (0, _uiControlsComputer.getDefaultUIControls)();
37
+ this.initializeStateMachine();
38
+ this.setupAutoWrapupTimer();
39
+ }
40
+ static resolveChannelType(data) {
41
+ const mediaType = data?.interaction?.mediaType ?? _types.MEDIA_CHANNEL.TELEPHONY;
42
+ return mediaType === _types.MEDIA_CHANNEL.TELEPHONY ? _types.TASK_CHANNEL_TYPE.VOICE : _types.TASK_CHANNEL_TYPE.DIGITAL;
43
+ }
44
+
45
+ // Abstract methods that all child classes must implement
46
+
47
+ // Voice-specific methods with default implementations that throw errors
48
+ // Voice class will override these with actual implementations
49
+ async decline() {
50
+ this.unsupportedMethodError('decline');
51
+ }
52
+ async pauseRecording() {
53
+ this.unsupportedMethodError('pauseRecording');
54
+ }
55
+ async resumeRecording(resumeRecordingPayload) {
56
+ if (resumeRecordingPayload) {
57
+ // parameter intentionally unused
58
+ }
59
+ this.unsupportedMethodError('resumeRecording');
60
+ }
61
+ async consult(consultPayload) {
62
+ if (consultPayload) {
63
+ // parameter intentionally unused
64
+ }
65
+ this.unsupportedMethodError('consult');
66
+ }
67
+ async endConsult(consultEndPayload) {
68
+ if (consultEndPayload) {
69
+ // parameter intentionally unused
70
+ }
71
+ this.unsupportedMethodError('endConsult');
72
+ }
73
+ async consultTransfer(consultTransferPayload) {
74
+ if (consultTransferPayload) {
75
+ // parameter intentionally unused
76
+ }
77
+ this.unsupportedMethodError('consultTransfer');
78
+ }
79
+ async consultConference() {
80
+ this.unsupportedMethodError('consultConference');
81
+ }
82
+ async dropConferenceParticipant(
83
+ // The base task preserves the public signature; Voice provides the implementation.
84
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
+ payload) {
86
+ this.unsupportedMethodError(_constants.METHODS.DROP_CONFERENCE_PARTICIPANT);
87
+ }
88
+ async exitConference() {
89
+ this.unsupportedMethodError('exitConference');
90
+ }
91
+ async transferConference() {
92
+ this.unsupportedMethodError('transferConference');
93
+ }
94
+ async switchCall() {
95
+ this.unsupportedMethodError('switchCall');
96
+ }
97
+ async toggleMute(options) {
98
+ if (options) {
99
+ // parameter intentionally unused
100
+ }
101
+ this.unsupportedMethodError('toggleMute');
102
+ }
103
+ async transmitDtmf(options) {
104
+ if (options) {
105
+ // parameter intentionally unused
106
+ }
107
+ this.unsupportedMethodError('transmitDtmf');
108
+ }
109
+ unregisterWebCallListeners() {
110
+ // Default implementation - child classes can override
111
+ _loggerProxy.default.log('unregisterWebCallListeners called', {
112
+ module: _constants2.CC_FILE,
113
+ method: 'unregisterWebCallListeners',
114
+ interactionId: this.data?.interactionId
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Cancel any in-progress auto wrap-up timer.
120
+ * Base implementation just clears the timer reference so subclasses inherit the behavior.
121
+ */
122
+ cancelAutoWrapupTimer() {
123
+ if (this.autoWrapup) {
124
+ this.autoWrapup.clear();
125
+ this.autoWrapup = undefined;
126
+ _loggerProxy.default.log('Auto wrap-up timer cancelled', {
127
+ module: _constants2.CC_FILE,
128
+ method: 'cancelAutoWrapupTimer',
129
+ interactionId: this.data?.interactionId
130
+ });
131
+ }
132
+ }
133
+
134
+ // Voice tasks use holdResume(), but provide separate methods for interface compliance
135
+ async hold() {
136
+ this.unsupportedMethodError('hold');
137
+ }
138
+ async resume() {
139
+ this.unsupportedMethodError('resume');
140
+ }
141
+ async holdResume() {
142
+ this.unsupportedMethodError('holdResume');
143
+ }
144
+
145
+ /**
146
+ * Latest UI controls derived from state machine state and context.
147
+ */
148
+ get uiControls() {
149
+ return this.currentUiControls;
150
+ }
151
+ updateUiControls(forceEmit = false) {
152
+ const nextControls = this.computeUIControls();
153
+ const shouldEmit = forceEmit || (0, _uiControlsComputer.haveUIControlsChanged)(this.currentUiControls, nextControls);
154
+ this.currentUiControls = nextControls;
155
+ if (shouldEmit) {
156
+ this.emit(_types.TASK_EVENTS.TASK_UI_CONTROLS_UPDATED, this.currentUiControls);
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Initialize the state machine
162
+ */
163
+ initializeStateMachine() {
164
+ const machine = (0, _stateMachine.createTaskStateMachine)(this.uiControlConfig, {
165
+ actions: this.getStateMachineActionOverrides()
166
+ });
167
+ this.stateMachineService = (0, _xstate.createActor)(machine);
168
+ this.stateMachineService.subscribe(snapshot => {
169
+ const previousState = this.lastState;
170
+ const currentState = snapshot.value;
171
+ _loggerProxy.default.log(`State machine transition: ${previousState || 'N/A'} -> ${currentState}`, {
172
+ module: _constants2.CC_FILE,
173
+ method: 'onTransition',
174
+ // @ts-ignore - snapshot may include event detail depending on XState version
175
+ eventType: snapshot?.event?.type
176
+ });
177
+ this.lastState = currentState;
178
+ this.state = snapshot;
179
+ this.updateUiControls(previousState !== currentState);
180
+ });
181
+ this.stateMachineService.start();
182
+ this.updateUiControls(true);
183
+ }
184
+
185
+ /**
186
+ * Send an event to the state machine
187
+ */
188
+ sendStateMachineEvent(event) {
189
+ if (this.stateMachineService) {
190
+ _loggerProxy.default.log(`Sending state machine event: ${event?.type}`, {
191
+ module: _constants2.CC_FILE,
192
+ method: 'sendStateMachineEvent',
193
+ interactionId: this.data?.interactionId
194
+ });
195
+ this.stateMachineService.send(event);
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Get the current state machine state
201
+ */
202
+ getCurrentState() {
203
+ return this.stateMachineService?.getSnapshot()?.value;
204
+ }
205
+
206
+ /**
207
+ * Compute UI controls based on current state machine state.
208
+ *
209
+ * @returns UI control states for all task actions
210
+ */
211
+ /**
212
+ * Update wxApp thick-client answer flag at runtime (Voice overrides).
213
+ */
214
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
215
+ setEnableWxBetterTogether(_enabled) {
216
+ // no-op for non-voice tasks
217
+ }
218
+
219
+ /**
220
+ * Apply wxApp mute state from external sync (Voice overrides).
221
+ */
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
223
+ applyWxAppMuteStateFromSync(_incomingCallId, _muted) {
224
+ // no-op for non-voice tasks
225
+ }
226
+
227
+ /**
228
+ * Hook for post-assign wxApp sync (Voice overrides).
229
+ */
230
+ onTaskAssigned() {
231
+ // no-op by default
232
+ }
233
+
234
+ /**
235
+ * Hook for post-hydrate wxApp sync (Voice overrides).
236
+ */
237
+ onTaskHydrated() {
238
+ // no-op by default
239
+ }
240
+ computeUIControls() {
241
+ const snapshot = this.stateMachineService?.getSnapshot?.();
242
+ if (!snapshot) {
243
+ return (0, _uiControlsComputer.getDefaultUIControls)();
244
+ }
245
+ const currentState = snapshot.value;
246
+ const context = snapshot.context;
247
+ const mergedContext = {
248
+ ...context,
249
+ uiControlConfig: {
250
+ ...context.uiControlConfig,
251
+ ...this.uiControlConfig
252
+ }
253
+ };
254
+ const uiControls = (0, _uiControlsComputer.computeUIControls)(currentState, mergedContext, this.data);
255
+ return uiControls;
256
+ }
257
+
258
+ /**
259
+ * Stop the state machine service
260
+ */
261
+ stopStateMachine() {
262
+ if (this.stateMachineService) {
263
+ this.stateMachineService.stop();
264
+ this.stateMachineService = undefined;
265
+ }
266
+ }
267
+ static extractTaskDataFromEvent(event) {
268
+ if (!event || typeof event !== 'object') {
269
+ return undefined;
270
+ }
271
+ if ('taskData' in event) {
272
+ return event.taskData;
273
+ }
274
+ return undefined;
275
+ }
276
+ async autoAnswerIfNeeded() {
277
+ if (!this.data) {
278
+ return;
279
+ }
280
+ const autoAnswerSupported = this.uiControlConfig.channelType === _types.TASK_CHANNEL_TYPE.DIGITAL || this.uiControlConfig.voiceVariant === _types.VOICE_VARIANT.WEBRTC;
281
+ if (!autoAnswerSupported) {
282
+ return;
283
+ }
284
+ const shouldAutoAnswer = this.data.isAutoAnswering === true;
285
+ if (!shouldAutoAnswer) {
286
+ return;
287
+ }
288
+ _loggerProxy.default.info(`Auto-answering task`, {
289
+ module: _constants2.TASK_FILE,
290
+ method: 'autoAnswerIfNeeded',
291
+ interactionId: this.data.interactionId
292
+ });
293
+ try {
294
+ await this.accept();
295
+ _loggerProxy.default.info(`Task auto-answered successfully`, {
296
+ module: _constants2.TASK_FILE,
297
+ method: 'autoAnswerIfNeeded',
298
+ interactionId: this.data.interactionId
299
+ });
300
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_AUTO_ANSWER_SUCCESS, {
301
+ taskId: this.data.interactionId,
302
+ mediaType: this.data.interaction.mediaType,
303
+ isAutoAnswered: true
304
+ }, ['behavioral', 'operational']);
305
+ this.emit(_types.TASK_EVENTS.TASK_AUTO_ANSWERED, this);
306
+ } catch (error) {
307
+ this.updateTaskData({
308
+ ...this.data,
309
+ isAutoAnswering: false
310
+ });
311
+ _loggerProxy.default.error(`Failed to auto-answer task`, {
312
+ module: _constants2.TASK_FILE,
313
+ method: 'autoAnswerIfNeeded',
314
+ interactionId: this.data.interactionId,
315
+ error
316
+ });
317
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_AUTO_ANSWER_FAILED, {
318
+ taskId: this.data.interactionId,
319
+ mediaType: this.data.interaction.mediaType,
320
+ error: error?.message || 'Unknown error',
321
+ isAutoAnswered: false
322
+ }, ['behavioral', 'operational']);
323
+ }
324
+ }
325
+ updateTaskFromEvent(event) {
326
+ const taskData = Task.extractTaskDataFromEvent(event);
327
+ if (taskData) {
328
+ this.updateTaskData(taskData);
329
+ }
330
+ }
331
+ getStateMachineActionOverrides() {
332
+ return {
333
+ ...this.getCommonActionOverrides(),
334
+ ...this.getChannelSpecificActionOverrides()
335
+ };
336
+ }
337
+ getChannelSpecificActionOverrides() {
338
+ return {};
339
+ }
340
+ createEmitSelfAction(taskEvent, {
341
+ updateTaskData = false
342
+ } = {}) {
343
+ return ({
344
+ event
345
+ }) => {
346
+ if (updateTaskData) {
347
+ this.updateTaskFromEvent(event);
348
+ }
349
+ _loggerProxy.default.info(`Emitting task event ${taskEvent}`, {
350
+ module: _constants2.TASK_FILE,
351
+ method: 'emitTaskEvent',
352
+ interactionId: this.data?.interactionId
353
+ });
354
+ this.emit(taskEvent, this);
355
+ };
356
+ }
357
+ getCommonActionOverrides() {
358
+ return {
359
+ syncTaskDataFromEvent: ({
360
+ event
361
+ }) => {
362
+ this.updateTaskFromEvent(event);
363
+ },
364
+ emitTaskIncoming: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_INCOMING, {
365
+ updateTaskData: true
366
+ }),
367
+ emitTaskCampaignPreviewReservation: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_RESERVATION, {
368
+ updateTaskData: true
369
+ }),
370
+ emitTaskCampaignPreviewAcceptFailed: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_ACCEPT_FAILED),
371
+ emitTaskCampaignPreviewSkipFailed: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_SKIP_FAILED),
372
+ emitTaskCampaignPreviewRemoveFailed: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_REMOVE_FAILED),
373
+ emitTaskHydrate: ({
374
+ event
375
+ }) => {
376
+ this.updateTaskFromEvent(event);
377
+ _loggerProxy.default.info(`Emitting task event ${_types.TASK_EVENTS.TASK_HYDRATE}`, {
378
+ module: _constants2.TASK_FILE,
379
+ method: 'emitTaskEvent',
380
+ interactionId: this.data?.interactionId
381
+ });
382
+ this.emit(_types.TASK_EVENTS.TASK_HYDRATE, this);
383
+ this.onTaskHydrated();
384
+ },
385
+ emitTaskOfferContact: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_OFFER_CONTACT, {
386
+ updateTaskData: true
387
+ }),
388
+ emitTaskAssigned: ({
389
+ event
390
+ }) => {
391
+ this.updateTaskFromEvent(event);
392
+ this.emit(_types.TASK_EVENTS.TASK_ASSIGNED, this);
393
+ this.emit(_types.TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, this);
394
+ this.onTaskAssigned();
395
+ },
396
+ emitTaskEnd: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_END, {
397
+ updateTaskData: true
398
+ }),
399
+ emitTaskOfferConsult: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_OFFER_CONSULT, {
400
+ updateTaskData: true
401
+ }),
402
+ emitTaskConsultCreated: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CONSULT_CREATED, {
403
+ updateTaskData: true
404
+ }),
405
+ emitTaskConsulting: ({
406
+ event
407
+ }) => {
408
+ this.updateTaskFromEvent(event);
409
+ if (this.data.isConsulted) {
410
+ this.emit(_types.TASK_EVENTS.TASK_CONSULT_ACCEPTED, this);
411
+ } else {
412
+ this.emit(_types.TASK_EVENTS.TASK_CONSULTING, this);
413
+ }
414
+ this.emit(_types.TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, this);
415
+ },
416
+ emitTaskConsultAccepted: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CONSULT_ACCEPTED),
417
+ emitTaskConsultEnd: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CONSULT_END, {
418
+ updateTaskData: true
419
+ }),
420
+ emitTaskConsultQueueCancelled: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CONSULT_QUEUE_CANCELLED, {
421
+ updateTaskData: true
422
+ }),
423
+ emitTaskConsultQueueFailed: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_CONSULT_QUEUE_FAILED, {
424
+ updateTaskData: true
425
+ }),
426
+ emitTaskReject: ({
427
+ event
428
+ }) => {
429
+ this.updateTaskFromEvent(event);
430
+ const reason = event && typeof event === 'object' && 'reason' in event ? event.reason : undefined;
431
+ this.emit(_types.TASK_EVENTS.TASK_REJECT, reason);
432
+ },
433
+ emitTaskWrapup: ({
434
+ event
435
+ }) => {
436
+ this.updateTaskFromEvent(event);
437
+ const shouldEmitWrapup = Boolean(this.data.wrapUpRequired);
438
+ if (!shouldEmitWrapup) {
439
+ _loggerProxy.default.info(`Skipping task:wrapup event - wrapUpRequired is false`, {
440
+ module: _constants2.TASK_FILE,
441
+ method: 'emitTaskEvent',
442
+ interactionId: this.data?.interactionId
443
+ });
444
+ return;
445
+ }
446
+ _loggerProxy.default.info(`Emitting task event ${_types.TASK_EVENTS.TASK_WRAPUP}`, {
447
+ module: _constants2.TASK_FILE,
448
+ method: 'emitTaskEvent',
449
+ interactionId: this.data?.interactionId
450
+ });
451
+ this.emit(_types.TASK_EVENTS.TASK_WRAPUP, this);
452
+ },
453
+ emitTaskWrappedup: this.createEmitSelfAction(_types.TASK_EVENTS.TASK_WRAPPEDUP, {
454
+ updateTaskData: true
455
+ }),
456
+ requestAutoAnswer: ({
457
+ event
458
+ }) => {
459
+ if (event) {
460
+ // parameter intentionally unused
461
+ }
462
+ this.autoAnswerIfNeeded();
463
+ },
464
+ requestCleanup: () => {
465
+ this.emit(_types.TASK_EVENTS.TASK_CLEANUP, this, {
466
+ removeFromCollection: false
467
+ });
468
+ },
469
+ cleanupResources: () => {
470
+ this.emit(_types.TASK_EVENTS.TASK_CLEANUP, this, {
471
+ removeFromCollection: true
472
+ });
473
+ }
474
+ };
475
+ }
476
+
477
+ /**
478
+ * Sets up the automatic wrap-up timer if wrap-up is required
479
+ */
480
+ setupAutoWrapupTimer() {
481
+ if (this.data.wrapUpRequired && !this.autoWrapup && this.wrapupData && this.wrapupData.wrapUpProps) {
482
+ const wrapUpProps = this.wrapupData.wrapUpProps;
483
+ if (!wrapUpProps || wrapUpProps.autoWrapup === false) {
484
+ _loggerProxy.default.info(`Auto wrap-up is not required for this task`, {
485
+ module: _constants2.TASK_FILE,
486
+ method: _constants.METHODS.SETUP_AUTO_WRAPUP_TIMER,
487
+ interactionId: this.data.interactionId
488
+ });
489
+ return;
490
+ }
491
+ const defaultWrapupReason = wrapUpProps.wrapUpReasonList?.find(r => r.isDefault) ?? wrapUpProps.wrapUpReasonList?.[0];
492
+ if (!defaultWrapupReason) {
493
+ _loggerProxy.default.error('No wrap-up reason configured', {
494
+ module: _constants2.TASK_FILE,
495
+ method: _constants.METHODS.SETUP_AUTO_WRAPUP_TIMER
496
+ });
497
+ return;
498
+ }
499
+ const intervalMs = wrapUpProps.autoWrapupInterval;
500
+ if (!intervalMs || intervalMs <= 0) {
501
+ _loggerProxy.default.error(`Invalid auto wrap-up interval: ${intervalMs}`, {
502
+ module: _constants2.TASK_FILE,
503
+ method: _constants.METHODS.SETUP_AUTO_WRAPUP_TIMER
504
+ });
505
+ return;
506
+ }
507
+ this.autoWrapup = new _AutoWrapup.default(intervalMs, wrapUpProps.allowCancelAutoWrapup);
508
+ this.autoWrapup.start(async () => {
509
+ _loggerProxy.default.info(`Auto wrap-up timer triggered`, {
510
+ module: _constants2.TASK_FILE,
511
+ method: _constants.METHODS.SETUP_AUTO_WRAPUP_TIMER,
512
+ interactionId: this.data.interactionId
513
+ });
514
+ await this.wrapup({
515
+ wrapUpReason: defaultWrapupReason.name,
516
+ auxCodeId: defaultWrapupReason.id
517
+ });
518
+ });
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Cancels the automatic wrap-up timer if it's running
524
+ */
525
+ reconcileData(oldData, newData) {
526
+ Object.keys(newData).forEach(key => {
527
+ if (newData[key] && typeof newData[key] === 'object' && !Array.isArray(newData[key])) {
528
+ oldData[key] = this.reconcileData({
529
+ ...oldData[key]
530
+ }, newData[key]);
531
+ } else {
532
+ oldData[key] = newData[key];
533
+ }
534
+ });
535
+ return oldData;
536
+ }
537
+
538
+ /**
539
+ *
540
+ * @param methodName - The name of the method that is unsupported
541
+ * @throws Error
542
+ */
543
+ unsupportedMethodError(methodName) {
544
+ _loggerProxy.default.error(`Unsupported operation`, {
545
+ module: 'TASK',
546
+ method: methodName,
547
+ interactionId: this.data?.interactionId
548
+ });
549
+ throw new Error(`Unsupported operation: ${methodName}`);
550
+ }
551
+
552
+ /**
553
+ * This method is used to update the task data.
554
+ * @param updatedData - TaskData
555
+ * @param shouldOverwrite - boolean
556
+ * @example
557
+ * ```typescript
558
+ * task.updateTaskData(updatedData, true);
559
+ * ```
560
+ */
561
+ updateTaskData(updatedData, shouldOverwrite = false) {
562
+ this.data = shouldOverwrite ? updatedData : this.reconcileData(this.data, updatedData);
563
+ if (!shouldOverwrite) {
564
+ this.pruneStaleInteractionMaps(updatedData);
565
+ }
566
+ this.updateUiControls();
567
+ this.setupAutoWrapupTimer();
568
+ return this;
569
+ }
570
+
571
+ /**
572
+ * The backend sends `interaction.media` and `interaction.participants` as complete snapshots
573
+ * of the current call state. `reconcileData` deep-merges and never removes keys, so entries the
574
+ * backend dropped (e.g. a consult leg's media and consultee participant after the consult ends)
575
+ * linger in `this.data`. That stale data drives incorrect UI controls (e.g. the consult button
576
+ * staying disabled after the consult leg is gone, until a page refresh re-hydrates cleanly).
577
+ * Make only these two snapshot maps authoritative to the incoming payload, leaving every other
578
+ * field on the generic deep-merge path (CAD and other partial updates still merge as before).
579
+ */
580
+ pruneStaleInteractionMaps(incoming) {
581
+ const incomingInteraction = incoming?.interaction;
582
+ const currentInteraction = this.data?.interaction;
583
+ if (!incomingInteraction || !currentInteraction) {
584
+ return;
585
+ }
586
+ ['media', 'participants'].forEach(mapKey => {
587
+ const incomingMap = incomingInteraction[mapKey];
588
+ const currentMap = currentInteraction[mapKey];
589
+ if (!incomingMap || !currentMap || typeof incomingMap !== 'object') {
590
+ return;
591
+ }
592
+ Object.keys(currentMap).forEach(id => {
593
+ if (!(id in incomingMap)) {
594
+ delete currentMap[id];
595
+ }
596
+ });
597
+ });
598
+ }
599
+
600
+ /**
601
+ * This is used to blind transfer or vTeam transfer the task
602
+ * @param transferPayload
603
+ * @returns Promise<TaskResponse>
604
+ * @throws Error
605
+ * @example
606
+ * ```typescript
607
+ * const transferPayload = {
608
+ * to: 'myQueueId',
609
+ * destinationType: 'queue',
610
+ * }
611
+ * task.transfer(transferPayload).then(()=>{}).catch(()=>{});
612
+ * ```
613
+ */
614
+ async transfer(transferPayload) {
615
+ _loggerProxy.default.log(`Starting task transfer for taskId:${this.data.interactionId}`, {
616
+ module: 'Task',
617
+ method: 'transfer'
618
+ });
619
+ try {
620
+ this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED]);
621
+ let result;
622
+ const isQueueTransfer = transferPayload.destinationType === _types.DESTINATION_TYPE.QUEUE;
623
+ const isEntryPointTransfer = transferPayload.destinationType === _types.DESTINATION_TYPE.ENTRYPOINT;
624
+ if (isQueueTransfer || isEntryPointTransfer) {
625
+ result = await this.contact.vteamTransfer({
626
+ interactionId: this.data.interactionId,
627
+ data: {
628
+ ...transferPayload,
629
+ destinationType: isEntryPointTransfer ? _constants.ENTRY_POINT_TRANSFER_DESTINATION_TYPE : _types.DESTINATION_TYPE.QUEUE
630
+ }
631
+ });
632
+ } else {
633
+ result = await this.contact.blindTransfer({
634
+ interactionId: this.data.interactionId,
635
+ data: transferPayload
636
+ });
637
+ }
638
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_SUCCESS, {
639
+ taskId: this.data.interactionId,
640
+ destination: transferPayload.to,
641
+ destinationType: transferPayload.destinationType,
642
+ isConsultTransfer: false,
643
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(result)
644
+ }, ['operational', 'behavioral', 'business']);
645
+ return result;
646
+ } catch (error) {
647
+ const {
648
+ error: detailedError
649
+ } = (0, _Utils.getErrorDetails)(error, 'transfer', _constants2.CC_FILE);
650
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_TRANSFER_FAILED, {
651
+ taskId: this.data.interactionId,
652
+ destination: transferPayload.to,
653
+ destinationType: transferPayload.destinationType,
654
+ isConsultTransfer: false,
655
+ error: error.toString(),
656
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
657
+ }, ['operational', 'behavioral', 'business']);
658
+ throw detailedError;
659
+ }
660
+ }
661
+
662
+ /**
663
+ * This is used to end the task.
664
+ * @returns Promise<TaskResponse>
665
+ * @throws Error
666
+ * @example
667
+ * ```typescript
668
+ * task.end().then(()=>{}).catch(()=>{})
669
+ * ```
670
+ */
671
+ async end() {
672
+ _loggerProxy.default.log(`Ending task for taskId:${this.data.interactionId}`, {
673
+ module: 'Task',
674
+ method: 'end'
675
+ });
676
+ const requestInteractionId = this.data.interaction?.mainInteractionId || this.data.interactionId;
677
+ try {
678
+ this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_END_FAILED]);
679
+ const response = await this.contact.end({
680
+ interactionId: requestInteractionId
681
+ });
682
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_SUCCESS, {
683
+ taskId: this.data.interactionId,
684
+ requestInteractionId,
685
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
686
+ }, ['operational', 'behavioral', 'business']);
687
+ return response;
688
+ } catch (error) {
689
+ const {
690
+ error: detailedError
691
+ } = (0, _Utils.getErrorDetails)(error, 'end', _constants2.CC_FILE);
692
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_END_FAILED, {
693
+ taskId: this.data.interactionId,
694
+ requestInteractionId,
695
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
696
+ }, ['operational', 'behavioral', 'business']);
697
+ throw detailedError;
698
+ }
699
+ }
700
+
701
+ /**
702
+ * This is used to wrap up the task.
703
+ * @param wrapupPayload - WrapupPayLoad
704
+ * @returns Promise<TaskResponse>
705
+ * @throws Error
706
+ * @example
707
+ * ```typescript
708
+ * task.wrapup(wrapupPayload).then(()=>{}).catch(()=>{})
709
+ * ```
710
+ */
711
+ async wrapup(wrapupPayload) {
712
+ this.cancelAutoWrapupTimer();
713
+ _loggerProxy.default.log(`Starting task wrapup for taskId:${this.data.interactionId}`, {
714
+ module: 'Task',
715
+ method: 'wrapup'
716
+ });
717
+ try {
718
+ this.metricsManager.timeEvent([_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, _constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED]);
719
+ if (!this.data) {
720
+ throw new Error('No task data available');
721
+ }
722
+ if (!wrapupPayload.auxCodeId || wrapupPayload.auxCodeId.length === 0) {
723
+ throw new Error('AuxCodeId is required');
724
+ }
725
+ if (!wrapupPayload.wrapUpReason || wrapupPayload.wrapUpReason.length === 0) {
726
+ throw new Error('WrapUpReason is required');
727
+ }
728
+ const response = await this.contact.wrapup({
729
+ interactionId: this.data.interactionId,
730
+ data: wrapupPayload
731
+ });
732
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_SUCCESS, {
733
+ taskId: this.data.interactionId,
734
+ wrapUpCode: wrapupPayload.auxCodeId,
735
+ wrapUpReason: wrapupPayload.wrapUpReason,
736
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponse(response)
737
+ }, ['operational', 'behavioral', 'business']);
738
+ return response;
739
+ } catch (error) {
740
+ const {
741
+ error: detailedError
742
+ } = (0, _Utils.getErrorDetails)(error, 'wrapup', _constants2.CC_FILE);
743
+ this.metricsManager.trackEvent(_constants3.METRIC_EVENT_NAMES.TASK_WRAPUP_FAILED, {
744
+ taskId: this.data.interactionId,
745
+ wrapUpCode: wrapupPayload.auxCodeId,
746
+ wrapUpReason: wrapupPayload.wrapUpReason,
747
+ ..._MetricsManager.default.getCommonTrackingFieldForAQMResponseFailed(error.details || {})
748
+ }, ['operational', 'behavioral', 'business']);
749
+ throw detailedError;
750
+ }
751
+ }
752
+ }
753
+ exports.default = Task;
754
+ //# sourceMappingURL=Task.js.map