@microsoft/omnichannel-chat-sdk 1.2.1-main.c18015b → 1.2.1-main.d627f36

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