@microsoft/omnichannel-chat-sdk 1.2.1-main.5f9a9de → 1.2.1-main.7251853

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 (40) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +16 -1
  3. package/lib/OmnichannelChatSDK.d.ts +5 -1
  4. package/lib/OmnichannelChatSDK.js +213 -135
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/core/ChatSDKErrors.d.ts +2 -0
  7. package/lib/core/ChatSDKErrors.js +2 -0
  8. package/lib/core/ChatSDKErrors.js.map +1 -1
  9. package/lib/core/ChatSDKExceptionDetails.d.ts +1 -0
  10. package/lib/core/GetAgentAvailabilityOptionalParams.d.ts +12 -0
  11. package/lib/core/GetAgentAvailabilityOptionalParams.js +3 -0
  12. package/lib/core/GetAgentAvailabilityOptionalParams.js.map +1 -0
  13. package/lib/core/StartChatOptionalParams.d.ts +3 -0
  14. package/lib/core/messaging/ACSClient.js +5 -0
  15. package/lib/core/messaging/ACSClient.js.map +1 -1
  16. package/lib/telemetry/AriaTelemetry.d.ts +1 -0
  17. package/lib/telemetry/AriaTelemetry.js +49 -0
  18. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  19. package/lib/telemetry/ScenarioType.d.ts +1 -0
  20. package/lib/telemetry/ScenarioType.js +1 -0
  21. package/lib/telemetry/ScenarioType.js.map +1 -1
  22. package/lib/telemetry/TelemetryEvent.d.ts +3 -1
  23. package/lib/telemetry/TelemetryEvent.js +2 -0
  24. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  25. package/lib/tsconfig.tsbuildinfo +167 -93
  26. package/lib/utils/WebUtils.d.ts +2 -2
  27. package/lib/utils/WebUtils.js +30 -4
  28. package/lib/utils/WebUtils.js.map +1 -1
  29. package/lib/utils/chatAdapterCreators.js +68 -31
  30. package/lib/utils/chatAdapterCreators.js.map +1 -1
  31. package/lib/utils/location.d.ts +7 -0
  32. package/lib/utils/location.js +96 -0
  33. package/lib/utils/location.js.map +1 -0
  34. package/lib/utils/loggers.d.ts +16 -0
  35. package/lib/utils/loggers.js +69 -1
  36. package/lib/utils/loggers.js.map +1 -1
  37. package/lib/utils/sleep.d.ts +2 -0
  38. package/lib/utils/sleep.js +5 -0
  39. package/lib/utils/sleep.js.map +1 -0
  40. package/package.json +3 -3
@@ -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,13 +87,15 @@ 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
- var _a, _b, _c, _d, _e, _f, _g, _h;
98
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
97
99
  this.ACSClient = null;
98
100
  this.AMSClient = null;
99
101
  this.authSettings = null;
@@ -106,10 +108,60 @@ var OmnichannelChatSDK = /** @class */ (function () {
106
108
  this.acsClientLogger = null;
107
109
  this.acsAdapterLogger = null;
108
110
  this.callingSdkLogger = null;
111
+ this.amsClientLogger = null;
109
112
  this.isPersistentChat = false;
110
113
  this.isChatReconnect = false;
111
114
  this.reconnectId = null;
112
115
  this.refreshTokenTimer = null;
116
+ this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams) {
117
+ requestOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(_this.localeId);
118
+ if (optionalParams.customContext) {
119
+ requestOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
120
+ }
121
+ if (optionalParams.browser) {
122
+ requestOptionalParams.initContext.browser = optionalParams.browser;
123
+ }
124
+ if (optionalParams.os) {
125
+ requestOptionalParams.initContext.os = optionalParams.os;
126
+ }
127
+ if (optionalParams.locale) {
128
+ requestOptionalParams.initContext.locale = optionalParams.locale;
129
+ }
130
+ if (optionalParams.device) {
131
+ requestOptionalParams.initContext.device = optionalParams.device;
132
+ }
133
+ if (optionalParams.preChatResponse) {
134
+ requestOptionalParams.initContext.preChatResponse = optionalParams.preChatResponse;
135
+ }
136
+ if (optionalParams.sendDefaultInitContext) {
137
+ if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
138
+ var exceptionDetails = {
139
+ response: ChatSDKErrors_1.default.UnsupportedPlatform,
140
+ message: "sendDefaultInitContext is only supported on browser"
141
+ };
142
+ console.error(exceptionDetails.message);
143
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
144
+ RequestId: _this.requestId,
145
+ ChatId: _this.chatToken.chatId,
146
+ ExceptionDetails: JSON.stringify(exceptionDetails)
147
+ });
148
+ throw new Error(exceptionDetails.response);
149
+ }
150
+ requestOptionalParams.getContext = true;
151
+ }
152
+ // Override initContext completely
153
+ if (optionalParams.initContext) {
154
+ requestOptionalParams.initContext = optionalParams.initContext;
155
+ }
156
+ if (_this.authenticatedUserToken) {
157
+ requestOptionalParams.authenticatedUserToken = _this.authenticatedUserToken;
158
+ }
159
+ if (_this.chatToken.chatId) {
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ requestOptionalParams.initContext.chatId = _this.chatToken.chatId;
162
+ }
163
+ return requestOptionalParams;
164
+ };
113
165
  this.debug = false;
114
166
  this.runtimeId = ocsdk_1.uuidv4();
115
167
  this.omnichannelConfig = omnichannelConfig;
@@ -131,18 +183,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
131
183
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
132
184
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
133
185
  this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
186
+ this.amsClientLogger = loggers_1.createAMSClientLogger(this.omnichannelConfig);
134
187
  this.scenarioMarker.useTelemetry(this.telemetry);
135
188
  this.ic3ClientLogger.useTelemetry(this.telemetry);
136
189
  this.ocSdkLogger.useTelemetry(this.telemetry);
137
190
  this.acsClientLogger.useTelemetry(this.telemetry);
138
191
  this.acsAdapterLogger.useTelemetry(this.telemetry);
139
192
  this.callingSdkLogger.useTelemetry(this.telemetry);
193
+ this.amsClientLogger.useTelemetry(this.telemetry);
140
194
  this.scenarioMarker.setRuntimeId(this.runtimeId);
141
195
  this.ic3ClientLogger.setRuntimeId(this.runtimeId);
142
196
  this.ocSdkLogger.setRuntimeId(this.runtimeId);
143
197
  this.acsClientLogger.setRuntimeId(this.runtimeId);
144
198
  this.acsAdapterLogger.setRuntimeId(this.runtimeId);
145
199
  this.callingSdkLogger.setRuntimeId(this.runtimeId);
200
+ this.amsClientLogger.setRuntimeId(this.runtimeId);
146
201
  OmnichannelConfigValidator_1.default(omnichannelConfig);
147
202
  SDKConfigValidators_1.default(chatSDKConfig);
148
203
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -154,10 +209,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
154
209
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
155
210
  (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
156
211
  (_h = this.callingSdkLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
212
+ (_j = this.amsClientLogger) === null || _j === void 0 ? void 0 : _j.setRequestId(this.requestId);
157
213
  }
158
214
  /* istanbul ignore next */
159
215
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
160
- var _a, _b, _c, _d, _e, _f, _g;
216
+ var _a, _b, _c, _d, _e, _f, _g, _h;
161
217
  this.debug = flag;
162
218
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
163
219
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -167,6 +223,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
167
223
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
168
224
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
169
225
  (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setDebug(flag);
226
+ (_h = this.amsClientLogger) === null || _h === void 0 ? void 0 : _h.setDebug(flag);
170
227
  };
171
228
  OmnichannelChatSDK.prototype.initialize = function (optionalParams) {
172
229
  if (optionalParams === void 0) { optionalParams = {}; }
@@ -199,7 +256,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
199
256
  framedMode: platform_1.isBrowser(),
200
257
  multiClient: true,
201
258
  debug: false,
202
- logger: undefined
259
+ logger: this.amsClientLogger
203
260
  })];
204
261
  case 4:
205
262
  _b.AMSClient = _e.sent();
@@ -308,44 +365,44 @@ var OmnichannelChatSDK = /** @class */ (function () {
308
365
  });
309
366
  };
310
367
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
311
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
368
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
312
369
  if (optionalParams === void 0) { optionalParams = {}; }
313
370
  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;
371
+ var shouldReinitIC3Client, _w, reconnectableChatsParams, reconnectableChatsResponse, _x, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _y, exceptionDetails, sessionInitOptionalParams, location_2, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _z, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _0, error_8, exceptionDetails;
315
372
  var _this = this;
316
- return __generator(this, function (_y) {
317
- switch (_y.label) {
373
+ return __generator(this, function (_1) {
374
+ switch (_1.label) {
318
375
  case 0:
319
376
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
320
377
  RequestId: this.requestId
321
378
  });
322
379
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
323
380
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
324
- _t = this;
381
+ _w = this;
325
382
  return [4 /*yield*/, this.getIC3Client()];
326
383
  case 1:
327
- _t.IC3Client = _y.sent();
328
- _y.label = 2;
384
+ _w.IC3Client = _1.sent();
385
+ _1.label = 2;
329
386
  case 2:
330
387
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
331
388
  this.reconnectId = optionalParams.reconnectId;
332
389
  }
333
390
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
334
- _y.label = 3;
391
+ _1.label = 3;
335
392
  case 3:
336
- _y.trys.push([3, 5, , 6]);
393
+ _1.trys.push([3, 5, , 6]);
337
394
  reconnectableChatsParams = {
338
395
  authenticatedUserToken: this.authenticatedUserToken
339
396
  };
340
397
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
341
398
  case 4:
342
- reconnectableChatsResponse = _y.sent();
399
+ reconnectableChatsResponse = _1.sent();
343
400
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
344
401
  this.reconnectId = reconnectableChatsResponse.reconnectid;
345
402
  }
346
403
  return [3 /*break*/, 6];
347
404
  case 5:
348
- _u = _y.sent();
405
+ _x = _1.sent();
349
406
  exceptionDetails = {
350
407
  response: "OCClientGetReconnectableChatsFailed"
351
408
  };
@@ -356,7 +413,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
356
413
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
357
414
  return [4 /*yield*/, this.getConversationDetails()];
358
415
  case 7:
359
- conversationDetails = _y.sent();
416
+ conversationDetails = _1.sent();
360
417
  if (Object.keys(conversationDetails).length === 0) {
361
418
  exceptionDetails = {
362
419
  response: "InvalidConversation"
@@ -381,30 +438,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
381
438
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
382
439
  throw Error(exceptionDetails.response);
383
440
  }
384
- _y.label = 8;
441
+ _1.label = 8;
385
442
  case 8:
386
443
  if (!this.authSettings) return [3 /*break*/, 14];
387
444
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
388
445
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
389
446
  case 9:
390
- _y.sent();
391
- _y.label = 10;
447
+ _1.sent();
448
+ _1.label = 10;
392
449
  case 10:
393
450
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
394
451
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
395
452
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
396
- _y.label = 11;
453
+ _1.label = 11;
397
454
  case 11:
398
- _y.trys.push([11, 13, , 14]);
455
+ _1.trys.push([11, 13, , 14]);
399
456
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
400
457
  authenticatedUserToken: this.authenticatedUserToken,
401
458
  chatId: this.chatToken.chatId
402
459
  })];
403
460
  case 12:
404
- _y.sent();
461
+ _1.sent();
405
462
  return [3 /*break*/, 14];
406
463
  case 13:
407
- _v = _y.sent();
464
+ _y = _1.sent();
408
465
  exceptionDetails = {
409
466
  response: "OCClientValidateAuthChatRecordFailed",
410
467
  message: "InvalidAuthChatRecord"
@@ -419,84 +476,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
419
476
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
420
477
  return [4 /*yield*/, this.getChatToken(false)];
421
478
  case 15:
422
- _y.sent();
423
- _y.label = 16;
479
+ _1.sent();
480
+ _1.label = 16;
424
481
  case 16:
425
482
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
426
483
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
427
484
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
428
485
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
429
486
  (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId(this.chatToken.chatId || '');
487
+ (_h = this.amsClientLogger) === null || _h === void 0 ? void 0 : _h.setChatId(this.chatToken.chatId || '');
430
488
  sessionInitOptionalParams = {
431
489
  initContext: {}
432
490
  };
433
- sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
434
- if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
491
+ sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams);
492
+ sessionInitOptionalParams.initContext.isProactiveChat = !!optionalParams.isProactiveChat;
493
+ if (this.isPersistentChat && !((_j = this.chatSDKConfig.persistentChat) === null || _j === void 0 ? void 0 : _j.disable)) {
435
494
  sessionInitOptionalParams.reconnectId = this.reconnectId;
436
495
  }
437
- if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
496
+ else if (this.isChatReconnect && !((_k = this.chatSDKConfig.chatReconnect) === null || _k === void 0 ? void 0 : _k.disable) && !this.isPersistentChat) {
438
497
  sessionInitOptionalParams.reconnectId = this.reconnectId;
439
498
  }
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;
499
+ if (!(((_m = (_l = this.liveChatConfig) === null || _l === void 0 ? void 0 : _l.LiveWSAndLiveChatEngJoin) === null || _m === void 0 ? void 0 : _m.msdyn_requestvisitorlocation) === "true")) return [3 /*break*/, 18];
500
+ return [4 /*yield*/, location_1.getLocationInfo(this.scenarioMarker, this.chatToken.chatId, this.requestId)];
487
501
  case 17:
488
- _y.trys.push([17, 19, , 20]);
489
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
502
+ location_2 = _1.sent();
503
+ sessionInitOptionalParams.initContext.latitude = location_2.latitude;
504
+ sessionInitOptionalParams.initContext.longitude = location_2.longitude;
505
+ _1.label = 18;
490
506
  case 18:
491
- _y.sent();
492
- return [3 /*break*/, 20];
507
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
508
+ _1.label = 19;
493
509
  case 19:
494
- error_3 = _y.sent();
510
+ _1.trys.push([19, 21, , 22]);
511
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
512
+ case 20:
513
+ _1.sent();
514
+ return [3 /*break*/, 22];
515
+ case 21:
516
+ error_3 = _1.sent();
495
517
  exceptionDetails = {
496
518
  response: "OCClientSessionInitFailed"
497
519
  };
498
520
  // 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()) {
521
+ if (((_o = error_3) === null || _o === void 0 ? void 0 : _o.isAxiosError) && ((_q = (_p = error_3.response) === null || _p === void 0 ? void 0 : _p.headers) === null || _q === void 0 ? void 0 : _q.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
500
522
  exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
501
523
  exceptionDetails.message = 'Widget used outside of operating hours';
502
524
  console.error(exceptionDetails.message);
@@ -507,8 +529,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
507
529
  ExceptionDetails: JSON.stringify(exceptionDetails)
508
530
  });
509
531
  throw new Error(exceptionDetails.response);
510
- case 20:
511
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 31];
532
+ case 22:
533
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 33];
512
534
  chatAdapterConfig = {
513
535
  token: this.chatToken.token,
514
536
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -516,18 +538,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
516
538
  environmentUrl: this.chatToken.acsEndpoint,
517
539
  pollingInterval: 30000
518
540
  };
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({
541
+ _1.label = 23;
542
+ case 23:
543
+ _1.trys.push([23, 25, , 26]);
544
+ return [4 /*yield*/, ((_r = this.ACSClient) === null || _r === void 0 ? void 0 : _r.initialize({
523
545
  token: chatAdapterConfig.token,
524
546
  environmentUrl: chatAdapterConfig.environmentUrl
525
547
  }))];
526
- case 22:
527
- _y.sent();
528
- return [3 /*break*/, 24];
529
- case 23:
530
- error_4 = _y.sent();
548
+ case 24:
549
+ _1.sent();
550
+ return [3 /*break*/, 26];
551
+ case 25:
552
+ error_4 = _1.sent();
531
553
  exceptionDetails = {
532
554
  response: "ACSClientInitializeFailed"
533
555
  };
@@ -538,23 +560,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
538
560
  });
539
561
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
540
562
  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({
563
+ case 26:
564
+ _1.trys.push([26, 28, , 29]);
565
+ _z = this;
566
+ return [4 /*yield*/, ((_s = this.ACSClient) === null || _s === void 0 ? void 0 : _s.joinConversation({
545
567
  id: chatAdapterConfig.id,
546
568
  threadId: chatAdapterConfig.threadId,
547
569
  pollingInterval: chatAdapterConfig.pollingInterval
548
570
  }))];
549
- case 25:
550
- _w.conversation = (_y.sent());
571
+ case 27:
572
+ _z.conversation = (_1.sent());
551
573
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
552
574
  RequestId: this.requestId,
553
575
  ChatId: this.chatToken.chatId
554
576
  });
555
- return [3 /*break*/, 27];
556
- case 26:
557
- error_5 = _y.sent();
577
+ return [3 /*break*/, 29];
578
+ case 28:
579
+ error_5 = _1.sent();
558
580
  exceptionDetails = {
559
581
  response: "ACSClientJoinConversationFailed"
560
582
  };
@@ -565,16 +587,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
565
587
  });
566
588
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
567
589
  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({
590
+ case 29:
591
+ _1.trys.push([29, 31, , 32]);
592
+ return [4 /*yield*/, ((_t = this.AMSClient) === null || _t === void 0 ? void 0 : _t.initialize({
571
593
  chatToken: this.chatToken
572
594
  }))];
573
- case 28:
574
- _y.sent();
575
- return [3 /*break*/, 30];
576
- case 29:
577
- error_6 = _y.sent();
595
+ case 30:
596
+ _1.sent();
597
+ return [3 /*break*/, 32];
598
+ case 31:
599
+ error_6 = _1.sent();
578
600
  exceptionDetails = {
579
601
  response: "AMSClientInitializeFailed"
580
602
  };
@@ -584,19 +606,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
584
606
  ExceptionDetails: JSON.stringify(exceptionDetails)
585
607
  });
586
608
  throw Error(exceptionDetails.response);
587
- case 30: return [3 /*break*/, 37];
588
- case 31:
589
- _y.trys.push([31, 33, , 34]);
609
+ case 32: return [3 /*break*/, 39];
610
+ case 33:
611
+ _1.trys.push([33, 35, , 36]);
590
612
  return [4 /*yield*/, this.IC3Client.initialize({
591
613
  token: this.chatToken.token,
592
614
  regionGtms: this.chatToken.regionGTMS,
593
615
  visitor: true
594
616
  })];
595
- case 32:
596
- _y.sent();
597
- return [3 /*break*/, 34];
598
- case 33:
599
- error_7 = _y.sent();
617
+ case 34:
618
+ _1.sent();
619
+ return [3 /*break*/, 36];
620
+ case 35:
621
+ error_7 = _1.sent();
600
622
  exceptionDetails = {
601
623
  response: "IC3ClientInitializeFailed"
602
624
  };
@@ -607,19 +629,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
607
629
  });
608
630
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
609
631
  return [2 /*return*/, error_7];
610
- case 34:
611
- _y.trys.push([34, 36, , 37]);
612
- _x = this;
632
+ case 36:
633
+ _1.trys.push([36, 38, , 39]);
634
+ _0 = this;
613
635
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
614
- case 35:
615
- _x.conversation = _y.sent();
636
+ case 37:
637
+ _0.conversation = _1.sent();
616
638
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
617
639
  RequestId: this.requestId,
618
640
  ChatId: this.chatToken.chatId
619
641
  });
620
- return [3 /*break*/, 37];
621
- case 36:
622
- error_8 = _y.sent();
642
+ return [3 /*break*/, 39];
643
+ case 38:
644
+ error_8 = _1.sent();
623
645
  exceptionDetails = {
624
646
  response: "IC3ClientJoinConversationFailed"
625
647
  };
@@ -630,8 +652,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
630
652
  });
631
653
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
632
654
  return [2 /*return*/, error_8];
633
- case 37:
634
- if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
655
+ case 39:
656
+ if (this.isPersistentChat && !((_u = this.chatSDKConfig.persistentChat) === null || _u === void 0 ? void 0 : _u.disable)) {
635
657
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
636
658
  return __generator(this, function (_a) {
637
659
  switch (_a.label) {
@@ -642,7 +664,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
642
664
  return [2 /*return*/];
643
665
  }
644
666
  });
645
- }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
667
+ }); }, (_v = this.chatSDKConfig.persistentChat) === null || _v === void 0 ? void 0 : _v.tokenUpdateTime);
646
668
  }
647
669
  return [2 /*return*/];
648
670
  }
@@ -650,11 +672,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
650
672
  });
651
673
  };
652
674
  OmnichannelChatSDK.prototype.endChat = function () {
653
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
675
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
654
676
  return __awaiter(this, void 0, void 0, function () {
655
677
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
656
- return __generator(this, function (_p) {
657
- switch (_p.label) {
678
+ return __generator(this, function (_r) {
679
+ switch (_r.label) {
658
680
  case 0:
659
681
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
660
682
  RequestId: this.requestId,
@@ -674,12 +696,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
674
696
  if (this.authenticatedUserToken) {
675
697
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
676
698
  }
677
- _p.label = 1;
699
+ _r.label = 1;
678
700
  case 1:
679
- _p.trys.push([1, 3, , 4]);
701
+ _r.trys.push([1, 3, , 4]);
680
702
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
681
703
  case 2:
682
- _p.sent();
704
+ _r.sent();
683
705
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
684
706
  RequestId: this.requestId,
685
707
  ChatId: this.chatToken.chatId
@@ -704,9 +726,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
704
726
  (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
705
727
  (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
706
728
  (_o = this.callingSdkLogger) === null || _o === void 0 ? void 0 : _o.setChatId('');
729
+ (_p = this.amsClientLogger) === null || _p === void 0 ? void 0 : _p.setRequestId(this.requestId);
730
+ (_q = this.amsClientLogger) === null || _q === void 0 ? void 0 : _q.setChatId('');
707
731
  return [3 /*break*/, 4];
708
732
  case 3:
709
- error_9 = _p.sent();
733
+ error_9 = _r.sent();
710
734
  exceptionDetails = {
711
735
  response: "OCClientSessionCloseFailed"
712
736
  };
@@ -1818,6 +1842,60 @@ var OmnichannelChatSDK = /** @class */ (function () {
1818
1842
  });
1819
1843
  });
1820
1844
  };
1845
+ OmnichannelChatSDK.prototype.getAgentAvailability = function (optionalParams) {
1846
+ if (optionalParams === void 0) { optionalParams = {}; }
1847
+ return __awaiter(this, void 0, void 0, function () {
1848
+ var reportError, getAgentAvailabilityOptionalParams, response, e_1;
1849
+ var _this = this;
1850
+ return __generator(this, function (_a) {
1851
+ switch (_a.label) {
1852
+ case 0:
1853
+ reportError = function (response, message, chatId) {
1854
+ if (chatId === void 0) { chatId = ""; }
1855
+ var exceptionDetails = {
1856
+ response: response,
1857
+ message: message
1858
+ };
1859
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1860
+ RequestId: _this.requestId,
1861
+ ExceptionDetails: JSON.stringify(exceptionDetails),
1862
+ ChatId: chatId
1863
+ });
1864
+ throw new Error(exceptionDetails.message);
1865
+ };
1866
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAgentAvailability, {
1867
+ RequestId: this.requestId
1868
+ });
1869
+ if (!this.authSettings) {
1870
+ reportError("Unsupported", "GetAgentAvailability is supported only for authenticated live chat widget.");
1871
+ }
1872
+ if (!this.authenticatedUserToken) {
1873
+ reportError("UndefinedAuthToken", "Missing AuthToken for GetAgentAvailability.");
1874
+ }
1875
+ if (this.conversation) {
1876
+ reportError("InvalidOperation", "GetAgentAvailability can only be called before a chat has started.", this.chatToken.chatId);
1877
+ }
1878
+ getAgentAvailabilityOptionalParams = {
1879
+ initContext: {}
1880
+ };
1881
+ getAgentAvailabilityOptionalParams = this.populateInitChatOptionalParam(getAgentAvailabilityOptionalParams, optionalParams);
1882
+ _a.label = 1;
1883
+ case 1:
1884
+ _a.trys.push([1, 3, , 4]);
1885
+ return [4 /*yield*/, this.OCClient.getAgentAvailability(this.requestId, getAgentAvailabilityOptionalParams)];
1886
+ case 2:
1887
+ response = _a.sent();
1888
+ return [2 /*return*/, response];
1889
+ case 3:
1890
+ e_1 = _a.sent();
1891
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1892
+ reportError("GetAgentAvailabilityFailed", e_1.message);
1893
+ return [3 /*break*/, 4];
1894
+ case 4: return [2 /*return*/];
1895
+ }
1896
+ });
1897
+ });
1898
+ };
1821
1899
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1822
1900
  return __awaiter(this, void 0, void 0, function () {
1823
1901
  var IC3Client;