@webex/contact-center 0.0.0-next.1

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 (177) hide show
  1. package/README.md +81 -0
  2. package/__mocks__/workerMock.js +15 -0
  3. package/babel.config.js +15 -0
  4. package/dist/cc.js +1416 -0
  5. package/dist/cc.js.map +1 -0
  6. package/dist/config.js +72 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/constants.js +58 -0
  9. package/dist/constants.js.map +1 -0
  10. package/dist/index.js +142 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/logger-proxy.js +115 -0
  13. package/dist/logger-proxy.js.map +1 -0
  14. package/dist/metrics/MetricsManager.js +474 -0
  15. package/dist/metrics/MetricsManager.js.map +1 -0
  16. package/dist/metrics/behavioral-events.js +322 -0
  17. package/dist/metrics/behavioral-events.js.map +1 -0
  18. package/dist/metrics/constants.js +134 -0
  19. package/dist/metrics/constants.js.map +1 -0
  20. package/dist/services/WebCallingService.js +323 -0
  21. package/dist/services/WebCallingService.js.map +1 -0
  22. package/dist/services/agent/index.js +177 -0
  23. package/dist/services/agent/index.js.map +1 -0
  24. package/dist/services/agent/types.js +137 -0
  25. package/dist/services/agent/types.js.map +1 -0
  26. package/dist/services/config/Util.js +203 -0
  27. package/dist/services/config/Util.js.map +1 -0
  28. package/dist/services/config/constants.js +221 -0
  29. package/dist/services/config/constants.js.map +1 -0
  30. package/dist/services/config/index.js +607 -0
  31. package/dist/services/config/index.js.map +1 -0
  32. package/dist/services/config/types.js +334 -0
  33. package/dist/services/config/types.js.map +1 -0
  34. package/dist/services/constants.js +117 -0
  35. package/dist/services/constants.js.map +1 -0
  36. package/dist/services/core/Err.js +43 -0
  37. package/dist/services/core/Err.js.map +1 -0
  38. package/dist/services/core/GlobalTypes.js +6 -0
  39. package/dist/services/core/GlobalTypes.js.map +1 -0
  40. package/dist/services/core/Utils.js +126 -0
  41. package/dist/services/core/Utils.js.map +1 -0
  42. package/dist/services/core/WebexRequest.js +96 -0
  43. package/dist/services/core/WebexRequest.js.map +1 -0
  44. package/dist/services/core/aqm-reqs.js +246 -0
  45. package/dist/services/core/aqm-reqs.js.map +1 -0
  46. package/dist/services/core/constants.js +109 -0
  47. package/dist/services/core/constants.js.map +1 -0
  48. package/dist/services/core/types.js +6 -0
  49. package/dist/services/core/types.js.map +1 -0
  50. package/dist/services/core/websocket/WebSocketManager.js +187 -0
  51. package/dist/services/core/websocket/WebSocketManager.js.map +1 -0
  52. package/dist/services/core/websocket/connection-service.js +111 -0
  53. package/dist/services/core/websocket/connection-service.js.map +1 -0
  54. package/dist/services/core/websocket/keepalive.worker.js +94 -0
  55. package/dist/services/core/websocket/keepalive.worker.js.map +1 -0
  56. package/dist/services/core/websocket/types.js +6 -0
  57. package/dist/services/core/websocket/types.js.map +1 -0
  58. package/dist/services/index.js +78 -0
  59. package/dist/services/index.js.map +1 -0
  60. package/dist/services/task/AutoWrapup.js +88 -0
  61. package/dist/services/task/AutoWrapup.js.map +1 -0
  62. package/dist/services/task/TaskManager.js +369 -0
  63. package/dist/services/task/TaskManager.js.map +1 -0
  64. package/dist/services/task/constants.js +58 -0
  65. package/dist/services/task/constants.js.map +1 -0
  66. package/dist/services/task/contact.js +464 -0
  67. package/dist/services/task/contact.js.map +1 -0
  68. package/dist/services/task/dialer.js +60 -0
  69. package/dist/services/task/dialer.js.map +1 -0
  70. package/dist/services/task/index.js +1188 -0
  71. package/dist/services/task/index.js.map +1 -0
  72. package/dist/services/task/types.js +214 -0
  73. package/dist/services/task/types.js.map +1 -0
  74. package/dist/types/cc.d.ts +676 -0
  75. package/dist/types/config.d.ts +66 -0
  76. package/dist/types/constants.d.ts +45 -0
  77. package/dist/types/index.d.ts +178 -0
  78. package/dist/types/logger-proxy.d.ts +71 -0
  79. package/dist/types/metrics/MetricsManager.d.ts +223 -0
  80. package/dist/types/metrics/behavioral-events.d.ts +29 -0
  81. package/dist/types/metrics/constants.d.ts +127 -0
  82. package/dist/types/services/WebCallingService.d.ts +1 -0
  83. package/dist/types/services/agent/index.d.ts +46 -0
  84. package/dist/types/services/agent/types.d.ts +413 -0
  85. package/dist/types/services/config/Util.d.ts +19 -0
  86. package/dist/types/services/config/constants.d.ts +203 -0
  87. package/dist/types/services/config/index.d.ts +171 -0
  88. package/dist/types/services/config/types.d.ts +1113 -0
  89. package/dist/types/services/constants.d.ts +97 -0
  90. package/dist/types/services/core/Err.d.ts +119 -0
  91. package/dist/types/services/core/GlobalTypes.d.ts +33 -0
  92. package/dist/types/services/core/Utils.d.ts +36 -0
  93. package/dist/types/services/core/WebexRequest.d.ts +22 -0
  94. package/dist/types/services/core/aqm-reqs.d.ts +16 -0
  95. package/dist/types/services/core/constants.d.ts +85 -0
  96. package/dist/types/services/core/types.d.ts +47 -0
  97. package/dist/types/services/core/websocket/WebSocketManager.d.ts +34 -0
  98. package/dist/types/services/core/websocket/connection-service.d.ts +27 -0
  99. package/dist/types/services/core/websocket/keepalive.worker.d.ts +2 -0
  100. package/dist/types/services/core/websocket/types.d.ts +37 -0
  101. package/dist/types/services/index.d.ts +52 -0
  102. package/dist/types/services/task/AutoWrapup.d.ts +40 -0
  103. package/dist/types/services/task/TaskManager.d.ts +1 -0
  104. package/dist/types/services/task/constants.d.ts +46 -0
  105. package/dist/types/services/task/contact.d.ts +59 -0
  106. package/dist/types/services/task/dialer.d.ts +28 -0
  107. package/dist/types/services/task/index.d.ts +569 -0
  108. package/dist/types/services/task/types.d.ts +1041 -0
  109. package/dist/types/types.d.ts +452 -0
  110. package/dist/types/webex-config.d.ts +53 -0
  111. package/dist/types/webex.d.ts +7 -0
  112. package/dist/types.js +292 -0
  113. package/dist/types.js.map +1 -0
  114. package/dist/webex-config.js +60 -0
  115. package/dist/webex-config.js.map +1 -0
  116. package/dist/webex.js +99 -0
  117. package/dist/webex.js.map +1 -0
  118. package/jest.config.js +45 -0
  119. package/package.json +83 -0
  120. package/src/cc.ts +1618 -0
  121. package/src/config.ts +65 -0
  122. package/src/constants.ts +51 -0
  123. package/src/index.ts +220 -0
  124. package/src/logger-proxy.ts +110 -0
  125. package/src/metrics/MetricsManager.ts +512 -0
  126. package/src/metrics/behavioral-events.ts +332 -0
  127. package/src/metrics/constants.ts +135 -0
  128. package/src/services/WebCallingService.ts +351 -0
  129. package/src/services/agent/index.ts +149 -0
  130. package/src/services/agent/types.ts +440 -0
  131. package/src/services/config/Util.ts +261 -0
  132. package/src/services/config/constants.ts +249 -0
  133. package/src/services/config/index.ts +743 -0
  134. package/src/services/config/types.ts +1117 -0
  135. package/src/services/constants.ts +111 -0
  136. package/src/services/core/Err.ts +126 -0
  137. package/src/services/core/GlobalTypes.ts +34 -0
  138. package/src/services/core/Utils.ts +132 -0
  139. package/src/services/core/WebexRequest.ts +103 -0
  140. package/src/services/core/aqm-reqs.ts +272 -0
  141. package/src/services/core/constants.ts +106 -0
  142. package/src/services/core/types.ts +48 -0
  143. package/src/services/core/websocket/WebSocketManager.ts +196 -0
  144. package/src/services/core/websocket/connection-service.ts +142 -0
  145. package/src/services/core/websocket/keepalive.worker.js +88 -0
  146. package/src/services/core/websocket/types.ts +40 -0
  147. package/src/services/index.ts +71 -0
  148. package/src/services/task/AutoWrapup.ts +86 -0
  149. package/src/services/task/TaskManager.ts +420 -0
  150. package/src/services/task/constants.ts +52 -0
  151. package/src/services/task/contact.ts +429 -0
  152. package/src/services/task/dialer.ts +52 -0
  153. package/src/services/task/index.ts +1375 -0
  154. package/src/services/task/types.ts +1113 -0
  155. package/src/types.ts +639 -0
  156. package/src/webex-config.ts +54 -0
  157. package/src/webex.js +96 -0
  158. package/test/unit/spec/cc.ts +1985 -0
  159. package/test/unit/spec/metrics/MetricsManager.ts +491 -0
  160. package/test/unit/spec/metrics/behavioral-events.ts +102 -0
  161. package/test/unit/spec/services/WebCallingService.ts +416 -0
  162. package/test/unit/spec/services/agent/index.ts +65 -0
  163. package/test/unit/spec/services/config/index.ts +1035 -0
  164. package/test/unit/spec/services/core/Utils.ts +279 -0
  165. package/test/unit/spec/services/core/WebexRequest.ts +144 -0
  166. package/test/unit/spec/services/core/aqm-reqs.ts +570 -0
  167. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +378 -0
  168. package/test/unit/spec/services/core/websocket/connection-service.ts +178 -0
  169. package/test/unit/spec/services/task/TaskManager.ts +1351 -0
  170. package/test/unit/spec/services/task/contact.ts +204 -0
  171. package/test/unit/spec/services/task/dialer.ts +157 -0
  172. package/test/unit/spec/services/task/index.ts +1474 -0
  173. package/tsconfig.json +6 -0
  174. package/typedoc.json +37 -0
  175. package/typedoc.md +240 -0
  176. package/umd/contact-center.min.js +3 -0
  177. package/umd/contact-center.min.js.map +1 -0
@@ -0,0 +1,351 @@
1
+ import EventEmitter from 'events';
2
+ import {
3
+ createClient,
4
+ ICall,
5
+ ICallingClient,
6
+ ILine,
7
+ LINE_EVENTS,
8
+ ServiceIndicator,
9
+ LocalMicrophoneStream,
10
+ CALL_EVENT_KEYS,
11
+ LOGGER,
12
+ } from '@webex/calling';
13
+ import {LoginOption, WebexSDK} from '../types';
14
+ import {TIMEOUT_DURATION, WEB_CALLING_SERVICE_FILE} from '../constants';
15
+ import LoggerProxy from '../logger-proxy';
16
+ import {
17
+ DEFAULT_RTMS_DOMAIN,
18
+ POST_AUTH,
19
+ WCC_CALLING_RTMS_DOMAIN,
20
+ DEREGISTER_WEBCALLING_LINE_MSG,
21
+ METHODS,
22
+ } from './constants';
23
+
24
+ /**
25
+ * WebCallingService provides WebRTC calling functionality for Contact Center agents.
26
+ * It handles registration, call management, and media operations for voice interactions.
27
+ * @internal
28
+ */
29
+ export default class WebCallingService extends EventEmitter {
30
+ /**
31
+ * The CallingClient instance that manages WebRTC calling capabilities
32
+ * @private
33
+ */
34
+ private callingClient: ICallingClient;
35
+
36
+ /**
37
+ * The Line instance that handles registration and incoming calls
38
+ * @private
39
+ */
40
+ private line: ILine;
41
+
42
+ /**
43
+ * The current active call instance
44
+ * @private
45
+ */
46
+ private call: ICall | undefined;
47
+
48
+ /**
49
+ * Reference to the WebexSDK instance
50
+ * @private
51
+ */
52
+ private webex: WebexSDK;
53
+
54
+ /**
55
+ * The login option selected for this session
56
+ * @private
57
+ */
58
+ public loginOption: LoginOption;
59
+
60
+ /**
61
+ * Map that associates call IDs with task IDs for correlation
62
+ * @private
63
+ */
64
+ private callTaskMap: Map<string, string>;
65
+
66
+ /**
67
+ * Creates an instance of WebCallingService.
68
+ * @param {WebexSDK} webex - The Webex SDK instance
69
+ */
70
+ constructor(webex: WebexSDK) {
71
+ super();
72
+ this.webex = webex;
73
+ this.callTaskMap = new Map();
74
+ }
75
+
76
+ /**
77
+ * Sets the login option for the current session
78
+ * @param {LoginOption} loginOption - The login option to use
79
+ * @private
80
+ */
81
+ public setLoginOption(loginOption: LoginOption): void {
82
+ this.loginOption = loginOption;
83
+ }
84
+
85
+ /**
86
+ * Handles remote media track events from the call
87
+ * @param {MediaStreamTrack} track - The media track received
88
+ * @private
89
+ */
90
+ private handleMediaEvent = (track: MediaStreamTrack): void => {
91
+ this.emit(CALL_EVENT_KEYS.REMOTE_MEDIA, track);
92
+ };
93
+
94
+ /**
95
+ * Handles disconnect events from the call
96
+ * @private
97
+ */
98
+ private handleDisconnectEvent = (): void => {
99
+ this.call.end();
100
+ this.cleanUpCall();
101
+ };
102
+
103
+ /**
104
+ * Registers event listeners for the current call
105
+ * @private
106
+ */
107
+ private registerCallListeners(): void {
108
+ // TODO: Add remaining call listeners here
109
+ this.call.on(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleMediaEvent);
110
+ this.call.on(CALL_EVENT_KEYS.DISCONNECT, this.handleDisconnectEvent);
111
+ }
112
+
113
+ /**
114
+ * Cleans up resources associated with the current call
115
+ * Removes event listeners and clears the call-task mapping
116
+ * @private
117
+ */
118
+ public cleanUpCall(): void {
119
+ if (this.call) {
120
+ this.call.off(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleMediaEvent);
121
+ this.call.off(CALL_EVENT_KEYS.DISCONNECT, this.handleDisconnectEvent);
122
+ const callId = this.call.getCallId();
123
+ const taskId = this.getTaskIdForCall(callId);
124
+
125
+ if (taskId) {
126
+ this.callTaskMap.delete(callId);
127
+ }
128
+ this.call = null;
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Retrieves the RTMS domain to use for WebRTC connections
134
+ * First tries to get it from the service catalog, then falls back to default
135
+ * @private
136
+ * @returns {Promise<string>} The RTMS domain to use
137
+ */
138
+ private async getRTMSDomain(): Promise<string> {
139
+ await this.webex.internal.services.waitForCatalog(POST_AUTH);
140
+
141
+ const rtmsURL = this.webex.internal.services.get(WCC_CALLING_RTMS_DOMAIN);
142
+
143
+ try {
144
+ const url = new URL(rtmsURL);
145
+
146
+ return url.hostname;
147
+ } catch (error) {
148
+ LoggerProxy.error(
149
+ `Invalid URL from u2c catalogue: ${rtmsURL} so falling back to default domain`,
150
+ {
151
+ module: WEB_CALLING_SERVICE_FILE,
152
+ method: METHODS.GET_RTMS_DOMAIN,
153
+ }
154
+ );
155
+
156
+ return DEFAULT_RTMS_DOMAIN;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Registers the WebCalling line for receiving calls
162
+ * Sets up event listeners for line events and initializes the calling client
163
+ *
164
+ * @private
165
+ * @returns {Promise<void>} A promise that resolves when registration is complete
166
+ * @throws {Error} When registration times out
167
+ */
168
+ public async registerWebCallingLine(): Promise<void> {
169
+ const rtmsDomain = await this.getRTMSDomain(); // get the RTMS domain from the u2c catalogue
170
+
171
+ const callingClientConfig = {
172
+ logger: {
173
+ level: LOGGER.INFO,
174
+ },
175
+ serviceData: {
176
+ indicator: ServiceIndicator.CONTACT_CENTER,
177
+ domain: rtmsDomain,
178
+ },
179
+ };
180
+
181
+ this.callingClient = await createClient(this.webex as any, callingClientConfig);
182
+ this.line = Object.values(this.callingClient.getLines())[0];
183
+
184
+ this.line.on(LINE_EVENTS.UNREGISTERED, () => {
185
+ LoggerProxy.log(`WxCC-SDK: Desktop unregistered successfully`, {
186
+ module: WEB_CALLING_SERVICE_FILE,
187
+ method: METHODS.REGISTER_WEB_CALLING_LINE,
188
+ });
189
+ });
190
+
191
+ // Start listening for incoming calls
192
+ this.line.on(LINE_EVENTS.INCOMING_CALL, (call: ICall) => {
193
+ this.call = call;
194
+ this.emit(LINE_EVENTS.INCOMING_CALL, call);
195
+ });
196
+
197
+ return new Promise<void>((resolve, reject) => {
198
+ const timeout = setTimeout(() => {
199
+ reject(new Error('WebCallingService Registration timed out'));
200
+ }, TIMEOUT_DURATION);
201
+
202
+ this.line.on(LINE_EVENTS.REGISTERED, (deviceInfo: ILine) => {
203
+ clearTimeout(timeout);
204
+ LoggerProxy.log(
205
+ `WxCC-SDK: Desktop registered successfully, mobiusDeviceId: ${deviceInfo.mobiusDeviceId}`,
206
+ {module: WEB_CALLING_SERVICE_FILE, method: METHODS.REGISTER_WEB_CALLING_LINE}
207
+ );
208
+ resolve();
209
+ });
210
+ this.line.register();
211
+ });
212
+ }
213
+
214
+ /**
215
+ * Deregisters the WebCalling line
216
+ * Cleans up any active calls and deregisters from the calling service
217
+ *
218
+ * @private
219
+ * @returns {Promise<void>} A promise that resolves when deregistration is complete
220
+ */
221
+ public async deregisterWebCallingLine(): Promise<void> {
222
+ LoggerProxy.log(DEREGISTER_WEBCALLING_LINE_MSG, {
223
+ module: WEB_CALLING_SERVICE_FILE,
224
+ method: METHODS.DEREGISTER_WEB_CALLING_LINE,
225
+ });
226
+ this.cleanUpCall();
227
+ this.line?.deregister();
228
+ }
229
+
230
+ /**
231
+ * Answers an incoming call with the provided audio stream
232
+ *
233
+ * @private
234
+ * @param {LocalMicrophoneStream} localAudioStream - The local microphone stream to use
235
+ * @param {string} taskId - The task ID associated with this call
236
+ * @throws {Error} If answering the call fails
237
+ */
238
+ public answerCall(localAudioStream: LocalMicrophoneStream, taskId: string): void {
239
+ if (this.call) {
240
+ try {
241
+ LoggerProxy.info(`Call answered: ${taskId}`, {
242
+ module: WEB_CALLING_SERVICE_FILE,
243
+ method: METHODS.ANSWER_CALL,
244
+ });
245
+ this.call.answer(localAudioStream);
246
+ this.registerCallListeners();
247
+ } catch (error) {
248
+ LoggerProxy.error(`Failed to answer call for ${taskId}. Error: ${error}`, {
249
+ module: WEB_CALLING_SERVICE_FILE,
250
+ method: METHODS.ANSWER_CALL,
251
+ });
252
+ // Optionally, throw the error to allow the invoker to handle it
253
+ throw error;
254
+ }
255
+ } else {
256
+ LoggerProxy.log(`Cannot answer a non WebRtc Call: ${taskId}`, {
257
+ module: WEB_CALLING_SERVICE_FILE,
258
+ method: METHODS.ANSWER_CALL,
259
+ });
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Toggles the mute state of the current call
265
+ *
266
+ * @private
267
+ * @param {LocalMicrophoneStream} localAudioStream - The local microphone stream to control
268
+ */
269
+ public muteUnmuteCall(localAudioStream: LocalMicrophoneStream): void {
270
+ if (this.call) {
271
+ LoggerProxy.info('Call mute or unmute requested!', {
272
+ module: WEB_CALLING_SERVICE_FILE,
273
+ method: METHODS.MUTE_UNMUTE_CALL,
274
+ });
275
+ this.call.mute(localAudioStream);
276
+ } else {
277
+ LoggerProxy.log(`Cannot mute a non WebRtc Call`, {
278
+ module: WEB_CALLING_SERVICE_FILE,
279
+ method: METHODS.MUTE_UNMUTE_CALL,
280
+ });
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Checks if the current call is muted
286
+ *
287
+ * @private
288
+ * @returns {boolean} True if the call is muted, false otherwise or if no call exists
289
+ */
290
+ public isCallMuted(): boolean {
291
+ if (this.call) {
292
+ return this.call.isMuted();
293
+ }
294
+
295
+ return false;
296
+ }
297
+
298
+ /**
299
+ * Declines or ends the current call
300
+ *
301
+ * @private
302
+ * @param {string} taskId - The task ID associated with this call
303
+ * @throws {Error} If ending the call fails
304
+ */
305
+ public declineCall(taskId: string): void {
306
+ if (this.call) {
307
+ try {
308
+ LoggerProxy.info(`Call end requested: ${taskId}`, {
309
+ module: WEB_CALLING_SERVICE_FILE,
310
+ method: METHODS.DECLINE_CALL,
311
+ });
312
+ this.call.end();
313
+ this.cleanUpCall();
314
+ } catch (error) {
315
+ LoggerProxy.error(`Failed to end call: ${taskId}. Error: ${error}`, {
316
+ module: WEB_CALLING_SERVICE_FILE,
317
+ method: METHODS.DECLINE_CALL,
318
+ });
319
+ // Optionally, throw the error to allow the invoker to handle it
320
+ throw error;
321
+ }
322
+ } else {
323
+ LoggerProxy.log(`Cannot end a non WebRtc Call: ${taskId}`, {
324
+ module: WEB_CALLING_SERVICE_FILE,
325
+ method: METHODS.DECLINE_CALL,
326
+ });
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Maps a call ID to a task ID for correlation
332
+ *
333
+ * @private
334
+ * @param {string} callId - The unique call identifier
335
+ * @param {string} taskId - The associated task identifier
336
+ */
337
+ public mapCallToTask(callId: string, taskId: string): void {
338
+ this.callTaskMap.set(callId, taskId);
339
+ }
340
+
341
+ /**
342
+ * Gets the task ID associated with a call ID
343
+ *
344
+ * @private
345
+ * @param {string} callId - The call ID to look up
346
+ * @returns {string|undefined} The associated task ID or undefined if not found
347
+ */
348
+ public getTaskIdForCall(callId: string): string | undefined {
349
+ return this.callTaskMap.get(callId);
350
+ }
351
+ }
@@ -0,0 +1,149 @@
1
+ import * as Err from '../core/Err';
2
+ import {createErrDetailsObject as err} from '../core/Utils';
3
+ import * as Agent from './types';
4
+ import AqmReqs from '../core/aqm-reqs';
5
+ import {HTTP_METHODS} from '../../types';
6
+ import {WCC_API_GATEWAY} from '../constants';
7
+ import {CC_EVENTS} from '../config/types';
8
+
9
+ /**
10
+ * Agent Service provides methods to manage agent states and operations
11
+ * @param routing - AqmReqs instance for making API requests
12
+ * @ignore
13
+ */
14
+ export default function routingAgent(routing: AqmReqs) {
15
+ return {
16
+ /**
17
+ * Reloads the agent session
18
+ * @public
19
+ */
20
+ reload: routing.reqEmpty(() => ({
21
+ host: WCC_API_GATEWAY,
22
+ url: '/v1/agents/reload',
23
+ data: {},
24
+ err,
25
+ notifSuccess: {
26
+ bind: {
27
+ type: CC_EVENTS.AGENT_RELOGIN_SUCCESS,
28
+ data: {type: CC_EVENTS.AGENT_RELOGIN_SUCCESS},
29
+ },
30
+ msg: {} as Agent.ReloginSuccess,
31
+ },
32
+ notifFail: {
33
+ bind: {
34
+ type: CC_EVENTS.AGENT_RELOGIN_FAILED,
35
+ data: {type: CC_EVENTS.AGENT_RELOGIN_FAILED},
36
+ },
37
+ errId: 'Service.aqm.agent.reload',
38
+ },
39
+ })),
40
+ /**
41
+ * Logs out the agent
42
+ * @param p.data - Logout parameters
43
+ * @public
44
+ */
45
+ logout: routing.req((p: {data: Agent.Logout}) => ({
46
+ url: '/v1/agents/logout',
47
+ host: WCC_API_GATEWAY,
48
+ data: p.data,
49
+ err,
50
+ notifSuccess: {
51
+ bind: {
52
+ type: CC_EVENTS.AGENT_LOGOUT,
53
+ data: {type: CC_EVENTS.AGENT_LOGOUT_SUCCESS},
54
+ },
55
+ msg: {} as Agent.LogoutSuccess,
56
+ },
57
+ notifFail: {
58
+ bind: {
59
+ type: CC_EVENTS.AGENT_LOGOUT,
60
+ data: {type: CC_EVENTS.AGENT_LOGOUT_FAILED},
61
+ },
62
+ errId: 'Service.aqm.agent.logout',
63
+ },
64
+ })),
65
+ /**
66
+ * Logs in the agent to a station
67
+ * @param p.data - Station login parameters
68
+ * @public
69
+ */
70
+ stationLogin: routing.req((p: {data: Agent.UserStationLogin}) => ({
71
+ url: '/v1/agents/login',
72
+ host: WCC_API_GATEWAY,
73
+ data: p.data,
74
+ err: /* istanbul ignore next */ (e: any) => {
75
+ return new Err.Details('Service.aqm.agent.stationLogin', {
76
+ status: e.response?.status ?? 0,
77
+ type: e.response?.data?.errorType,
78
+ trackingId: e.response?.headers?.trackingid?.split('_')[1],
79
+ });
80
+ },
81
+ notifSuccess: {
82
+ bind: {
83
+ type: CC_EVENTS.AGENT_STATION_LOGIN,
84
+ data: {type: CC_EVENTS.AGENT_STATION_LOGIN_SUCCESS},
85
+ },
86
+ msg: {} as Agent.StationLoginSuccess,
87
+ },
88
+ notifFail: {
89
+ bind: {
90
+ type: CC_EVENTS.AGENT_STATION_LOGIN,
91
+ data: {type: CC_EVENTS.AGENT_STATION_LOGIN_FAILED},
92
+ },
93
+ errId: 'Service.aqm.agent.stationLoginFailed',
94
+ },
95
+ })),
96
+ /**
97
+ * Changes the agent's state
98
+ * @param p.data - State change parameters
99
+ * @public
100
+ */
101
+ stateChange: routing.req((p: {data: Agent.StateChange}) => ({
102
+ url: '/v1/agents/session/state',
103
+ host: WCC_API_GATEWAY,
104
+ data: p.data,
105
+ err,
106
+ method: HTTP_METHODS.PUT,
107
+ notifSuccess: {
108
+ bind: {
109
+ type: CC_EVENTS.AGENT_STATE_CHANGE,
110
+ data: {type: CC_EVENTS.AGENT_STATE_CHANGE_SUCCESS},
111
+ },
112
+ msg: {} as Agent.StateChangeSuccess,
113
+ },
114
+ notifFail: {
115
+ bind: {
116
+ type: CC_EVENTS.AGENT_STATE_CHANGE,
117
+ data: {type: CC_EVENTS.AGENT_STATE_CHANGE_FAILED},
118
+ },
119
+ errId: 'Service.aqm.agent.stateChange',
120
+ },
121
+ })),
122
+ /**
123
+ * Retrieves list of buddy agents
124
+ * @param p.data - Buddy agent query parameters
125
+ * @public
126
+ */
127
+ buddyAgents: routing.req((p: {data: Agent.BuddyAgents}) => ({
128
+ url: `/v1/agents/buddyList`,
129
+ host: WCC_API_GATEWAY,
130
+ data: {...p.data},
131
+ err,
132
+ method: HTTP_METHODS.POST,
133
+ notifSuccess: {
134
+ bind: {
135
+ type: CC_EVENTS.AGENT_BUDDY_AGENTS,
136
+ data: {type: CC_EVENTS.AGENT_BUDDY_AGENTS_SUCCESS},
137
+ },
138
+ msg: {} as Agent.BuddyAgentsSuccess,
139
+ },
140
+ notifFail: {
141
+ bind: {
142
+ type: CC_EVENTS.AGENT_BUDDY_AGENTS,
143
+ data: {type: CC_EVENTS.AGENT_BUDDY_AGENTS_RETRIEVE_FAILED},
144
+ },
145
+ errId: 'Service.aqm.agent.BuddyAgentsRetrieveFailed',
146
+ },
147
+ })),
148
+ };
149
+ }