@microsoft/omnichannel-chat-sdk 1.0.0 → 1.0.1-main.1082fd3

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