@microsoft/omnichannel-chat-sdk 1.0.1-main.85b823d → 1.0.1-main.91ec7fb

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 (67) hide show
  1. package/CHANGELOG.md +24 -3
  2. package/README.md +104 -104
  3. package/lib/OmnichannelChatSDK.d.ts +6 -4
  4. package/lib/OmnichannelChatSDK.js +311 -297
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/api/createVoiceVideoCalling.js +6 -2
  7. package/lib/api/createVoiceVideoCalling.js.map +1 -1
  8. package/lib/config/settings.d.ts +1 -1
  9. package/lib/config/settings.js +1 -1
  10. package/lib/config/settings.js.map +1 -1
  11. package/lib/core/ChatConfig.d.ts +4 -0
  12. package/lib/core/ChatSDKExceptionDetails.d.ts +5 -0
  13. package/lib/core/ChatSDKExceptionDetails.js +3 -0
  14. package/lib/core/ChatSDKExceptionDetails.js.map +1 -0
  15. package/lib/core/ChatTranscriptBody.d.ts +1 -1
  16. package/lib/core/LiveWorkItemDetails.d.ts +2 -0
  17. package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
  18. package/lib/core/OmnichannelErrorCodes.js +8 -0
  19. package/lib/core/OmnichannelErrorCodes.js.map +1 -0
  20. package/lib/core/PostChatContext.d.ts +1 -0
  21. package/lib/core/messaging/ACSClient.js +1 -1
  22. package/lib/core/messaging/ACSClient.js.map +1 -1
  23. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  24. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  25. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  26. package/lib/core/messaging/MessageTags.d.ts +2 -0
  27. package/lib/core/messaging/MessageTags.js +4 -2
  28. package/lib/core/messaging/MessageTags.js.map +1 -1
  29. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
  30. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
  31. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js.map +1 -0
  32. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  33. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  34. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  35. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  36. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  37. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  38. package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -0
  39. package/lib/external/CallingSDK/ICallingSDKLogData.js +3 -0
  40. package/lib/external/CallingSDK/ICallingSDKLogData.js.map +1 -0
  41. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  42. package/lib/telemetry/AriaTelemetry.d.ts +1 -0
  43. package/lib/telemetry/AriaTelemetry.js +55 -0
  44. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  45. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  46. package/lib/telemetry/ScenarioMarker.js +7 -3
  47. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  48. package/lib/telemetry/ScenarioType.d.ts +1 -0
  49. package/lib/telemetry/ScenarioType.js +1 -0
  50. package/lib/telemetry/ScenarioType.js.map +1 -1
  51. package/lib/telemetry/TelemetryEvent.d.ts +1 -3
  52. package/lib/telemetry/TelemetryEvent.js +0 -2
  53. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  54. package/lib/tsconfig.tsbuildinfo +906 -1127
  55. package/lib/utils/WebUtils.d.ts +3 -1
  56. package/lib/utils/WebUtils.js +8 -2
  57. package/lib/utils/WebUtils.js.map +1 -1
  58. package/lib/utils/libraries.d.ts +1 -3
  59. package/lib/utils/libraries.js +2 -11
  60. package/lib/utils/libraries.js.map +1 -1
  61. package/lib/utils/locale.d.ts +1 -0
  62. package/lib/utils/locale.js +2 -1
  63. package/lib/utils/locale.js.map +1 -1
  64. package/lib/utils/loggers.d.ts +25 -0
  65. package/lib/utils/loggers.js +93 -1
  66. package/lib/utils/loggers.js.map +1 -1
  67. package/package.json +2 -2
@@ -58,7 +58,8 @@ 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 libraries_1 = require("./utils/libraries");
61
+ var locale_1 = require("./utils/locale");
62
+ var WebUtils_1 = require("./utils/WebUtils");
62
63
  var platform_1 = require("./utils/platform");
63
64
  var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
64
65
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
@@ -74,23 +75,26 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
74
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
75
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
76
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
77
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
78
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
79
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
80
82
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
81
83
  var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
85
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
86
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
82
87
  var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
83
88
  var createTelemetry_1 = require("./utils/createTelemetry");
84
89
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
85
90
  var MessageTags_1 = require("./core/messaging/MessageTags");
86
- var locale_1 = require("./utils/locale");
87
91
  var utilities_1 = require("./utils/utilities");
88
- var WebUtils_1 = require("./utils/WebUtils");
92
+ var libraries_1 = require("./utils/libraries");
89
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
90
94
  var OmnichannelChatSDK = /** @class */ (function () {
91
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
92
96
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
93
- var _a, _b, _c, _d, _e, _f, _g;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h;
94
98
  this.ACSClient = null;
95
99
  this.AMSClient = null;
96
100
  this.authSettings = null;
@@ -102,16 +106,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
102
106
  this.ocSdkLogger = null;
103
107
  this.acsClientLogger = null;
104
108
  this.acsAdapterLogger = null;
109
+ this.callingSdkLogger = null;
105
110
  this.isPersistentChat = false;
106
111
  this.isChatReconnect = false;
107
112
  this.reconnectId = null;
108
113
  this.refreshTokenTimer = null;
109
114
  this.debug = false;
115
+ this.runtimeId = ocsdk_1.uuidv4();
110
116
  this.omnichannelConfig = omnichannelConfig;
111
117
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
112
118
  );
113
119
  this.isInitialized = false;
114
120
  this.liveChatVersion = LiveChatVersion_1.default.V1;
121
+ this.localeId = locale_1.defaultLocaleId;
115
122
  this.requestId = ocsdk_1.uuidv4();
116
123
  this.chatToken = {};
117
124
  this.liveChatConfig = {};
@@ -124,11 +131,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
124
131
  this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
125
132
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
126
133
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
134
+ this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
127
135
  this.scenarioMarker.useTelemetry(this.telemetry);
128
136
  this.ic3ClientLogger.useTelemetry(this.telemetry);
129
137
  this.ocSdkLogger.useTelemetry(this.telemetry);
130
138
  this.acsClientLogger.useTelemetry(this.telemetry);
131
139
  this.acsAdapterLogger.useTelemetry(this.telemetry);
140
+ this.callingSdkLogger.useTelemetry(this.telemetry);
141
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
142
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
143
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
144
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
145
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
146
+ this.callingSdkLogger.setRuntimeId(this.runtimeId);
132
147
  OmnichannelConfigValidator_1.default(omnichannelConfig);
133
148
  SDKConfigValidators_1.default(chatSDKConfig);
134
149
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -139,10 +154,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
139
154
  (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
140
155
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
141
156
  (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
157
+ (_h = this.callingSdkLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
142
158
  }
143
159
  /* istanbul ignore next */
144
160
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
145
- var _a, _b, _c, _d, _e, _f;
161
+ var _a, _b, _c, _d, _e, _f, _g;
146
162
  this.debug = flag;
147
163
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
148
164
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -151,6 +167,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
151
167
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
152
168
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
153
169
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
170
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setDebug(flag);
154
171
  };
155
172
  OmnichannelChatSDK.prototype.initialize = function () {
156
173
  return __awaiter(this, void 0, void 0, function () {
@@ -289,47 +306,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
289
306
  });
290
307
  };
291
308
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
292
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
309
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
293
310
  if (optionalParams === void 0) { optionalParams = {}; }
294
311
  return __awaiter(this, void 0, void 0, function () {
295
- var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
312
+ var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _v, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _w, error_8, exceptionDetails;
296
313
  var _this = this;
297
- return __generator(this, function (_s) {
298
- switch (_s.label) {
314
+ return __generator(this, function (_x) {
315
+ switch (_x.label) {
299
316
  case 0:
300
317
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
301
318
  RequestId: this.requestId
302
319
  });
320
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
321
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
322
+ _t = this;
323
+ return [4 /*yield*/, this.getIC3Client()];
324
+ case 1:
325
+ _t.IC3Client = _x.sent();
326
+ _x.label = 2;
327
+ case 2:
303
328
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
304
329
  this.reconnectId = optionalParams.reconnectId;
305
330
  }
306
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
307
- _s.label = 1;
308
- case 1:
309
- _s.trys.push([1, 3, , 4]);
331
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
332
+ _x.label = 3;
333
+ case 3:
334
+ _x.trys.push([3, 5, , 6]);
310
335
  reconnectableChatsParams = {
311
336
  authenticatedUserToken: this.authenticatedUserToken
312
337
  };
313
338
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
314
- case 2:
315
- reconnectableChatsResponse = _s.sent();
339
+ case 4:
340
+ reconnectableChatsResponse = _x.sent();
316
341
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
317
342
  this.reconnectId = reconnectableChatsResponse.reconnectid;
318
343
  }
319
- return [3 /*break*/, 4];
320
- case 3:
321
- _p = _s.sent();
344
+ return [3 /*break*/, 6];
345
+ case 5:
346
+ _u = _x.sent();
322
347
  exceptionDetails = {
323
348
  response: "OCClientGetReconnectableChatsFailed"
324
349
  };
325
350
  throw Error(exceptionDetails.response);
326
- case 4:
327
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
351
+ case 6:
352
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
328
353
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
329
354
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
330
355
  return [4 /*yield*/, this.getConversationDetails()];
331
- case 5:
332
- conversationDetails = _s.sent();
356
+ case 7:
357
+ conversationDetails = _x.sent();
333
358
  if (Object.keys(conversationDetails).length === 0) {
334
359
  exceptionDetails = {
335
360
  response: "InvalidConversation"
@@ -354,25 +379,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
354
379
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
355
380
  throw Error(exceptionDetails.response);
356
381
  }
357
- _s.label = 6;
358
- case 6:
359
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
360
- return [4 /*yield*/, this.getChatToken(false)];
361
- case 7:
362
- _s.sent();
363
- _s.label = 8;
382
+ _x.label = 8;
364
383
  case 8:
384
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
385
+ return [4 /*yield*/, this.getChatToken(false)];
386
+ case 9:
387
+ _x.sent();
388
+ _x.label = 10;
389
+ case 10:
365
390
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
366
391
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
367
392
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
368
393
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
394
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId(this.chatToken.chatId || '');
369
395
  sessionInitOptionalParams = {
370
396
  initContext: {}
371
397
  };
372
- if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
398
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
399
+ if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
373
400
  sessionInitOptionalParams.reconnectId = this.reconnectId;
374
401
  }
375
- if (this.isChatReconnect && !((_h = this.chatSDKConfig.chatReconnect) === null || _h === void 0 ? void 0 : _h.disable) && !this.isPersistentChat) {
402
+ if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
376
403
  sessionInitOptionalParams.reconnectId = this.reconnectId;
377
404
  }
378
405
  if (optionalParams.customContext) {
@@ -400,27 +427,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
400
427
  if (this.authenticatedUserToken) {
401
428
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
402
429
  }
403
- _s.label = 9;
404
- case 9:
405
- _s.trys.push([9, 11, , 12]);
406
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
407
- case 10:
408
- _s.sent();
409
- return [3 /*break*/, 12];
430
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
431
+ _x.label = 11;
410
432
  case 11:
411
- error_3 = _s.sent();
433
+ _x.trys.push([11, 13, , 14]);
434
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
435
+ case 12:
436
+ _x.sent();
437
+ return [3 /*break*/, 14];
438
+ case 13:
439
+ error_3 = _x.sent();
412
440
  exceptionDetails = {
413
441
  response: "OCClientSessionInitFailed"
414
442
  };
443
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
444
+ 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()) {
445
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
446
+ exceptionDetails.message = 'Widget used outside of operating hours';
447
+ console.error(exceptionDetails.message);
448
+ }
415
449
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
416
450
  RequestId: this.requestId,
417
451
  ChatId: this.chatToken.chatId,
418
452
  ExceptionDetails: JSON.stringify(exceptionDetails)
419
453
  });
420
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
421
- return [2 /*return*/, error_3];
422
- case 12:
423
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
454
+ throw new Error(exceptionDetails.response);
455
+ case 14:
456
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
424
457
  chatAdapterConfig = {
425
458
  token: this.chatToken.token,
426
459
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -428,18 +461,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
428
461
  environmentUrl: this.chatToken.acsEndpoint,
429
462
  pollingInterval: 1000
430
463
  };
431
- _s.label = 13;
432
- case 13:
433
- _s.trys.push([13, 15, , 16]);
434
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
464
+ _x.label = 15;
465
+ case 15:
466
+ _x.trys.push([15, 17, , 18]);
467
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.initialize({
435
468
  token: chatAdapterConfig.token,
436
469
  environmentUrl: chatAdapterConfig.environmentUrl
437
470
  }))];
438
- case 14:
439
- _s.sent();
440
- return [3 /*break*/, 16];
441
- case 15:
442
- error_4 = _s.sent();
471
+ case 16:
472
+ _x.sent();
473
+ return [3 /*break*/, 18];
474
+ case 17:
475
+ error_4 = _x.sent();
443
476
  exceptionDetails = {
444
477
  response: "ACSClientInitializeFailed"
445
478
  };
@@ -450,23 +483,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
450
483
  });
451
484
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
452
485
  return [2 /*return*/, error_4];
453
- case 16:
454
- _s.trys.push([16, 18, , 19]);
455
- _q = this;
456
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
486
+ case 18:
487
+ _x.trys.push([18, 20, , 21]);
488
+ _v = this;
489
+ return [4 /*yield*/, ((_p = this.ACSClient) === null || _p === void 0 ? void 0 : _p.joinConversation({
457
490
  id: chatAdapterConfig.id,
458
491
  threadId: chatAdapterConfig.threadId,
459
492
  pollingInterval: chatAdapterConfig.pollingInterval
460
493
  }))];
461
- case 17:
462
- _q.conversation = (_s.sent());
494
+ case 19:
495
+ _v.conversation = (_x.sent());
463
496
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
464
497
  RequestId: this.requestId,
465
498
  ChatId: this.chatToken.chatId
466
499
  });
467
- return [3 /*break*/, 19];
468
- case 18:
469
- error_5 = _s.sent();
500
+ return [3 /*break*/, 21];
501
+ case 20:
502
+ error_5 = _x.sent();
470
503
  exceptionDetails = {
471
504
  response: "ACSClientJoinConversationFailed"
472
505
  };
@@ -477,16 +510,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
477
510
  });
478
511
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
479
512
  throw Error(exceptionDetails.response);
480
- case 19:
481
- _s.trys.push([19, 21, , 22]);
482
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
513
+ case 21:
514
+ _x.trys.push([21, 23, , 24]);
515
+ return [4 /*yield*/, ((_q = this.AMSClient) === null || _q === void 0 ? void 0 : _q.initialize({
483
516
  chatToken: this.chatToken
484
517
  }))];
485
- case 20:
486
- _s.sent();
487
- return [3 /*break*/, 22];
488
- case 21:
489
- error_6 = _s.sent();
518
+ case 22:
519
+ _x.sent();
520
+ return [3 /*break*/, 24];
521
+ case 23:
522
+ error_6 = _x.sent();
490
523
  exceptionDetails = {
491
524
  response: "AMSClientInitializeFailed"
492
525
  };
@@ -496,19 +529,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
496
529
  ExceptionDetails: JSON.stringify(exceptionDetails)
497
530
  });
498
531
  throw Error(exceptionDetails.response);
499
- case 22: return [3 /*break*/, 29];
500
- case 23:
501
- _s.trys.push([23, 25, , 26]);
532
+ case 24: return [3 /*break*/, 31];
533
+ case 25:
534
+ _x.trys.push([25, 27, , 28]);
502
535
  return [4 /*yield*/, this.IC3Client.initialize({
503
536
  token: this.chatToken.token,
504
537
  regionGtms: this.chatToken.regionGTMS,
505
538
  visitor: true
506
539
  })];
507
- case 24:
508
- _s.sent();
509
- return [3 /*break*/, 26];
510
- case 25:
511
- error_7 = _s.sent();
540
+ case 26:
541
+ _x.sent();
542
+ return [3 /*break*/, 28];
543
+ case 27:
544
+ error_7 = _x.sent();
512
545
  exceptionDetails = {
513
546
  response: "IC3ClientInitializeFailed"
514
547
  };
@@ -519,19 +552,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
519
552
  });
520
553
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
521
554
  return [2 /*return*/, error_7];
522
- case 26:
523
- _s.trys.push([26, 28, , 29]);
524
- _r = this;
555
+ case 28:
556
+ _x.trys.push([28, 30, , 31]);
557
+ _w = this;
525
558
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
526
- case 27:
527
- _r.conversation = _s.sent();
559
+ case 29:
560
+ _w.conversation = _x.sent();
528
561
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
529
562
  RequestId: this.requestId,
530
563
  ChatId: this.chatToken.chatId
531
564
  });
532
- return [3 /*break*/, 29];
533
- case 28:
534
- error_8 = _s.sent();
565
+ return [3 /*break*/, 31];
566
+ case 30:
567
+ error_8 = _x.sent();
535
568
  exceptionDetails = {
536
569
  response: "IC3ClientJoinConversationFailed"
537
570
  };
@@ -542,8 +575,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
542
575
  });
543
576
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
544
577
  return [2 /*return*/, error_8];
545
- case 29:
546
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
578
+ case 31:
579
+ if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
547
580
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
548
581
  return __generator(this, function (_a) {
549
582
  switch (_a.label) {
@@ -554,7 +587,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
554
587
  return [2 /*return*/];
555
588
  }
556
589
  });
557
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
590
+ }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
558
591
  }
559
592
  return [2 /*return*/];
560
593
  }
@@ -562,11 +595,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
562
595
  });
563
596
  };
564
597
  OmnichannelChatSDK.prototype.endChat = function () {
565
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
598
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
566
599
  return __awaiter(this, void 0, void 0, function () {
567
600
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
568
- return __generator(this, function (_m) {
569
- switch (_m.label) {
601
+ return __generator(this, function (_p) {
602
+ switch (_p.label) {
570
603
  case 0:
571
604
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
572
605
  RequestId: this.requestId,
@@ -580,17 +613,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
580
613
  }
581
614
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
582
615
  isChatReconnect = this.reconnectId !== null ? true : false;
616
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
583
617
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
584
618
  }
585
619
  if (this.authenticatedUserToken) {
586
620
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
587
621
  }
588
- _m.label = 1;
622
+ _p.label = 1;
589
623
  case 1:
590
- _m.trys.push([1, 3, , 4]);
624
+ _p.trys.push([1, 3, , 4]);
591
625
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
592
626
  case 2:
593
- _m.sent();
627
+ _p.sent();
594
628
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
595
629
  RequestId: this.requestId,
596
630
  ChatId: this.chatToken.chatId
@@ -600,6 +634,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
600
634
  this.requestId = ocsdk_1.uuidv4();
601
635
  this.chatToken = {};
602
636
  this.reconnectId = null;
637
+ if (this.IC3Client) {
638
+ this.IC3Client.dispose();
639
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
640
+ this.IC3Client = null;
641
+ }
603
642
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
604
643
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
605
644
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -608,9 +647,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
608
647
  (_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
609
648
  (_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
610
649
  (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
650
+ (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
651
+ (_o = this.callingSdkLogger) === null || _o === void 0 ? void 0 : _o.setChatId('');
611
652
  return [3 /*break*/, 4];
612
653
  case 3:
613
- error_9 = _m.sent();
654
+ error_9 = _p.sent();
614
655
  exceptionDetails = {
615
656
  response: "OCClientSessionCloseFailed"
616
657
  };
@@ -661,23 +702,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
661
702
  });
662
703
  };
663
704
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
664
- var _a, _b;
705
+ var _a, _b, _c, _d;
665
706
  return __awaiter(this, void 0, void 0, function () {
666
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
667
- return __generator(this, function (_c) {
668
- switch (_c.label) {
707
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_10;
708
+ return __generator(this, function (_e) {
709
+ switch (_e.label) {
669
710
  case 0:
670
711
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
671
712
  RequestId: this.requestId,
672
713
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
673
714
  });
674
- _c.label = 1;
715
+ getLWIDetailsOptionalParams = {};
716
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
717
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
718
+ }
719
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
720
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
721
+ }
722
+ if (this.authenticatedUserToken) {
723
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
724
+ }
725
+ _e.label = 1;
675
726
  case 1:
676
- _c.trys.push([1, 3, , 4]);
677
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
727
+ _e.trys.push([1, 3, , 4]);
728
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
678
729
  case 2:
679
- lwiDetails = _c.sent();
680
- state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
730
+ lwiDetails = _e.sent();
731
+ state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn, canRenderPostChat = lwiDetails.CanRenderPostChat, participantType = lwiDetails.ParticipantType;
681
732
  liveWorkItemDetails = {
682
733
  state: state,
683
734
  conversationId: conversationId
@@ -685,13 +736,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
685
736
  if (agentAcceptedOn) {
686
737
  liveWorkItemDetails.agentAcceptedOn = agentAcceptedOn;
687
738
  }
739
+ if (canRenderPostChat) {
740
+ liveWorkItemDetails.canRenderPostChat = canRenderPostChat;
741
+ }
742
+ if (participantType) {
743
+ liveWorkItemDetails.participantType = participantType;
744
+ }
688
745
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
689
746
  RequestId: this.requestId,
690
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
747
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
691
748
  });
692
749
  return [2 /*return*/, liveWorkItemDetails];
693
750
  case 3:
694
- error_10 = _c.sent();
751
+ error_10 = _e.sent();
695
752
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
696
753
  RequestId: this.requestId,
697
754
  ChatId: this.chatToken.chatId || '',
@@ -897,6 +954,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
897
954
  sendMessageRequest = {
898
955
  content: message.content,
899
956
  };
957
+ sendMessageRequest.metadata = {
958
+ widgetId: this.omnichannelConfig.widgetId,
959
+ clientMessageId: Date.now().toString()
960
+ };
961
+ if (message.metadata) {
962
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
963
+ }
900
964
  _e.label = 1;
901
965
  case 1:
902
966
  _e.trys.push([1, 3, , 4]);
@@ -1279,7 +1343,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1279
1343
  };
1280
1344
  sendMessageRequest = {
1281
1345
  content: '',
1282
- metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
1346
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1283
1347
  };
1284
1348
  messageToSend = {
1285
1349
  content: "",
@@ -1440,7 +1504,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1440
1504
  ChatId: this.chatToken.chatId,
1441
1505
  EmailAddress: body.emailAddress,
1442
1506
  DefaultAttachmentMessage: body.attachmentMessage,
1443
- CustomerLocale: body.locale
1507
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1444
1508
  };
1445
1509
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1446
1510
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1490,32 +1554,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1490
1554
  });
1491
1555
  });
1492
1556
  };
1493
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1494
- if (protocol === void 0) { protocol = null; }
1557
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1558
+ if (optionalParams === void 0) { optionalParams = {}; }
1495
1559
  return __awaiter(this, void 0, void 0, function () {
1496
- var supportedChatAdapterProtocols;
1560
+ var protocol, supportedChatAdapterProtocols;
1497
1561
  var _this = this;
1498
1562
  return __generator(this, function (_a) {
1499
1563
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1500
1564
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1501
1565
  }
1566
+ protocol = optionalParams.protocol;
1502
1567
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1503
1568
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1504
1569
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1505
1570
  }
1506
1571
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1507
1572
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1508
- var featuresOption, acsAdapterCDNUrl;
1573
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1509
1574
  var _this = this;
1510
1575
  var _a;
1511
1576
  return __generator(this, function (_b) {
1512
1577
  switch (_b.label) {
1513
1578
  case 0:
1514
- featuresOption = {
1515
- enableAdaptiveCards: false,
1516
- enableThreadMemberUpdateNotification: true,
1517
- enableLeaveThreadOnWindowClosed: false
1518
- };
1579
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1580
+ defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1581
+ defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1582
+ egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1583
+ ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1584
+ featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1585
+ ingressMiddleware: ingressMiddleware,
1586
+ egressMiddleware: egressMiddleware });
1519
1587
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1520
1588
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1521
1589
  ACSAdapter: acsAdapterCDNUrl
@@ -1526,7 +1594,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1526
1594
  try {
1527
1595
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1528
1596
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1529
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, featuresOption);
1597
+ var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, // chatClient
1598
+ undefined, // logger
1599
+ featuresOption);
1530
1600
  resolve(adapter);
1531
1601
  }
1532
1602
  catch (_a) {
@@ -1544,12 +1614,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1544
1614
  }
1545
1615
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1546
1616
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1547
- var ic3AdapterCDNUrl;
1617
+ var options, ic3AdapterCDNUrl;
1548
1618
  var _this = this;
1549
1619
  var _a;
1550
1620
  return __generator(this, function (_b) {
1551
1621
  switch (_b.label) {
1552
1622
  case 0:
1623
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1553
1624
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1554
1625
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1555
1626
  IC3Adapter: ic3AdapterCDNUrl
@@ -1558,17 +1629,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1558
1629
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1559
1630
  /* istanbul ignore next */
1560
1631
  _this.debug && console.debug('IC3Adapter loaded!');
1561
- var adapterConfig = {
1562
- chatToken: _this.chatToken,
1563
- userDisplayName: 'Customer',
1564
- userId: 'teamsvisitor',
1565
- sdkURL: _this.resolveIC3ClientUrl(),
1566
- sdk: _this.IC3Client
1567
- };
1632
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1633
+ );
1568
1634
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1569
1635
  adapter.logger = _this.ic3ClientLogger;
1570
- // Keep iframe communication alive to reuse the same IC3Client instance
1571
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1572
1636
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1573
1637
  resolve(adapter);
1574
1638
  }, function () {
@@ -1589,16 +1653,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
1589
1653
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1590
1654
  if (params === void 0) { params = {}; }
1591
1655
  return __awaiter(this, void 0, void 0, function () {
1592
- var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1656
+ var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1593
1657
  var _this = this;
1594
1658
  return __generator(this, function (_a) {
1595
1659
  switch (_a.label) {
1596
1660
  case 0:
1661
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1597
1662
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1598
- return [2 /*return*/, Promise.reject('VoiceVideoCalling is only supported on browser')];
1663
+ exceptionDetails = {
1664
+ response: "UnsupportedPlatform",
1665
+ message: "VoiceVideoCalling is only supported on browser"
1666
+ };
1667
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1668
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1669
+ });
1670
+ throw new Error(exceptionDetails.response);
1599
1671
  }
1600
1672
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1601
- return [2 /*return*/, Promise.reject('Voice and video call is not enabled')];
1673
+ exceptionDetails = {
1674
+ response: "FeatureDisabled",
1675
+ message: "Voice and video call is not enabled"
1676
+ };
1677
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1678
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1679
+ });
1680
+ throw new Error(exceptionDetails.response);
1602
1681
  }
1603
1682
  return [4 /*yield*/, this.getChatConfig()];
1604
1683
  case 1:
@@ -1608,25 +1687,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
1608
1687
  widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
1609
1688
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1610
1689
  if (result && result.length) {
1611
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1612
- var LiveChatWidgetLibCDNUrl;
1690
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
1691
+ var LiveChatWidgetLibCDNUrl, defaultParams;
1613
1692
  var _this = this;
1614
1693
  var _a;
1615
1694
  return __generator(this, function (_b) {
1616
1695
  switch (_b.label) {
1617
1696
  case 0:
1618
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1619
1697
  LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1620
1698
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1621
1699
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1622
1700
  });
1701
+ defaultParams = {
1702
+ logger: this.callingSdkLogger
1703
+ };
1623
1704
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
1624
1705
  var VoiceVideoCalling;
1625
1706
  return __generator(this, function (_a) {
1626
1707
  switch (_a.label) {
1627
1708
  case 0:
1628
1709
  this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!");
1629
- return [4 /*yield*/, createVoiceVideoCalling_1.default(params)];
1710
+ return [4 /*yield*/, createVoiceVideoCalling_1.default(__assign(__assign({}, params), defaultParams))];
1630
1711
  case 1:
1631
1712
  VoiceVideoCalling = _a.sent();
1632
1713
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
@@ -1639,13 +1720,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1639
1720
  var exceptionDetails;
1640
1721
  return __generator(this, function (_a) {
1641
1722
  exceptionDetails = {
1642
- response: "VoiceVideoCallingLoadFailed"
1723
+ response: "VoiceVideoCallingLoadFailed",
1724
+ message: "Failed to load VoiceVideoCalling"
1643
1725
  };
1644
1726
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1645
1727
  ExceptionDetails: JSON.stringify(exceptionDetails)
1646
1728
  });
1647
- reject('Failed to load VoiceVideoCalling');
1648
- return [2 /*return*/];
1729
+ throw new Error(exceptionDetails.response);
1649
1730
  });
1650
1731
  }); })];
1651
1732
  case 1:
@@ -1662,7 +1743,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1662
1743
  };
1663
1744
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1664
1745
  return __awaiter(this, void 0, void 0, function () {
1665
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, chatWidgetLanguage, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, msdyn_localeid, localeId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1746
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, surveyInviteLinkRequest, optionalParams, ownerId, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1666
1747
  return __generator(this, function (_a) {
1667
1748
  switch (_a.label) {
1668
1749
  case 0:
@@ -1673,20 +1754,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1673
1754
  case 1:
1674
1755
  _a.trys.push([1, 6, , 7]);
1675
1756
  chatConfig = this.liveChatConfig;
1676
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1677
- msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1678
- msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1679
- localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
1680
- if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1681
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1757
+ liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
1758
+ msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId;
1759
+ if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 4];
1760
+ return [4 /*yield*/, this.getConversationDetails()];
1682
1761
  case 2:
1683
1762
  liveWorkItemDetails = _a.sent();
1684
- participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) && (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) === "True";
1685
- conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.ConversationId;
1763
+ participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.canRenderPostChat) === "True";
1764
+ participantType = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.participantType;
1765
+ conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.conversationId;
1686
1766
  surveyInviteLinkRequest = {
1687
- "FormId": msfp_sourcesurveyidentifier,
1767
+ "FormId": participantType === "Bot" ? msfp_botsourcesurveyidentifier : msfp_sourcesurveyidentifier,
1688
1768
  "ConversationId": conversationId,
1689
- "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1769
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1690
1770
  };
1691
1771
  optionalParams = {
1692
1772
  "requestId": this.requestId
@@ -1694,7 +1774,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1694
1774
  if (this.authenticatedUserToken) {
1695
1775
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1696
1776
  }
1697
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, surveyInviteLinkRequest)];
1777
+ ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1778
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1698
1779
  case 3:
1699
1780
  surveyInviteLinkResponse = _a.sent();
1700
1781
  surveyInviteLink = void 0, formsProLocale = void 0;
@@ -1715,6 +1796,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1715
1796
  }
1716
1797
  postChatContext = {
1717
1798
  participantJoined: participantJoined,
1799
+ participantType: participantType,
1718
1800
  surveyInviteLink: surveyInviteLink,
1719
1801
  formsProLocale: formsProLocale
1720
1802
  };
@@ -1739,7 +1821,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1739
1821
  case 6:
1740
1822
  ex_1 = _a.sent();
1741
1823
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1742
- ConversationId: conversationId,
1824
+ ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1743
1825
  RequestId: this.requestId,
1744
1826
  ExceptionDetails: JSON.stringify(ex_1)
1745
1827
  });
@@ -1749,102 +1831,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1749
1831
  });
1750
1832
  });
1751
1833
  };
1752
- OmnichannelChatSDK.prototype.initializePostChatRenderer = function () {
1753
- return __awaiter(this, void 0, void 0, function () {
1754
- var msfpEmbedScript, elm, scriptNodes, styleNodes, i, node, tmpNode, tmpNode, i, node, tmpNode;
1755
- return __generator(this, function (_a) {
1756
- if (!platform_1.isBrowser()) {
1757
- return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
1758
- }
1759
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
1760
- RequestId: this.requestId
1761
- });
1762
- try {
1763
- msfpEmbedScript = libraries_1.getMsfpEmbedScript();
1764
- elm = document.createElement('div');
1765
- elm.innerHTML = msfpEmbedScript;
1766
- scriptNodes = elm.getElementsByTagName('script');
1767
- styleNodes = elm.getElementsByTagName('link');
1768
- for (i = 0; i < scriptNodes.length; i++) {
1769
- node = scriptNodes[i];
1770
- if (node.src) {
1771
- tmpNode = document.createElement('script');
1772
- tmpNode.type = node.type;
1773
- tmpNode.src = node.src;
1774
- tmpNode.async = false;
1775
- if (!window.document.head.contains(tmpNode)) {
1776
- document.getElementsByTagName('head')[0].appendChild(tmpNode);
1777
- }
1778
- }
1779
- if (node.innerHTML) {
1780
- tmpNode = document.createElement('script');
1781
- tmpNode.innerHTML = node.innerHTML;
1782
- tmpNode.async = false;
1783
- if (!window.document.head.contains(tmpNode)) {
1784
- window.document.head.appendChild(tmpNode);
1785
- }
1786
- }
1787
- }
1788
- for (i = 0; i < styleNodes.length; i++) {
1789
- node = styleNodes[i];
1790
- if (node.href) {
1791
- tmpNode = document.createElement('link');
1792
- tmpNode.type = node.type;
1793
- tmpNode.rel = node.rel;
1794
- tmpNode.href = node.href;
1795
- if (!window.document.head.contains(tmpNode)) {
1796
- document.getElementsByTagName('head')[0].appendChild(tmpNode);
1797
- }
1798
- }
1799
- }
1800
- }
1801
- catch (ex) {
1802
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
1803
- RequestId: this.requestId,
1804
- ExceptionDetails: JSON.stringify(ex)
1805
- });
1806
- return [2 /*return*/, Promise.reject("Error occurred when initializer post chat renderer. " + JSON.stringify(ex))];
1807
- }
1808
- return [2 /*return*/];
1809
- });
1810
- });
1811
- };
1812
- OmnichannelChatSDK.prototype.renderPostChatSurvey = function (containerId, postChatContext) {
1813
- return __awaiter(this, void 0, void 0, function () {
1814
- var ex_2;
1815
- return __generator(this, function (_a) {
1816
- switch (_a.label) {
1817
- case 0:
1818
- if (!platform_1.isBrowser()) {
1819
- return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
1820
- }
1821
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1822
- RequestId: this.requestId
1823
- });
1824
- _a.label = 1;
1825
- case 1:
1826
- _a.trys.push([1, 3, , 4]);
1827
- if (!postChatContext) {
1828
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1829
- RequestId: this.requestId,
1830
- ExceptionDetails: "Post Chat Context is null."
1831
- });
1832
- return [2 /*return*/, Promise.reject("Post Chat Context is null.")];
1833
- }
1834
- return [4 /*yield*/, renderSurvey(containerId, postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.surveyInviteLink, "", "", postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.formsProLocale)];
1835
- case 2: return [2 /*return*/, _a.sent()];
1836
- case 3:
1837
- ex_2 = _a.sent();
1838
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1839
- RequestId: this.requestId,
1840
- ExceptionDetails: JSON.stringify(ex_2)
1841
- });
1842
- return [2 /*return*/, Promise.reject("Error occurred when rendering post chat survey. " + JSON.stringify(ex_2))];
1843
- case 4: return [2 /*return*/];
1844
- }
1845
- });
1846
- });
1847
- };
1848
1834
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1849
1835
  return __awaiter(this, void 0, void 0, function () {
1850
1836
  var IC3Client;
@@ -1871,7 +1857,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1871
1857
  this.debug && console.debug('IC3Client');
1872
1858
  // Use IC3Client if browser is detected
1873
1859
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1874
- var ic3ClientCDNUrl;
1860
+ var ic3ClientCDNUrl, IC3Client;
1875
1861
  var _this = this;
1876
1862
  var _a;
1877
1863
  return __generator(this, function (_b) {
@@ -1882,6 +1868,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1882
1868
  IC3Client: ic3ClientCDNUrl
1883
1869
  });
1884
1870
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1871
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1872
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1873
+ hostType: HostType_1.default.IFrame,
1874
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1875
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1876
+ })];
1877
+ case 1:
1878
+ IC3Client = _b.sent();
1879
+ return [2 /*return*/, resolve(IC3Client)];
1880
+ case 2:
1885
1881
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1886
1882
  var ic3sdk, IC3SDKProvider, IC3Client;
1887
1883
  return __generator(this, function (_a) {
@@ -1918,7 +1914,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1918
1914
  });
1919
1915
  reject('Failed to load IC3Client');
1920
1916
  })];
1921
- case 1:
1917
+ case 3:
1922
1918
  _b.sent();
1923
1919
  return [2 /*return*/];
1924
1920
  }
@@ -1930,15 +1926,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1930
1926
  };
1931
1927
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1932
1928
  return __awaiter(this, void 0, void 0, function () {
1933
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1934
- return __generator(this, function (_b) {
1935
- switch (_b.label) {
1929
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1930
+ return __generator(this, function (_a) {
1931
+ switch (_a.label) {
1936
1932
  case 0:
1937
- _b.trys.push([0, 8, , 9]);
1933
+ _a.trys.push([0, 4, , 5]);
1938
1934
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1939
1935
  case 1:
1940
- liveChatConfig = _b.sent();
1941
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1936
+ liveChatConfig = _a.sent();
1937
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1938
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1939
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1942
1940
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1943
1941
  /* istanbul ignore next */
1944
1942
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1961,47 +1959,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1961
1959
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1962
1960
  this.preChatSurvey = preChatSurvey;
1963
1961
  }
1964
- if (!this.authSettings) return [3 /*break*/, 7];
1965
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1966
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1967
- _b.label = 2;
1962
+ if (!this.authSettings) return [3 /*break*/, 3];
1963
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1968
1964
  case 2:
1969
- _b.trys.push([2, 4, , 5]);
1970
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1965
+ _a.sent();
1966
+ _a.label = 3;
1971
1967
  case 3:
1972
- token = _b.sent();
1973
- if (token) {
1974
- this.authenticatedUserToken = token;
1975
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1976
- }
1977
- else {
1978
- exceptionDetails = {
1979
- response: "UndefinedAuthToken"
1980
- };
1981
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1982
- ExceptionDetails: JSON.stringify(exceptionDetails)
1983
- });
1984
- }
1985
- return [3 /*break*/, 5];
1986
- case 4:
1987
- _a = _b.sent();
1988
- exceptionDetails = {
1989
- response: "GetAuthTokenFailed"
1990
- };
1991
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1992
- ExceptionDetails: JSON.stringify(exceptionDetails)
1993
- });
1994
- return [3 /*break*/, 5];
1995
- case 5: return [3 /*break*/, 7];
1996
- case 6:
1997
- exceptionDetails = {
1998
- response: "GetAuthTokenNotFound"
1999
- };
2000
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2001
- ExceptionDetails: JSON.stringify(exceptionDetails)
2002
- });
2003
- _b.label = 7;
2004
- case 7:
2005
1968
  if (this.preChatSurvey) {
2006
1969
  /* istanbul ignore next */
2007
1970
  this.debug && console.log('Prechat Survey!');
@@ -2009,11 +1972,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
2009
1972
  this.callingOption = msdyn_callingoptions;
2010
1973
  this.liveChatConfig = liveChatConfig;
2011
1974
  return [2 /*return*/, this.liveChatConfig];
2012
- case 8:
2013
- error_18 = _b.sent();
1975
+ case 4:
1976
+ error_18 = _a.sent();
2014
1977
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
2015
1978
  return [2 /*return*/, error_18];
2016
- case 9: return [2 /*return*/];
1979
+ case 5: return [2 /*return*/];
2017
1980
  }
2018
1981
  });
2019
1982
  });
@@ -2095,6 +2058,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2095
2058
  });
2096
2059
  });
2097
2060
  };
2061
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2062
+ return __awaiter(this, void 0, void 0, function () {
2063
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2064
+ return __generator(this, function (_b) {
2065
+ switch (_b.label) {
2066
+ case 0:
2067
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2068
+ this.chatSDKConfig.getAuthToken = provider;
2069
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2070
+ _b.label = 1;
2071
+ case 1:
2072
+ _b.trys.push([1, 3, , 4]);
2073
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2074
+ case 2:
2075
+ token = _b.sent();
2076
+ if (token) {
2077
+ this.authenticatedUserToken = token;
2078
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2079
+ }
2080
+ else {
2081
+ exceptionDetails = {
2082
+ response: "UndefinedAuthToken"
2083
+ };
2084
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2085
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2086
+ });
2087
+ }
2088
+ return [3 /*break*/, 4];
2089
+ case 3:
2090
+ _a = _b.sent();
2091
+ exceptionDetails = {
2092
+ response: "GetAuthTokenFailed"
2093
+ };
2094
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2095
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2096
+ });
2097
+ return [3 /*break*/, 4];
2098
+ case 4: return [3 /*break*/, 6];
2099
+ case 5:
2100
+ exceptionDetails = {
2101
+ response: "GetAuthTokenNotFound"
2102
+ };
2103
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2104
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2105
+ });
2106
+ _b.label = 6;
2107
+ case 6: return [2 /*return*/];
2108
+ }
2109
+ });
2110
+ });
2111
+ };
2098
2112
  return OmnichannelChatSDK;
2099
2113
  }());
2100
2114
  exports.default = OmnichannelChatSDK;