@microsoft/omnichannel-chat-sdk 1.2.1-main.8f1151a → 1.2.1-main.94ae8ab

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.
package/CHANGELOG.md CHANGED
@@ -5,9 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  ### Added
6
6
  - Add ability to use `ChatSDK.createChatAdapter()` for `DirectLine` protocol
7
7
  - Add `CreateACSAdapter` telemetry event
8
+ - Improve `ChatSDK.createChatAdapter()` with retries using exponential backoff & additional details on failures
9
+ - Add `GetAgentAvailability` SDK method for auth chat
8
10
 
9
11
  ### Fixed
10
12
  - Fix `ChatAdapterOptionalParams.ACSAdapter.options.egressMiddleware` being used as `ingressMiddleware`
13
+ - Fix `ChatSDK.onTypingEvent()` being triggered on current user typing
11
14
 
12
15
  ## [1.2.0] - 2022-11-11
13
16
  ### Added
package/README.md CHANGED
@@ -90,6 +90,7 @@ Omnichannel offers an live chat widget (LCW) by default. You can use the Chat SD
90
90
  | Persistent Chat | ✔ | ✔ |
91
91
  | Chat Reconnect | ✔ | ✔ |
92
92
  | Operating Hours | ✔ | ✔ |
93
+ | Get Agent Availability | ✔ | ✔ |
93
94
  | Queue Position | ✔ | ✔ | No SDK method. Handled as *system message* |
94
95
  | Average Wait Time | ✔ | ✔ | No SDK method. Handled as *system message* |
95
96
 
@@ -450,6 +451,14 @@ It gets post chat survey link, survey locale, and whether an agent has joined th
450
451
  const context = await chatSDK.getPostChatSurveyContext();
451
452
  ```
452
453
 
454
+ ### Get Agent Availability
455
+
456
+ It gets information on whether a queue is available, and whether there are agents available in that queue, as well as queue position and average wait time. This call only supports authenticated chat.
457
+
458
+ ```ts
459
+ const agentAvailability = await chatSDK.getAgentAvailability();
460
+ ```
461
+
453
462
  ## Common Scenarios
454
463
 
455
464
  ### Pre-Chat Survey
@@ -10,14 +10,15 @@ import ChatTranscriptBody from "./core/ChatTranscriptBody";
10
10
  import FileMetadata from "@microsoft/omnichannel-amsclient/lib/FileMetadata";
11
11
  import FramedClient from "@microsoft/omnichannel-amsclient/lib/FramedClient";
12
12
  import FramedlessClient from "@microsoft/omnichannel-amsclient/lib/FramedlessClient";
13
+ import GetAgentAvailabilityOptionalParams from "./core/GetAgentAvailabilityOptionalParams";
13
14
  import GetLiveChatConfigOptionalParams from "./core/GetLiveChatConfigOptionalParams";
14
15
  import IChatToken from "./external/IC3Adapter/IChatToken";
15
16
  import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
16
17
  import IFileMetadata from "@microsoft/omnichannel-ic3core/lib/model/IFileMetadata";
17
18
  import IMessage from "@microsoft/omnichannel-ic3core/lib/model/IMessage";
18
- import InitializeOptionalParams from "./core/InitializeOptionalParams";
19
19
  import IRawMessage from "@microsoft/omnichannel-ic3core/lib/model/IRawMessage";
20
20
  import IRawThread from "@microsoft/omnichannel-ic3core/lib/interfaces/IRawThread";
21
+ import InitializeOptionalParams from "./core/InitializeOptionalParams";
21
22
  import LiveChatContext from "./core/LiveChatContext";
22
23
  import LiveWorkItemDetails from "./core/LiveWorkItemDetails";
23
24
  import OmnichannelConfig from "./core/OmnichannelConfig";
@@ -88,6 +89,8 @@ declare class OmnichannelChatSDK {
88
89
  createChatAdapter(optionalParams?: ChatAdapterOptionalParams): Promise<unknown>;
89
90
  getVoiceVideoCalling(params?: any): Promise<any>;
90
91
  getPostChatSurveyContext(): Promise<any>;
92
+ getAgentAvailability(optionalParams?: GetAgentAvailabilityOptionalParams): Promise<any>;
93
+ private populateInitChatOptionalParam;
91
94
  private getIC3Client;
92
95
  private getChatConfig;
93
96
  private resolveIC3ClientUrl;
@@ -58,6 +58,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
58
58
  var loggers_1 = require("./utils/loggers");
59
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
60
  var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var chatAdapterCreators_1 = require("./utils/chatAdapterCreators");
61
62
  var locale_1 = require("./utils/locale");
62
63
  var WebUtils_1 = require("./utils/WebUtils");
63
64
  var platform_1 = require("./utils/platform");
@@ -67,7 +68,6 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
67
68
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
68
69
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
69
70
  var ChatSDKErrors_1 = require("./core/ChatSDKErrors");
70
- var chatAdapterCreators_1 = require("./utils/chatAdapterCreators");
71
71
  var ConversationMode_1 = require("./core/ConversationMode");
72
72
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
73
73
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
@@ -87,11 +87,13 @@ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
87
87
  var createTelemetry_1 = require("./utils/createTelemetry");
88
88
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
89
89
  var MessageTags_1 = require("./core/messaging/MessageTags");
90
+ var location_1 = require("./utils/location");
90
91
  var utilities_1 = require("./utils/utilities");
91
92
  var urlResolvers_1 = require("./utils/urlResolvers");
92
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
93
94
  var OmnichannelChatSDK = /** @class */ (function () {
94
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
96
+ var _this = this;
95
97
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
96
98
  var _a, _b, _c, _d, _e, _f, _g, _h;
97
99
  this.ACSClient = null;
@@ -110,6 +112,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
110
112
  this.isChatReconnect = false;
111
113
  this.reconnectId = null;
112
114
  this.refreshTokenTimer = null;
115
+ this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams) {
116
+ requestOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(_this.localeId);
117
+ if (optionalParams.customContext) {
118
+ requestOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
119
+ }
120
+ if (optionalParams.browser) {
121
+ requestOptionalParams.initContext.browser = optionalParams.browser;
122
+ }
123
+ if (optionalParams.os) {
124
+ requestOptionalParams.initContext.os = optionalParams.os;
125
+ }
126
+ if (optionalParams.locale) {
127
+ requestOptionalParams.initContext.locale = optionalParams.locale;
128
+ }
129
+ if (optionalParams.device) {
130
+ requestOptionalParams.initContext.device = optionalParams.device;
131
+ }
132
+ if (optionalParams.preChatResponse) {
133
+ requestOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
134
+ }
135
+ if (optionalParams.sendDefaultInitContext) {
136
+ if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
137
+ var exceptionDetails = {
138
+ response: ChatSDKErrors_1.default.UnsupportedPlatform,
139
+ message: "sendDefaultInitContext is only supported on browser"
140
+ };
141
+ console.error(exceptionDetails.message);
142
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
143
+ RequestId: _this.requestId,
144
+ ChatId: _this.chatToken.chatId,
145
+ ExceptionDetails: JSON.stringify(exceptionDetails)
146
+ });
147
+ throw new Error(exceptionDetails.response);
148
+ }
149
+ requestOptionalParams.getContext = true;
150
+ }
151
+ // Override initContext completely
152
+ if (optionalParams.initContext) {
153
+ requestOptionalParams.initContext = optionalParams.initContext;
154
+ }
155
+ if (_this.authenticatedUserToken) {
156
+ requestOptionalParams.authenticatedUserToken = _this.authenticatedUserToken;
157
+ }
158
+ if (_this.chatToken.chatId) {
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
+ requestOptionalParams.initContext.chatId = _this.chatToken.chatId;
161
+ }
162
+ return requestOptionalParams;
163
+ };
113
164
  this.debug = false;
114
165
  this.runtimeId = ocsdk_1.uuidv4();
115
166
  this.omnichannelConfig = omnichannelConfig;
@@ -308,44 +359,44 @@ var OmnichannelChatSDK = /** @class */ (function () {
308
359
  });
309
360
  };
310
361
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
311
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
362
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
312
363
  if (optionalParams === void 0) { optionalParams = {}; }
313
364
  return __awaiter(this, void 0, void 0, function () {
314
- var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _v, exceptionDetails, sessionInitOptionalParams, exceptionDetails, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _w, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _x, error_8, exceptionDetails;
365
+ var shouldReinitIC3Client, _v, reconnectableChatsParams, reconnectableChatsResponse, _w, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _x, exceptionDetails, sessionInitOptionalParams, location_2, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _y, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _z, error_8, exceptionDetails;
315
366
  var _this = this;
316
- return __generator(this, function (_y) {
317
- switch (_y.label) {
367
+ return __generator(this, function (_0) {
368
+ switch (_0.label) {
318
369
  case 0:
319
370
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
320
371
  RequestId: this.requestId
321
372
  });
322
373
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
323
374
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
324
- _t = this;
375
+ _v = this;
325
376
  return [4 /*yield*/, this.getIC3Client()];
326
377
  case 1:
327
- _t.IC3Client = _y.sent();
328
- _y.label = 2;
378
+ _v.IC3Client = _0.sent();
379
+ _0.label = 2;
329
380
  case 2:
330
381
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
331
382
  this.reconnectId = optionalParams.reconnectId;
332
383
  }
333
384
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
334
- _y.label = 3;
385
+ _0.label = 3;
335
386
  case 3:
336
- _y.trys.push([3, 5, , 6]);
387
+ _0.trys.push([3, 5, , 6]);
337
388
  reconnectableChatsParams = {
338
389
  authenticatedUserToken: this.authenticatedUserToken
339
390
  };
340
391
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
341
392
  case 4:
342
- reconnectableChatsResponse = _y.sent();
393
+ reconnectableChatsResponse = _0.sent();
343
394
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
344
395
  this.reconnectId = reconnectableChatsResponse.reconnectid;
345
396
  }
346
397
  return [3 /*break*/, 6];
347
398
  case 5:
348
- _u = _y.sent();
399
+ _w = _0.sent();
349
400
  exceptionDetails = {
350
401
  response: "OCClientGetReconnectableChatsFailed"
351
402
  };
@@ -356,7 +407,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
356
407
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
357
408
  return [4 /*yield*/, this.getConversationDetails()];
358
409
  case 7:
359
- conversationDetails = _y.sent();
410
+ conversationDetails = _0.sent();
360
411
  if (Object.keys(conversationDetails).length === 0) {
361
412
  exceptionDetails = {
362
413
  response: "InvalidConversation"
@@ -381,30 +432,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
381
432
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
382
433
  throw Error(exceptionDetails.response);
383
434
  }
384
- _y.label = 8;
435
+ _0.label = 8;
385
436
  case 8:
386
437
  if (!this.authSettings) return [3 /*break*/, 14];
387
438
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
388
439
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
389
440
  case 9:
390
- _y.sent();
391
- _y.label = 10;
441
+ _0.sent();
442
+ _0.label = 10;
392
443
  case 10:
393
444
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
394
445
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
395
446
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
396
- _y.label = 11;
447
+ _0.label = 11;
397
448
  case 11:
398
- _y.trys.push([11, 13, , 14]);
449
+ _0.trys.push([11, 13, , 14]);
399
450
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
400
451
  authenticatedUserToken: this.authenticatedUserToken,
401
452
  chatId: this.chatToken.chatId
402
453
  })];
403
454
  case 12:
404
- _y.sent();
455
+ _0.sent();
405
456
  return [3 /*break*/, 14];
406
457
  case 13:
407
- _v = _y.sent();
458
+ _x = _0.sent();
408
459
  exceptionDetails = {
409
460
  response: "OCClientValidateAuthChatRecordFailed",
410
461
  message: "InvalidAuthChatRecord"
@@ -419,8 +470,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
419
470
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
420
471
  return [4 /*yield*/, this.getChatToken(false)];
421
472
  case 15:
422
- _y.sent();
423
- _y.label = 16;
473
+ _0.sent();
474
+ _0.label = 16;
424
475
  case 16:
425
476
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
426
477
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
@@ -430,73 +481,37 @@ var OmnichannelChatSDK = /** @class */ (function () {
430
481
  sessionInitOptionalParams = {
431
482
  initContext: {}
432
483
  };
433
- sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
484
+ sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams);
485
+ sessionInitOptionalParams.initContext.isProactiveChat = !!optionalParams.isProactiveChat;
434
486
  if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
435
487
  sessionInitOptionalParams.reconnectId = this.reconnectId;
436
488
  }
437
- if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
489
+ else if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
438
490
  sessionInitOptionalParams.reconnectId = this.reconnectId;
439
491
  }
440
- if (optionalParams.customContext) {
441
- sessionInitOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
442
- }
443
- if (optionalParams.browser) {
444
- sessionInitOptionalParams.initContext.browser = optionalParams.browser;
445
- }
446
- if (optionalParams.os) {
447
- sessionInitOptionalParams.initContext.os = optionalParams.os;
448
- }
449
- if (optionalParams.locale) {
450
- sessionInitOptionalParams.initContext.locale = optionalParams.locale;
451
- }
452
- if (optionalParams.device) {
453
- sessionInitOptionalParams.initContext.device = optionalParams.device;
454
- }
455
- if (optionalParams.preChatResponse) {
456
- sessionInitOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
457
- }
458
- if (optionalParams.sendDefaultInitContext) {
459
- if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
460
- exceptionDetails = {
461
- response: ChatSDKErrors_1.default.UnsupportedPlatform,
462
- message: "sendDefaultInitContext is only supported on browser"
463
- };
464
- console.error(exceptionDetails.message);
465
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
466
- RequestId: this.requestId,
467
- ChatId: this.chatToken.chatId,
468
- ExceptionDetails: JSON.stringify(exceptionDetails)
469
- });
470
- throw new Error(exceptionDetails.response);
471
- }
472
- sessionInitOptionalParams.getContext = true;
473
- }
474
- // Override initContext completely
475
- if (optionalParams.initContext) {
476
- sessionInitOptionalParams.initContext = optionalParams.initContext;
477
- }
478
- if (this.authenticatedUserToken) {
479
- sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
480
- }
481
- if (this.chatToken.chatId) {
482
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
483
- sessionInitOptionalParams.initContext.chatId = this.chatToken.chatId;
484
- }
485
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 20];
486
- _y.label = 17;
492
+ if (!(((_l = (_k = this.liveChatConfig) === null || _k === void 0 ? void 0 : _k.LiveWSAndLiveChatEngJoin) === null || _l === void 0 ? void 0 : _l.msdyn_requestvisitorlocation) === "true")) return [3 /*break*/, 18];
493
+ return [4 /*yield*/, location_1.getLocationInfo(this.scenarioMarker, this.chatToken.chatId, this.requestId)];
487
494
  case 17:
488
- _y.trys.push([17, 19, , 20]);
489
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
495
+ location_2 = _0.sent();
496
+ sessionInitOptionalParams.initContext.latitude = location_2.latitude;
497
+ sessionInitOptionalParams.initContext.longitude = location_2.longitude;
498
+ _0.label = 18;
490
499
  case 18:
491
- _y.sent();
492
- return [3 /*break*/, 20];
500
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
501
+ _0.label = 19;
493
502
  case 19:
494
- error_3 = _y.sent();
503
+ _0.trys.push([19, 21, , 22]);
504
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
505
+ case 20:
506
+ _0.sent();
507
+ return [3 /*break*/, 22];
508
+ case 21:
509
+ error_3 = _0.sent();
495
510
  exceptionDetails = {
496
511
  response: "OCClientSessionInitFailed"
497
512
  };
498
513
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
499
- if (((_k = error_3) === null || _k === void 0 ? void 0 : _k.isAxiosError) && ((_m = (_l = error_3.response) === null || _l === void 0 ? void 0 : _l.headers) === null || _m === void 0 ? void 0 : _m.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
514
+ if (((_m = error_3) === null || _m === void 0 ? void 0 : _m.isAxiosError) && ((_p = (_o = error_3.response) === null || _o === void 0 ? void 0 : _o.headers) === null || _p === void 0 ? void 0 : _p.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
500
515
  exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
501
516
  exceptionDetails.message = 'Widget used outside of operating hours';
502
517
  console.error(exceptionDetails.message);
@@ -507,8 +522,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
507
522
  ExceptionDetails: JSON.stringify(exceptionDetails)
508
523
  });
509
524
  throw new Error(exceptionDetails.response);
510
- case 20:
511
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 31];
525
+ case 22:
526
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 33];
512
527
  chatAdapterConfig = {
513
528
  token: this.chatToken.token,
514
529
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -516,18 +531,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
516
531
  environmentUrl: this.chatToken.acsEndpoint,
517
532
  pollingInterval: 30000
518
533
  };
519
- _y.label = 21;
520
- case 21:
521
- _y.trys.push([21, 23, , 24]);
522
- return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.initialize({
534
+ _0.label = 23;
535
+ case 23:
536
+ _0.trys.push([23, 25, , 26]);
537
+ return [4 /*yield*/, ((_q = this.ACSClient) === null || _q === void 0 ? void 0 : _q.initialize({
523
538
  token: chatAdapterConfig.token,
524
539
  environmentUrl: chatAdapterConfig.environmentUrl
525
540
  }))];
526
- case 22:
527
- _y.sent();
528
- return [3 /*break*/, 24];
529
- case 23:
530
- error_4 = _y.sent();
541
+ case 24:
542
+ _0.sent();
543
+ return [3 /*break*/, 26];
544
+ case 25:
545
+ error_4 = _0.sent();
531
546
  exceptionDetails = {
532
547
  response: "ACSClientInitializeFailed"
533
548
  };
@@ -538,23 +553,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
538
553
  });
539
554
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
540
555
  return [2 /*return*/, error_4];
541
- case 24:
542
- _y.trys.push([24, 26, , 27]);
543
- _w = this;
544
- return [4 /*yield*/, ((_p = this.ACSClient) === null || _p === void 0 ? void 0 : _p.joinConversation({
556
+ case 26:
557
+ _0.trys.push([26, 28, , 29]);
558
+ _y = this;
559
+ return [4 /*yield*/, ((_r = this.ACSClient) === null || _r === void 0 ? void 0 : _r.joinConversation({
545
560
  id: chatAdapterConfig.id,
546
561
  threadId: chatAdapterConfig.threadId,
547
562
  pollingInterval: chatAdapterConfig.pollingInterval
548
563
  }))];
549
- case 25:
550
- _w.conversation = (_y.sent());
564
+ case 27:
565
+ _y.conversation = (_0.sent());
551
566
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
552
567
  RequestId: this.requestId,
553
568
  ChatId: this.chatToken.chatId
554
569
  });
555
- return [3 /*break*/, 27];
556
- case 26:
557
- error_5 = _y.sent();
570
+ return [3 /*break*/, 29];
571
+ case 28:
572
+ error_5 = _0.sent();
558
573
  exceptionDetails = {
559
574
  response: "ACSClientJoinConversationFailed"
560
575
  };
@@ -565,16 +580,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
565
580
  });
566
581
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
567
582
  throw Error(exceptionDetails.response);
568
- case 27:
569
- _y.trys.push([27, 29, , 30]);
570
- return [4 /*yield*/, ((_q = this.AMSClient) === null || _q === void 0 ? void 0 : _q.initialize({
583
+ case 29:
584
+ _0.trys.push([29, 31, , 32]);
585
+ return [4 /*yield*/, ((_s = this.AMSClient) === null || _s === void 0 ? void 0 : _s.initialize({
571
586
  chatToken: this.chatToken
572
587
  }))];
573
- case 28:
574
- _y.sent();
575
- return [3 /*break*/, 30];
576
- case 29:
577
- error_6 = _y.sent();
588
+ case 30:
589
+ _0.sent();
590
+ return [3 /*break*/, 32];
591
+ case 31:
592
+ error_6 = _0.sent();
578
593
  exceptionDetails = {
579
594
  response: "AMSClientInitializeFailed"
580
595
  };
@@ -584,19 +599,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
584
599
  ExceptionDetails: JSON.stringify(exceptionDetails)
585
600
  });
586
601
  throw Error(exceptionDetails.response);
587
- case 30: return [3 /*break*/, 37];
588
- case 31:
589
- _y.trys.push([31, 33, , 34]);
602
+ case 32: return [3 /*break*/, 39];
603
+ case 33:
604
+ _0.trys.push([33, 35, , 36]);
590
605
  return [4 /*yield*/, this.IC3Client.initialize({
591
606
  token: this.chatToken.token,
592
607
  regionGtms: this.chatToken.regionGTMS,
593
608
  visitor: true
594
609
  })];
595
- case 32:
596
- _y.sent();
597
- return [3 /*break*/, 34];
598
- case 33:
599
- error_7 = _y.sent();
610
+ case 34:
611
+ _0.sent();
612
+ return [3 /*break*/, 36];
613
+ case 35:
614
+ error_7 = _0.sent();
600
615
  exceptionDetails = {
601
616
  response: "IC3ClientInitializeFailed"
602
617
  };
@@ -607,19 +622,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
607
622
  });
608
623
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
609
624
  return [2 /*return*/, error_7];
610
- case 34:
611
- _y.trys.push([34, 36, , 37]);
612
- _x = this;
625
+ case 36:
626
+ _0.trys.push([36, 38, , 39]);
627
+ _z = this;
613
628
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
614
- case 35:
615
- _x.conversation = _y.sent();
629
+ case 37:
630
+ _z.conversation = _0.sent();
616
631
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
617
632
  RequestId: this.requestId,
618
633
  ChatId: this.chatToken.chatId
619
634
  });
620
- return [3 /*break*/, 37];
621
- case 36:
622
- error_8 = _y.sent();
635
+ return [3 /*break*/, 39];
636
+ case 38:
637
+ error_8 = _0.sent();
623
638
  exceptionDetails = {
624
639
  response: "IC3ClientJoinConversationFailed"
625
640
  };
@@ -630,8 +645,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
630
645
  });
631
646
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
632
647
  return [2 /*return*/, error_8];
633
- case 37:
634
- if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
648
+ case 39:
649
+ if (this.isPersistentChat && !((_t = this.chatSDKConfig.persistentChat) === null || _t === void 0 ? void 0 : _t.disable)) {
635
650
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
636
651
  return __generator(this, function (_a) {
637
652
  switch (_a.label) {
@@ -642,7 +657,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
642
657
  return [2 /*return*/];
643
658
  }
644
659
  });
645
- }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
660
+ }); }, (_u = this.chatSDKConfig.persistentChat) === null || _u === void 0 ? void 0 : _u.tokenUpdateTime);
646
661
  }
647
662
  return [2 /*return*/];
648
663
  }
@@ -1818,6 +1833,60 @@ var OmnichannelChatSDK = /** @class */ (function () {
1818
1833
  });
1819
1834
  });
1820
1835
  };
1836
+ OmnichannelChatSDK.prototype.getAgentAvailability = function (optionalParams) {
1837
+ if (optionalParams === void 0) { optionalParams = {}; }
1838
+ return __awaiter(this, void 0, void 0, function () {
1839
+ var reportError, getAgentAvailabilityOptionalParams, response, e_1;
1840
+ var _this = this;
1841
+ return __generator(this, function (_a) {
1842
+ switch (_a.label) {
1843
+ case 0:
1844
+ reportError = function (response, message, chatId) {
1845
+ if (chatId === void 0) { chatId = ""; }
1846
+ var exceptionDetails = {
1847
+ response: response,
1848
+ message: message
1849
+ };
1850
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1851
+ RequestId: _this.requestId,
1852
+ ExceptionDetails: JSON.stringify(exceptionDetails),
1853
+ ChatId: chatId
1854
+ });
1855
+ throw new Error(exceptionDetails.message);
1856
+ };
1857
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1858
+ RequestId: this.requestId
1859
+ });
1860
+ if (!this.authSettings) {
1861
+ reportError("Unsupported", "GetAgentAvailability is supported only for authenticated live chat widget.");
1862
+ }
1863
+ if (!this.authenticatedUserToken) {
1864
+ reportError("UndefinedAuthToken", "Missing AuthToken for GetAgentAvailability.");
1865
+ }
1866
+ if (this.conversation) {
1867
+ reportError("InvalidOperation", "GetAgentAvailability can only be called before a chat has started.", this.chatToken.chatId);
1868
+ }
1869
+ getAgentAvailabilityOptionalParams = {
1870
+ initContext: {}
1871
+ };
1872
+ getAgentAvailabilityOptionalParams = this.populateInitChatOptionalParam(getAgentAvailabilityOptionalParams, optionalParams);
1873
+ _a.label = 1;
1874
+ case 1:
1875
+ _a.trys.push([1, 3, , 4]);
1876
+ return [4 /*yield*/, this.OCClient.getAgentAvailability(this.requestId, getAgentAvailabilityOptionalParams)];
1877
+ case 2:
1878
+ response = _a.sent();
1879
+ return [2 /*return*/, response];
1880
+ case 3:
1881
+ e_1 = _a.sent();
1882
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1883
+ reportError("GetAgentAvailabilityFailed", e_1.message);
1884
+ return [3 /*break*/, 4];
1885
+ case 4: return [2 /*return*/];
1886
+ }
1887
+ });
1888
+ });
1889
+ };
1821
1890
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1822
1891
  return __awaiter(this, void 0, void 0, function () {
1823
1892
  var IC3Client;