@microsoft/omnichannel-chat-sdk 1.0.0 → 1.0.1-main.2b06a3d

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 (49) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +49 -18
  3. package/lib/OmnichannelChatSDK.d.ts +9 -4
  4. package/lib/OmnichannelChatSDK.js +335 -177
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/config/settings.d.ts +1 -1
  7. package/lib/config/settings.js +1 -1
  8. package/lib/config/settings.js.map +1 -1
  9. package/lib/core/ChatConfig.d.ts +4 -0
  10. package/lib/core/ChatSDKExceptionDetails.d.ts +5 -0
  11. package/lib/core/ChatSDKExceptionDetails.js +3 -0
  12. package/lib/core/ChatSDKExceptionDetails.js.map +1 -0
  13. package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
  14. package/lib/core/OmnichannelErrorCodes.js +8 -0
  15. package/lib/core/OmnichannelErrorCodes.js.map +1 -0
  16. package/lib/core/PostChatContext.d.ts +5 -0
  17. package/lib/core/PostChatContext.js +3 -0
  18. package/lib/core/PostChatContext.js.map +1 -0
  19. package/lib/core/messaging/ACSClient.js +1 -1
  20. package/lib/core/messaging/ACSClient.js.map +1 -1
  21. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  22. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  23. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  24. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  25. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  26. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  27. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  28. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  29. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  30. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  31. package/lib/telemetry/AriaTelemetry.js +5 -0
  32. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  33. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  34. package/lib/telemetry/ScenarioMarker.js +7 -3
  35. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  36. package/lib/telemetry/TelemetryEvent.d.ts +2 -1
  37. package/lib/telemetry/TelemetryEvent.js +1 -0
  38. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  39. package/lib/tsconfig.tsbuildinfo +1067 -1290
  40. package/lib/utils/WebUtils.d.ts +3 -1
  41. package/lib/utils/WebUtils.js +8 -2
  42. package/lib/utils/WebUtils.js.map +1 -1
  43. package/lib/utils/locale.d.ts +3 -0
  44. package/lib/utils/locale.js +60 -0
  45. package/lib/utils/locale.js.map +1 -0
  46. package/lib/utils/loggers.d.ts +8 -0
  47. package/lib/utils/loggers.js +24 -0
  48. package/lib/utils/loggers.js.map +1 -1
  49. package/package.json +2 -2
@@ -55,37 +55,41 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
55
55
  return r;
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ var loggers_1 = require("./utils/loggers");
58
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
+ var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var platform_1 = require("./utils/platform");
62
+ var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
59
63
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
60
64
  var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
61
65
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
62
66
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
63
67
  var ConversationMode_1 = require("./core/ConversationMode");
64
- var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
65
- var loggers_1 = require("./utils/loggers");
66
- var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
67
- var createTelemetry_1 = require("./utils/createTelemetry");
68
- var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
69
- var MessageTags_1 = require("./core/messaging/MessageTags");
68
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
70
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
71
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
72
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
73
- var utilities_1 = require("./utils/utilities");
74
- var libraries_1 = require("./utils/libraries");
75
- var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
73
+ var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
76
74
  var LiveChatVersion_1 = require("./core/LiveChatVersion");
77
- var WebUtils_1 = require("./utils/WebUtils");
75
+ var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
78
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
79
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
80
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
81
- var platform_1 = require("./utils/platform");
82
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
83
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
84
- var ocsdk_1 = require("@microsoft/ocsdk");
85
- var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
86
82
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
83
+ var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
+ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
85
+ var createTelemetry_1 = require("./utils/createTelemetry");
86
+ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
87
+ var MessageTags_1 = require("./core/messaging/MessageTags");
88
+ var locale_1 = require("./utils/locale");
89
+ var utilities_1 = require("./utils/utilities");
90
+ var libraries_1 = require("./utils/libraries");
91
+ var WebUtils_1 = require("./utils/WebUtils");
87
92
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
88
- var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
89
93
  var OmnichannelChatSDK = /** @class */ (function () {
90
94
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
91
95
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
@@ -106,11 +110,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
106
110
  this.reconnectId = null;
107
111
  this.refreshTokenTimer = null;
108
112
  this.debug = false;
113
+ this.runtimeId = ocsdk_1.uuidv4();
109
114
  this.omnichannelConfig = omnichannelConfig;
110
115
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
111
116
  );
112
117
  this.isInitialized = false;
113
118
  this.liveChatVersion = LiveChatVersion_1.default.V1;
119
+ this.localeId = locale_1.defaultLocaleId;
114
120
  this.requestId = ocsdk_1.uuidv4();
115
121
  this.chatToken = {};
116
122
  this.liveChatConfig = {};
@@ -128,6 +134,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
128
134
  this.ocSdkLogger.useTelemetry(this.telemetry);
129
135
  this.acsClientLogger.useTelemetry(this.telemetry);
130
136
  this.acsAdapterLogger.useTelemetry(this.telemetry);
137
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
138
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
139
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
140
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
141
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
131
142
  OmnichannelConfigValidator_1.default(omnichannelConfig);
132
143
  SDKConfigValidators_1.default(chatSDKConfig);
133
144
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -288,47 +299,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
288
299
  });
289
300
  };
290
301
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
291
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
302
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
292
303
  if (optionalParams === void 0) { optionalParams = {}; }
293
304
  return __awaiter(this, void 0, void 0, function () {
294
- 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;
305
+ var shouldReinitIC3Client, _s, reconnectableChatsParams, reconnectableChatsResponse, _t, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _u, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _v, error_8, exceptionDetails;
295
306
  var _this = this;
296
- return __generator(this, function (_s) {
297
- switch (_s.label) {
307
+ return __generator(this, function (_w) {
308
+ switch (_w.label) {
298
309
  case 0:
299
310
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
300
311
  RequestId: this.requestId
301
312
  });
313
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
314
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
315
+ _s = this;
316
+ return [4 /*yield*/, this.getIC3Client()];
317
+ case 1:
318
+ _s.IC3Client = _w.sent();
319
+ _w.label = 2;
320
+ case 2:
302
321
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
303
322
  this.reconnectId = optionalParams.reconnectId;
304
323
  }
305
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
306
- _s.label = 1;
307
- case 1:
308
- _s.trys.push([1, 3, , 4]);
324
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
325
+ _w.label = 3;
326
+ case 3:
327
+ _w.trys.push([3, 5, , 6]);
309
328
  reconnectableChatsParams = {
310
329
  authenticatedUserToken: this.authenticatedUserToken
311
330
  };
312
331
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
313
- case 2:
314
- reconnectableChatsResponse = _s.sent();
332
+ case 4:
333
+ reconnectableChatsResponse = _w.sent();
315
334
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
316
335
  this.reconnectId = reconnectableChatsResponse.reconnectid;
317
336
  }
318
- return [3 /*break*/, 4];
319
- case 3:
320
- _p = _s.sent();
337
+ return [3 /*break*/, 6];
338
+ case 5:
339
+ _t = _w.sent();
321
340
  exceptionDetails = {
322
341
  response: "OCClientGetReconnectableChatsFailed"
323
342
  };
324
343
  throw Error(exceptionDetails.response);
325
- case 4:
326
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
344
+ case 6:
345
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
327
346
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
328
347
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
329
348
  return [4 /*yield*/, this.getConversationDetails()];
330
- case 5:
331
- conversationDetails = _s.sent();
349
+ case 7:
350
+ conversationDetails = _w.sent();
332
351
  if (Object.keys(conversationDetails).length === 0) {
333
352
  exceptionDetails = {
334
353
  response: "InvalidConversation"
@@ -353,14 +372,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
353
372
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
354
373
  throw Error(exceptionDetails.response);
355
374
  }
356
- _s.label = 6;
357
- case 6:
358
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
359
- return [4 /*yield*/, this.getChatToken(false)];
360
- case 7:
361
- _s.sent();
362
- _s.label = 8;
375
+ _w.label = 8;
363
376
  case 8:
377
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
378
+ return [4 /*yield*/, this.getChatToken(false)];
379
+ case 9:
380
+ _w.sent();
381
+ _w.label = 10;
382
+ case 10:
364
383
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
365
384
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
366
385
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
@@ -368,6 +387,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
368
387
  sessionInitOptionalParams = {
369
388
  initContext: {}
370
389
  };
390
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
371
391
  if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
372
392
  sessionInitOptionalParams.reconnectId = this.reconnectId;
373
393
  }
@@ -399,27 +419,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
399
419
  if (this.authenticatedUserToken) {
400
420
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
401
421
  }
402
- _s.label = 9;
403
- case 9:
404
- _s.trys.push([9, 11, , 12]);
405
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
406
- case 10:
407
- _s.sent();
408
- return [3 /*break*/, 12];
422
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
423
+ _w.label = 11;
409
424
  case 11:
410
- error_3 = _s.sent();
425
+ _w.trys.push([11, 13, , 14]);
426
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
427
+ case 12:
428
+ _w.sent();
429
+ return [3 /*break*/, 14];
430
+ case 13:
431
+ error_3 = _w.sent();
411
432
  exceptionDetails = {
412
433
  response: "OCClientSessionInitFailed"
413
434
  };
435
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
436
+ if (((_j = error_3) === null || _j === void 0 ? void 0 : _j.isAxiosError) && ((_l = (_k = error_3.response) === null || _k === void 0 ? void 0 : _k.headers) === null || _l === void 0 ? void 0 : _l.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
437
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
438
+ exceptionDetails.message = 'Widget used outside of operating hours';
439
+ console.error(exceptionDetails.message);
440
+ }
414
441
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
415
442
  RequestId: this.requestId,
416
443
  ChatId: this.chatToken.chatId,
417
444
  ExceptionDetails: JSON.stringify(exceptionDetails)
418
445
  });
419
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
420
- return [2 /*return*/, error_3];
421
- case 12:
422
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
446
+ throw new Error(exceptionDetails.response);
447
+ case 14:
448
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
423
449
  chatAdapterConfig = {
424
450
  token: this.chatToken.token,
425
451
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -427,18 +453,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
427
453
  environmentUrl: this.chatToken.acsEndpoint,
428
454
  pollingInterval: 1000
429
455
  };
430
- _s.label = 13;
431
- case 13:
432
- _s.trys.push([13, 15, , 16]);
433
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
456
+ _w.label = 15;
457
+ case 15:
458
+ _w.trys.push([15, 17, , 18]);
459
+ return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
434
460
  token: chatAdapterConfig.token,
435
461
  environmentUrl: chatAdapterConfig.environmentUrl
436
462
  }))];
437
- case 14:
438
- _s.sent();
439
- return [3 /*break*/, 16];
440
- case 15:
441
- error_4 = _s.sent();
463
+ case 16:
464
+ _w.sent();
465
+ return [3 /*break*/, 18];
466
+ case 17:
467
+ error_4 = _w.sent();
442
468
  exceptionDetails = {
443
469
  response: "ACSClientInitializeFailed"
444
470
  };
@@ -449,23 +475,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
449
475
  });
450
476
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
451
477
  return [2 /*return*/, error_4];
452
- case 16:
453
- _s.trys.push([16, 18, , 19]);
454
- _q = this;
455
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
478
+ case 18:
479
+ _w.trys.push([18, 20, , 21]);
480
+ _u = this;
481
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
456
482
  id: chatAdapterConfig.id,
457
483
  threadId: chatAdapterConfig.threadId,
458
484
  pollingInterval: chatAdapterConfig.pollingInterval
459
485
  }))];
460
- case 17:
461
- _q.conversation = (_s.sent());
486
+ case 19:
487
+ _u.conversation = (_w.sent());
462
488
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
463
489
  RequestId: this.requestId,
464
490
  ChatId: this.chatToken.chatId
465
491
  });
466
- return [3 /*break*/, 19];
467
- case 18:
468
- error_5 = _s.sent();
492
+ return [3 /*break*/, 21];
493
+ case 20:
494
+ error_5 = _w.sent();
469
495
  exceptionDetails = {
470
496
  response: "ACSClientJoinConversationFailed"
471
497
  };
@@ -476,16 +502,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
476
502
  });
477
503
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
478
504
  throw Error(exceptionDetails.response);
479
- case 19:
480
- _s.trys.push([19, 21, , 22]);
481
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
505
+ case 21:
506
+ _w.trys.push([21, 23, , 24]);
507
+ return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
482
508
  chatToken: this.chatToken
483
509
  }))];
484
- case 20:
485
- _s.sent();
486
- return [3 /*break*/, 22];
487
- case 21:
488
- error_6 = _s.sent();
510
+ case 22:
511
+ _w.sent();
512
+ return [3 /*break*/, 24];
513
+ case 23:
514
+ error_6 = _w.sent();
489
515
  exceptionDetails = {
490
516
  response: "AMSClientInitializeFailed"
491
517
  };
@@ -495,19 +521,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
495
521
  ExceptionDetails: JSON.stringify(exceptionDetails)
496
522
  });
497
523
  throw Error(exceptionDetails.response);
498
- case 22: return [3 /*break*/, 29];
499
- case 23:
500
- _s.trys.push([23, 25, , 26]);
524
+ case 24: return [3 /*break*/, 31];
525
+ case 25:
526
+ _w.trys.push([25, 27, , 28]);
501
527
  return [4 /*yield*/, this.IC3Client.initialize({
502
528
  token: this.chatToken.token,
503
529
  regionGtms: this.chatToken.regionGTMS,
504
530
  visitor: true
505
531
  })];
506
- case 24:
507
- _s.sent();
508
- return [3 /*break*/, 26];
509
- case 25:
510
- error_7 = _s.sent();
532
+ case 26:
533
+ _w.sent();
534
+ return [3 /*break*/, 28];
535
+ case 27:
536
+ error_7 = _w.sent();
511
537
  exceptionDetails = {
512
538
  response: "IC3ClientInitializeFailed"
513
539
  };
@@ -518,19 +544,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
518
544
  });
519
545
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
520
546
  return [2 /*return*/, error_7];
521
- case 26:
522
- _s.trys.push([26, 28, , 29]);
523
- _r = this;
547
+ case 28:
548
+ _w.trys.push([28, 30, , 31]);
549
+ _v = this;
524
550
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
525
- case 27:
526
- _r.conversation = _s.sent();
551
+ case 29:
552
+ _v.conversation = _w.sent();
527
553
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
528
554
  RequestId: this.requestId,
529
555
  ChatId: this.chatToken.chatId
530
556
  });
531
- return [3 /*break*/, 29];
532
- case 28:
533
- error_8 = _s.sent();
557
+ return [3 /*break*/, 31];
558
+ case 30:
559
+ error_8 = _w.sent();
534
560
  exceptionDetails = {
535
561
  response: "IC3ClientJoinConversationFailed"
536
562
  };
@@ -541,8 +567,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
541
567
  });
542
568
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
543
569
  return [2 /*return*/, error_8];
544
- case 29:
545
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
570
+ case 31:
571
+ if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
546
572
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
547
573
  return __generator(this, function (_a) {
548
574
  switch (_a.label) {
@@ -553,7 +579,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
553
579
  return [2 /*return*/];
554
580
  }
555
581
  });
556
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
582
+ }); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
557
583
  }
558
584
  return [2 /*return*/];
559
585
  }
@@ -579,6 +605,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
579
605
  }
580
606
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
581
607
  isChatReconnect = this.reconnectId !== null ? true : false;
608
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
582
609
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
583
610
  }
584
611
  if (this.authenticatedUserToken) {
@@ -599,6 +626,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
599
626
  this.requestId = ocsdk_1.uuidv4();
600
627
  this.chatToken = {};
601
628
  this.reconnectId = null;
629
+ this.IC3Client.dispose();
630
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
631
+ this.IC3Client = null;
602
632
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
603
633
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
604
634
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -660,22 +690,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
660
690
  });
661
691
  };
662
692
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
663
- var _a, _b;
693
+ var _a, _b, _c, _d;
664
694
  return __awaiter(this, void 0, void 0, function () {
665
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
666
- return __generator(this, function (_c) {
667
- switch (_c.label) {
695
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
696
+ return __generator(this, function (_e) {
697
+ switch (_e.label) {
668
698
  case 0:
669
699
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
670
700
  RequestId: this.requestId,
671
701
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
672
702
  });
673
- _c.label = 1;
703
+ getLWIDetailsOptionalParams = {};
704
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
705
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
706
+ }
707
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
708
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
709
+ }
710
+ if (this.authenticatedUserToken) {
711
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
712
+ }
713
+ _e.label = 1;
674
714
  case 1:
675
- _c.trys.push([1, 3, , 4]);
676
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
715
+ _e.trys.push([1, 3, , 4]);
716
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
677
717
  case 2:
678
- lwiDetails = _c.sent();
718
+ lwiDetails = _e.sent();
679
719
  state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
680
720
  liveWorkItemDetails = {
681
721
  state: state,
@@ -686,11 +726,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
686
726
  }
687
727
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
688
728
  RequestId: this.requestId,
689
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
729
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
690
730
  });
691
731
  return [2 /*return*/, liveWorkItemDetails];
692
732
  case 3:
693
- error_10 = _c.sent();
733
+ error_10 = _e.sent();
694
734
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
695
735
  RequestId: this.requestId,
696
736
  ChatId: this.chatToken.chatId || '',
@@ -896,6 +936,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
896
936
  sendMessageRequest = {
897
937
  content: message.content,
898
938
  };
939
+ sendMessageRequest.metadata = {
940
+ widgetId: this.omnichannelConfig.widgetId,
941
+ clientMessageId: Date.now().toString()
942
+ };
943
+ if (message.metadata) {
944
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
945
+ }
899
946
  _e.label = 1;
900
947
  case 1:
901
948
  _e.trys.push([1, 3, , 4]);
@@ -1278,7 +1325,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1278
1325
  };
1279
1326
  sendMessageRequest = {
1280
1327
  content: '',
1281
- metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
1328
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1282
1329
  };
1283
1330
  messageToSend = {
1284
1331
  content: "",
@@ -1439,7 +1486,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1439
1486
  ChatId: this.chatToken.chatId,
1440
1487
  EmailAddress: body.emailAddress,
1441
1488
  DefaultAttachmentMessage: body.attachmentMessage,
1442
- CustomerLocale: body.locale
1489
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1443
1490
  };
1444
1491
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1445
1492
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1489,32 +1536,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1489
1536
  });
1490
1537
  });
1491
1538
  };
1492
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1493
- if (protocol === void 0) { protocol = null; }
1539
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1540
+ if (optionalParams === void 0) { optionalParams = {}; }
1494
1541
  return __awaiter(this, void 0, void 0, function () {
1495
- var supportedChatAdapterProtocols;
1542
+ var protocol, supportedChatAdapterProtocols;
1496
1543
  var _this = this;
1497
1544
  return __generator(this, function (_a) {
1498
1545
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1499
1546
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1500
1547
  }
1548
+ protocol = optionalParams.protocol;
1501
1549
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1502
1550
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1503
1551
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1504
1552
  }
1505
1553
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1506
1554
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1507
- var featuresOption, acsAdapterCDNUrl;
1555
+ var options, egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1508
1556
  var _this = this;
1509
1557
  var _a;
1510
1558
  return __generator(this, function (_b) {
1511
1559
  switch (_b.label) {
1512
1560
  case 0:
1513
- featuresOption = {
1514
- enableAdaptiveCards: false,
1515
- enableThreadMemberUpdateNotification: true,
1516
- enableLeaveThreadOnWindowClosed: false
1517
- };
1561
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1562
+ egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1563
+ ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1564
+ featuresOption = __assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false, egressMiddleware: egressMiddlewares, ingressMiddleware: ingressMiddlewares }, options // overrides
1565
+ );
1518
1566
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1519
1567
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1520
1568
  ACSAdapter: acsAdapterCDNUrl
@@ -1525,7 +1573,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1525
1573
  try {
1526
1574
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1527
1575
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1528
- 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);
1576
+ 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
1577
+ undefined, // logger
1578
+ featuresOption);
1529
1579
  resolve(adapter);
1530
1580
  }
1531
1581
  catch (_a) {
@@ -1543,12 +1593,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1543
1593
  }
1544
1594
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1545
1595
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1546
- var ic3AdapterCDNUrl;
1596
+ var options, ic3AdapterCDNUrl;
1547
1597
  var _this = this;
1548
1598
  var _a;
1549
1599
  return __generator(this, function (_b) {
1550
1600
  switch (_b.label) {
1551
1601
  case 0:
1602
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1552
1603
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1553
1604
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1554
1605
  IC3Adapter: ic3AdapterCDNUrl
@@ -1557,17 +1608,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1557
1608
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1558
1609
  /* istanbul ignore next */
1559
1610
  _this.debug && console.debug('IC3Adapter loaded!');
1560
- var adapterConfig = {
1561
- chatToken: _this.chatToken,
1562
- userDisplayName: 'Customer',
1563
- userId: 'teamsvisitor',
1564
- sdkURL: _this.resolveIC3ClientUrl(),
1565
- sdk: _this.IC3Client
1566
- };
1611
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1612
+ );
1567
1613
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1568
1614
  adapter.logger = _this.ic3ClientLogger;
1569
- // Keep iframe communication alive to reuse the same IC3Client instance
1570
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1571
1615
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1572
1616
  resolve(adapter);
1573
1617
  }, function () {
@@ -1659,6 +1703,92 @@ var OmnichannelChatSDK = /** @class */ (function () {
1659
1703
  });
1660
1704
  });
1661
1705
  };
1706
+ OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1707
+ return __awaiter(this, void 0, void 0, function () {
1708
+ var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1709
+ return __generator(this, function (_a) {
1710
+ switch (_a.label) {
1711
+ case 0:
1712
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1713
+ RequestId: this.requestId
1714
+ });
1715
+ _a.label = 1;
1716
+ case 1:
1717
+ _a.trys.push([1, 6, , 7]);
1718
+ liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
1719
+ msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1720
+ if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1721
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1722
+ case 2:
1723
+ liveWorkItemDetails = _a.sent();
1724
+ participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) && (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) === "True";
1725
+ conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.ConversationId;
1726
+ surveyInviteLinkRequest = {
1727
+ "FormId": msfp_sourcesurveyidentifier,
1728
+ "ConversationId": conversationId,
1729
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
1730
+ };
1731
+ optionalParams = {
1732
+ "requestId": this.requestId
1733
+ };
1734
+ if (this.authenticatedUserToken) {
1735
+ optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1736
+ }
1737
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, surveyInviteLinkRequest)];
1738
+ case 3:
1739
+ surveyInviteLinkResponse = _a.sent();
1740
+ surveyInviteLink = void 0, formsProLocale = void 0;
1741
+ if (surveyInviteLinkResponse != null) {
1742
+ if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1743
+ surveyInviteLink = surveyInviteLinkResponse.inviteList[0].invitationLink;
1744
+ }
1745
+ else {
1746
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1747
+ ConversationId: conversationId,
1748
+ RequestId: this.requestId,
1749
+ ExceptionDetails: "Survey Invite link failed to send response."
1750
+ });
1751
+ return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1752
+ }
1753
+ if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1754
+ formsProLocale = surveyInviteLinkResponse.formsProLocaleCode;
1755
+ }
1756
+ postChatContext = {
1757
+ participantJoined: participantJoined,
1758
+ surveyInviteLink: surveyInviteLink,
1759
+ formsProLocale: formsProLocale
1760
+ };
1761
+ return [2 /*return*/, Promise.resolve(postChatContext)];
1762
+ }
1763
+ else {
1764
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1765
+ ConversationId: conversationId,
1766
+ RequestId: this.requestId,
1767
+ ExceptionDetails: "surveyInviteLinkResponse is null."
1768
+ });
1769
+ return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1770
+ }
1771
+ return [3 /*break*/, 5];
1772
+ case 4:
1773
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1774
+ RequestId: this.requestId,
1775
+ ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1776
+ });
1777
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1778
+ case 5: return [3 /*break*/, 7];
1779
+ case 6:
1780
+ ex_1 = _a.sent();
1781
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1782
+ ConversationId: conversationId,
1783
+ RequestId: this.requestId,
1784
+ ExceptionDetails: JSON.stringify(ex_1)
1785
+ });
1786
+ return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1787
+ case 7: return [2 /*return*/];
1788
+ }
1789
+ });
1790
+ });
1791
+ };
1662
1792
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1663
1793
  return __awaiter(this, void 0, void 0, function () {
1664
1794
  var IC3Client;
@@ -1685,7 +1815,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1685
1815
  this.debug && console.debug('IC3Client');
1686
1816
  // Use IC3Client if browser is detected
1687
1817
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1688
- var ic3ClientCDNUrl;
1818
+ var ic3ClientCDNUrl, IC3Client;
1689
1819
  var _this = this;
1690
1820
  var _a;
1691
1821
  return __generator(this, function (_b) {
@@ -1696,6 +1826,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1696
1826
  IC3Client: ic3ClientCDNUrl
1697
1827
  });
1698
1828
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1829
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1830
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1831
+ hostType: HostType_1.default.IFrame,
1832
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1833
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1834
+ })];
1835
+ case 1:
1836
+ IC3Client = _b.sent();
1837
+ return [2 /*return*/, resolve(IC3Client)];
1838
+ case 2:
1699
1839
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1700
1840
  var ic3sdk, IC3SDKProvider, IC3Client;
1701
1841
  return __generator(this, function (_a) {
@@ -1732,7 +1872,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1732
1872
  });
1733
1873
  reject('Failed to load IC3Client');
1734
1874
  })];
1735
- case 1:
1875
+ case 3:
1736
1876
  _b.sent();
1737
1877
  return [2 /*return*/];
1738
1878
  }
@@ -1744,15 +1884,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1744
1884
  };
1745
1885
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1746
1886
  return __awaiter(this, void 0, void 0, function () {
1747
- 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;
1748
- return __generator(this, function (_b) {
1749
- switch (_b.label) {
1887
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1888
+ return __generator(this, function (_a) {
1889
+ switch (_a.label) {
1750
1890
  case 0:
1751
- _b.trys.push([0, 8, , 9]);
1891
+ _a.trys.push([0, 4, , 5]);
1752
1892
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1753
1893
  case 1:
1754
- liveChatConfig = _b.sent();
1755
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1894
+ liveChatConfig = _a.sent();
1895
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1896
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1897
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1756
1898
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1757
1899
  /* istanbul ignore next */
1758
1900
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1775,47 +1917,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1775
1917
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1776
1918
  this.preChatSurvey = preChatSurvey;
1777
1919
  }
1778
- if (!this.authSettings) return [3 /*break*/, 7];
1779
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1780
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1781
- _b.label = 2;
1920
+ if (!this.authSettings) return [3 /*break*/, 3];
1921
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1782
1922
  case 2:
1783
- _b.trys.push([2, 4, , 5]);
1784
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1923
+ _a.sent();
1924
+ _a.label = 3;
1785
1925
  case 3:
1786
- token = _b.sent();
1787
- if (token) {
1788
- this.authenticatedUserToken = token;
1789
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1790
- }
1791
- else {
1792
- exceptionDetails = {
1793
- response: "UndefinedAuthToken"
1794
- };
1795
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1796
- ExceptionDetails: JSON.stringify(exceptionDetails)
1797
- });
1798
- }
1799
- return [3 /*break*/, 5];
1800
- case 4:
1801
- _a = _b.sent();
1802
- exceptionDetails = {
1803
- response: "GetAuthTokenFailed"
1804
- };
1805
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1806
- ExceptionDetails: JSON.stringify(exceptionDetails)
1807
- });
1808
- return [3 /*break*/, 5];
1809
- case 5: return [3 /*break*/, 7];
1810
- case 6:
1811
- exceptionDetails = {
1812
- response: "GetAuthTokenNotFound"
1813
- };
1814
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1815
- ExceptionDetails: JSON.stringify(exceptionDetails)
1816
- });
1817
- _b.label = 7;
1818
- case 7:
1819
1926
  if (this.preChatSurvey) {
1820
1927
  /* istanbul ignore next */
1821
1928
  this.debug && console.log('Prechat Survey!');
@@ -1823,11 +1930,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1823
1930
  this.callingOption = msdyn_callingoptions;
1824
1931
  this.liveChatConfig = liveChatConfig;
1825
1932
  return [2 /*return*/, this.liveChatConfig];
1826
- case 8:
1827
- error_18 = _b.sent();
1933
+ case 4:
1934
+ error_18 = _a.sent();
1828
1935
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1829
1936
  return [2 /*return*/, error_18];
1830
- case 9: return [2 /*return*/];
1937
+ case 5: return [2 /*return*/];
1831
1938
  }
1832
1939
  });
1833
1940
  });
@@ -1909,6 +2016,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
1909
2016
  });
1910
2017
  });
1911
2018
  };
2019
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2020
+ return __awaiter(this, void 0, void 0, function () {
2021
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2022
+ return __generator(this, function (_b) {
2023
+ switch (_b.label) {
2024
+ case 0:
2025
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2026
+ this.chatSDKConfig.getAuthToken = provider;
2027
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2028
+ _b.label = 1;
2029
+ case 1:
2030
+ _b.trys.push([1, 3, , 4]);
2031
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2032
+ case 2:
2033
+ token = _b.sent();
2034
+ if (token) {
2035
+ this.authenticatedUserToken = token;
2036
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2037
+ }
2038
+ else {
2039
+ exceptionDetails = {
2040
+ response: "UndefinedAuthToken"
2041
+ };
2042
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2043
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2044
+ });
2045
+ }
2046
+ return [3 /*break*/, 4];
2047
+ case 3:
2048
+ _a = _b.sent();
2049
+ exceptionDetails = {
2050
+ response: "GetAuthTokenFailed"
2051
+ };
2052
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2053
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2054
+ });
2055
+ return [3 /*break*/, 4];
2056
+ case 4: return [3 /*break*/, 6];
2057
+ case 5:
2058
+ exceptionDetails = {
2059
+ response: "GetAuthTokenNotFound"
2060
+ };
2061
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2062
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2063
+ });
2064
+ _b.label = 6;
2065
+ case 6: return [2 /*return*/];
2066
+ }
2067
+ });
2068
+ });
2069
+ };
1912
2070
  return OmnichannelChatSDK;
1913
2071
  }());
1914
2072
  exports.default = OmnichannelChatSDK;