@microsoft/omnichannel-chat-sdk 1.0.1-main.90a4f94 → 1.0.1-main.980a629

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 (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +69 -59
  3. package/lib/OmnichannelChatSDK.d.ts +6 -1
  4. package/lib/OmnichannelChatSDK.js +279 -194
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/api/createVoiceVideoCalling.js +6 -2
  7. package/lib/api/createVoiceVideoCalling.js.map +1 -1
  8. package/lib/core/ChatConfig.d.ts +1 -0
  9. package/lib/core/ChatSDKExceptionDetails.d.ts +5 -0
  10. package/lib/core/ChatSDKExceptionDetails.js +3 -0
  11. package/lib/core/ChatSDKExceptionDetails.js.map +1 -0
  12. package/lib/core/ChatTranscriptBody.d.ts +1 -1
  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/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  17. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  18. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  19. package/lib/core/messaging/MessageTags.d.ts +2 -0
  20. package/lib/core/messaging/MessageTags.js +4 -2
  21. package/lib/core/messaging/MessageTags.js.map +1 -1
  22. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
  23. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
  24. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js.map +1 -0
  25. package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -0
  26. package/lib/external/CallingSDK/ICallingSDKLogData.js +3 -0
  27. package/lib/external/CallingSDK/ICallingSDKLogData.js.map +1 -0
  28. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  29. package/lib/telemetry/AriaTelemetry.d.ts +1 -0
  30. package/lib/telemetry/AriaTelemetry.js +55 -0
  31. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  32. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  33. package/lib/telemetry/ScenarioMarker.js +7 -3
  34. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  35. package/lib/telemetry/ScenarioType.d.ts +1 -0
  36. package/lib/telemetry/ScenarioType.js +1 -0
  37. package/lib/telemetry/ScenarioType.js.map +1 -1
  38. package/lib/tsconfig.tsbuildinfo +129 -35
  39. package/lib/utils/WebUtils.d.ts +3 -1
  40. package/lib/utils/WebUtils.js +8 -2
  41. package/lib/utils/WebUtils.js.map +1 -1
  42. package/lib/utils/locale.d.ts +1 -0
  43. package/lib/utils/locale.js +2 -1
  44. package/lib/utils/locale.js.map +1 -1
  45. package/lib/utils/loggers.d.ts +25 -0
  46. package/lib/utils/loggers.js +93 -1
  47. package/lib/utils/loggers.js.map +1 -1
  48. package/package.json +1 -1
@@ -65,6 +65,7 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
65
65
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
66
66
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
67
67
  var ConversationMode_1 = require("./core/ConversationMode");
68
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
68
69
  var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
70
  var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
70
71
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
@@ -75,6 +76,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
75
76
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
76
77
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
77
78
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
79
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
78
80
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
79
81
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
80
82
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
@@ -92,7 +94,7 @@ var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValida
92
94
  var OmnichannelChatSDK = /** @class */ (function () {
93
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
94
96
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
95
- var _a, _b, _c, _d, _e, _f, _g;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h;
96
98
  this.ACSClient = null;
97
99
  this.AMSClient = null;
98
100
  this.authSettings = null;
@@ -104,16 +106,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
104
106
  this.ocSdkLogger = null;
105
107
  this.acsClientLogger = null;
106
108
  this.acsAdapterLogger = null;
109
+ this.callingSdkLogger = null;
107
110
  this.isPersistentChat = false;
108
111
  this.isChatReconnect = false;
109
112
  this.reconnectId = null;
110
113
  this.refreshTokenTimer = null;
111
114
  this.debug = false;
115
+ this.runtimeId = ocsdk_1.uuidv4();
112
116
  this.omnichannelConfig = omnichannelConfig;
113
117
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
114
118
  );
115
119
  this.isInitialized = false;
116
120
  this.liveChatVersion = LiveChatVersion_1.default.V1;
121
+ this.localeId = locale_1.defaultLocaleId;
117
122
  this.requestId = ocsdk_1.uuidv4();
118
123
  this.chatToken = {};
119
124
  this.liveChatConfig = {};
@@ -126,11 +131,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
126
131
  this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
127
132
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
128
133
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
134
+ this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
129
135
  this.scenarioMarker.useTelemetry(this.telemetry);
130
136
  this.ic3ClientLogger.useTelemetry(this.telemetry);
131
137
  this.ocSdkLogger.useTelemetry(this.telemetry);
132
138
  this.acsClientLogger.useTelemetry(this.telemetry);
133
139
  this.acsAdapterLogger.useTelemetry(this.telemetry);
140
+ this.callingSdkLogger.useTelemetry(this.telemetry);
141
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
142
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
143
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
144
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
145
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
146
+ this.callingSdkLogger.setRuntimeId(this.runtimeId);
134
147
  OmnichannelConfigValidator_1.default(omnichannelConfig);
135
148
  SDKConfigValidators_1.default(chatSDKConfig);
136
149
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -141,10 +154,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
141
154
  (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
142
155
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
143
156
  (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
157
+ (_h = this.callingSdkLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
144
158
  }
145
159
  /* istanbul ignore next */
146
160
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
147
- var _a, _b, _c, _d, _e, _f;
161
+ var _a, _b, _c, _d, _e, _f, _g;
148
162
  this.debug = flag;
149
163
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
150
164
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -153,6 +167,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
153
167
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
154
168
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
155
169
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
170
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setDebug(flag);
156
171
  };
157
172
  OmnichannelChatSDK.prototype.initialize = function () {
158
173
  return __awaiter(this, void 0, void 0, function () {
@@ -291,47 +306,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
291
306
  });
292
307
  };
293
308
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
294
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
309
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
295
310
  if (optionalParams === void 0) { optionalParams = {}; }
296
311
  return __awaiter(this, void 0, void 0, function () {
297
- var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
312
+ var shouldReinitIC3Client, _t, reconnectableChatsParams, reconnectableChatsResponse, _u, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _v, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _w, error_8, exceptionDetails;
298
313
  var _this = this;
299
- return __generator(this, function (_s) {
300
- switch (_s.label) {
314
+ return __generator(this, function (_x) {
315
+ switch (_x.label) {
301
316
  case 0:
302
317
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
303
318
  RequestId: this.requestId
304
319
  });
320
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
321
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
322
+ _t = this;
323
+ return [4 /*yield*/, this.getIC3Client()];
324
+ case 1:
325
+ _t.IC3Client = _x.sent();
326
+ _x.label = 2;
327
+ case 2:
305
328
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
306
329
  this.reconnectId = optionalParams.reconnectId;
307
330
  }
308
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
309
- _s.label = 1;
310
- case 1:
311
- _s.trys.push([1, 3, , 4]);
331
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
332
+ _x.label = 3;
333
+ case 3:
334
+ _x.trys.push([3, 5, , 6]);
312
335
  reconnectableChatsParams = {
313
336
  authenticatedUserToken: this.authenticatedUserToken
314
337
  };
315
338
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
316
- case 2:
317
- reconnectableChatsResponse = _s.sent();
339
+ case 4:
340
+ reconnectableChatsResponse = _x.sent();
318
341
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
319
342
  this.reconnectId = reconnectableChatsResponse.reconnectid;
320
343
  }
321
- return [3 /*break*/, 4];
322
- case 3:
323
- _p = _s.sent();
344
+ return [3 /*break*/, 6];
345
+ case 5:
346
+ _u = _x.sent();
324
347
  exceptionDetails = {
325
348
  response: "OCClientGetReconnectableChatsFailed"
326
349
  };
327
350
  throw Error(exceptionDetails.response);
328
- case 4:
329
- if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 6];
351
+ case 6:
352
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
330
353
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
331
354
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
332
355
  return [4 /*yield*/, this.getConversationDetails()];
333
- case 5:
334
- conversationDetails = _s.sent();
356
+ case 7:
357
+ conversationDetails = _x.sent();
335
358
  if (Object.keys(conversationDetails).length === 0) {
336
359
  exceptionDetails = {
337
360
  response: "InvalidConversation"
@@ -356,25 +379,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
356
379
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
357
380
  throw Error(exceptionDetails.response);
358
381
  }
359
- _s.label = 6;
360
- case 6:
361
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
362
- return [4 /*yield*/, this.getChatToken(false)];
363
- case 7:
364
- _s.sent();
365
- _s.label = 8;
382
+ _x.label = 8;
366
383
  case 8:
384
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
385
+ return [4 /*yield*/, this.getChatToken(false)];
386
+ case 9:
387
+ _x.sent();
388
+ _x.label = 10;
389
+ case 10:
367
390
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
368
391
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
369
392
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
370
393
  (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
394
+ (_g = this.callingSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId(this.chatToken.chatId || '');
371
395
  sessionInitOptionalParams = {
372
396
  initContext: {}
373
397
  };
374
- if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
398
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
399
+ if (this.isPersistentChat && !((_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.disable)) {
375
400
  sessionInitOptionalParams.reconnectId = this.reconnectId;
376
401
  }
377
- if (this.isChatReconnect && !((_h = this.chatSDKConfig.chatReconnect) === null || _h === void 0 ? void 0 : _h.disable) && !this.isPersistentChat) {
402
+ if (this.isChatReconnect && !((_j = this.chatSDKConfig.chatReconnect) === null || _j === void 0 ? void 0 : _j.disable) && !this.isPersistentChat) {
378
403
  sessionInitOptionalParams.reconnectId = this.reconnectId;
379
404
  }
380
405
  if (optionalParams.customContext) {
@@ -402,28 +427,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
402
427
  if (this.authenticatedUserToken) {
403
428
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
404
429
  }
405
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 12];
406
- _s.label = 9;
407
- case 9:
408
- _s.trys.push([9, 11, , 12]);
409
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
410
- case 10:
411
- _s.sent();
412
- return [3 /*break*/, 12];
430
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
431
+ _x.label = 11;
413
432
  case 11:
414
- error_3 = _s.sent();
433
+ _x.trys.push([11, 13, , 14]);
434
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
435
+ case 12:
436
+ _x.sent();
437
+ return [3 /*break*/, 14];
438
+ case 13:
439
+ error_3 = _x.sent();
415
440
  exceptionDetails = {
416
441
  response: "OCClientSessionInitFailed"
417
442
  };
443
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
444
+ if (((_k = error_3) === null || _k === void 0 ? void 0 : _k.isAxiosError) && ((_m = (_l = error_3.response) === null || _l === void 0 ? void 0 : _l.headers) === null || _m === void 0 ? void 0 : _m.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
445
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
446
+ exceptionDetails.message = 'Widget used outside of operating hours';
447
+ console.error(exceptionDetails.message);
448
+ }
418
449
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
419
450
  RequestId: this.requestId,
420
451
  ChatId: this.chatToken.chatId,
421
452
  ExceptionDetails: JSON.stringify(exceptionDetails)
422
453
  });
423
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
424
- return [2 /*return*/, error_3];
425
- case 12:
426
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
454
+ throw new Error(exceptionDetails.response);
455
+ case 14:
456
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
427
457
  chatAdapterConfig = {
428
458
  token: this.chatToken.token,
429
459
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -431,18 +461,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
431
461
  environmentUrl: this.chatToken.acsEndpoint,
432
462
  pollingInterval: 1000
433
463
  };
434
- _s.label = 13;
435
- case 13:
436
- _s.trys.push([13, 15, , 16]);
437
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
464
+ _x.label = 15;
465
+ case 15:
466
+ _x.trys.push([15, 17, , 18]);
467
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.initialize({
438
468
  token: chatAdapterConfig.token,
439
469
  environmentUrl: chatAdapterConfig.environmentUrl
440
470
  }))];
441
- case 14:
442
- _s.sent();
443
- return [3 /*break*/, 16];
444
- case 15:
445
- error_4 = _s.sent();
471
+ case 16:
472
+ _x.sent();
473
+ return [3 /*break*/, 18];
474
+ case 17:
475
+ error_4 = _x.sent();
446
476
  exceptionDetails = {
447
477
  response: "ACSClientInitializeFailed"
448
478
  };
@@ -453,23 +483,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
453
483
  });
454
484
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
455
485
  return [2 /*return*/, error_4];
456
- case 16:
457
- _s.trys.push([16, 18, , 19]);
458
- _q = this;
459
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
486
+ case 18:
487
+ _x.trys.push([18, 20, , 21]);
488
+ _v = this;
489
+ return [4 /*yield*/, ((_p = this.ACSClient) === null || _p === void 0 ? void 0 : _p.joinConversation({
460
490
  id: chatAdapterConfig.id,
461
491
  threadId: chatAdapterConfig.threadId,
462
492
  pollingInterval: chatAdapterConfig.pollingInterval
463
493
  }))];
464
- case 17:
465
- _q.conversation = (_s.sent());
494
+ case 19:
495
+ _v.conversation = (_x.sent());
466
496
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
467
497
  RequestId: this.requestId,
468
498
  ChatId: this.chatToken.chatId
469
499
  });
470
- return [3 /*break*/, 19];
471
- case 18:
472
- error_5 = _s.sent();
500
+ return [3 /*break*/, 21];
501
+ case 20:
502
+ error_5 = _x.sent();
473
503
  exceptionDetails = {
474
504
  response: "ACSClientJoinConversationFailed"
475
505
  };
@@ -480,16 +510,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
480
510
  });
481
511
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
482
512
  throw Error(exceptionDetails.response);
483
- case 19:
484
- _s.trys.push([19, 21, , 22]);
485
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
513
+ case 21:
514
+ _x.trys.push([21, 23, , 24]);
515
+ return [4 /*yield*/, ((_q = this.AMSClient) === null || _q === void 0 ? void 0 : _q.initialize({
486
516
  chatToken: this.chatToken
487
517
  }))];
488
- case 20:
489
- _s.sent();
490
- return [3 /*break*/, 22];
491
- case 21:
492
- error_6 = _s.sent();
518
+ case 22:
519
+ _x.sent();
520
+ return [3 /*break*/, 24];
521
+ case 23:
522
+ error_6 = _x.sent();
493
523
  exceptionDetails = {
494
524
  response: "AMSClientInitializeFailed"
495
525
  };
@@ -499,19 +529,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
499
529
  ExceptionDetails: JSON.stringify(exceptionDetails)
500
530
  });
501
531
  throw Error(exceptionDetails.response);
502
- case 22: return [3 /*break*/, 29];
503
- case 23:
504
- _s.trys.push([23, 25, , 26]);
532
+ case 24: return [3 /*break*/, 31];
533
+ case 25:
534
+ _x.trys.push([25, 27, , 28]);
505
535
  return [4 /*yield*/, this.IC3Client.initialize({
506
536
  token: this.chatToken.token,
507
537
  regionGtms: this.chatToken.regionGTMS,
508
538
  visitor: true
509
539
  })];
510
- case 24:
511
- _s.sent();
512
- return [3 /*break*/, 26];
513
- case 25:
514
- error_7 = _s.sent();
540
+ case 26:
541
+ _x.sent();
542
+ return [3 /*break*/, 28];
543
+ case 27:
544
+ error_7 = _x.sent();
515
545
  exceptionDetails = {
516
546
  response: "IC3ClientInitializeFailed"
517
547
  };
@@ -522,19 +552,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
522
552
  });
523
553
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
524
554
  return [2 /*return*/, error_7];
525
- case 26:
526
- _s.trys.push([26, 28, , 29]);
527
- _r = this;
555
+ case 28:
556
+ _x.trys.push([28, 30, , 31]);
557
+ _w = this;
528
558
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
529
- case 27:
530
- _r.conversation = _s.sent();
559
+ case 29:
560
+ _w.conversation = _x.sent();
531
561
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
532
562
  RequestId: this.requestId,
533
563
  ChatId: this.chatToken.chatId
534
564
  });
535
- return [3 /*break*/, 29];
536
- case 28:
537
- error_8 = _s.sent();
565
+ return [3 /*break*/, 31];
566
+ case 30:
567
+ error_8 = _x.sent();
538
568
  exceptionDetails = {
539
569
  response: "IC3ClientJoinConversationFailed"
540
570
  };
@@ -545,8 +575,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
545
575
  });
546
576
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
547
577
  return [2 /*return*/, error_8];
548
- case 29:
549
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
578
+ case 31:
579
+ if (this.isPersistentChat && !((_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.disable)) {
550
580
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
551
581
  return __generator(this, function (_a) {
552
582
  switch (_a.label) {
@@ -557,7 +587,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
557
587
  return [2 /*return*/];
558
588
  }
559
589
  });
560
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
590
+ }); }, (_s = this.chatSDKConfig.persistentChat) === null || _s === void 0 ? void 0 : _s.tokenUpdateTime);
561
591
  }
562
592
  return [2 /*return*/];
563
593
  }
@@ -565,11 +595,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
565
595
  });
566
596
  };
567
597
  OmnichannelChatSDK.prototype.endChat = function () {
568
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
598
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
569
599
  return __awaiter(this, void 0, void 0, function () {
570
600
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
571
- return __generator(this, function (_m) {
572
- switch (_m.label) {
601
+ return __generator(this, function (_p) {
602
+ switch (_p.label) {
573
603
  case 0:
574
604
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
575
605
  RequestId: this.requestId,
@@ -583,17 +613,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
583
613
  }
584
614
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
585
615
  isChatReconnect = this.reconnectId !== null ? true : false;
616
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
586
617
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
587
618
  }
588
619
  if (this.authenticatedUserToken) {
589
620
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
590
621
  }
591
- _m.label = 1;
622
+ _p.label = 1;
592
623
  case 1:
593
- _m.trys.push([1, 3, , 4]);
624
+ _p.trys.push([1, 3, , 4]);
594
625
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
595
626
  case 2:
596
- _m.sent();
627
+ _p.sent();
597
628
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
598
629
  RequestId: this.requestId,
599
630
  ChatId: this.chatToken.chatId
@@ -603,6 +634,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
603
634
  this.requestId = ocsdk_1.uuidv4();
604
635
  this.chatToken = {};
605
636
  this.reconnectId = null;
637
+ if (this.IC3Client) {
638
+ this.IC3Client.dispose();
639
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
640
+ this.IC3Client = null;
641
+ }
606
642
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
607
643
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
608
644
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -611,9 +647,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
611
647
  (_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
612
648
  (_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
613
649
  (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
650
+ (_m = this.callingSdkLogger) === null || _m === void 0 ? void 0 : _m.setRequestId(this.requestId);
651
+ (_o = this.callingSdkLogger) === null || _o === void 0 ? void 0 : _o.setChatId('');
614
652
  return [3 /*break*/, 4];
615
653
  case 3:
616
- error_9 = _m.sent();
654
+ error_9 = _p.sent();
617
655
  exceptionDetails = {
618
656
  response: "OCClientSessionCloseFailed"
619
657
  };
@@ -664,22 +702,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
664
702
  });
665
703
  };
666
704
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
667
- var _a, _b;
705
+ var _a, _b, _c, _d;
668
706
  return __awaiter(this, void 0, void 0, function () {
669
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
670
- return __generator(this, function (_c) {
671
- switch (_c.label) {
707
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
708
+ return __generator(this, function (_e) {
709
+ switch (_e.label) {
672
710
  case 0:
673
711
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
674
712
  RequestId: this.requestId,
675
713
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
676
714
  });
677
- _c.label = 1;
715
+ getLWIDetailsOptionalParams = {};
716
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
717
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
718
+ }
719
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
720
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
721
+ }
722
+ if (this.authenticatedUserToken) {
723
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
724
+ }
725
+ _e.label = 1;
678
726
  case 1:
679
- _c.trys.push([1, 3, , 4]);
680
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
727
+ _e.trys.push([1, 3, , 4]);
728
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
681
729
  case 2:
682
- lwiDetails = _c.sent();
730
+ lwiDetails = _e.sent();
683
731
  state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
684
732
  liveWorkItemDetails = {
685
733
  state: state,
@@ -690,11 +738,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
690
738
  }
691
739
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
692
740
  RequestId: this.requestId,
693
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
741
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
694
742
  });
695
743
  return [2 /*return*/, liveWorkItemDetails];
696
744
  case 3:
697
- error_10 = _c.sent();
745
+ error_10 = _e.sent();
698
746
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
699
747
  RequestId: this.requestId,
700
748
  ChatId: this.chatToken.chatId || '',
@@ -1450,7 +1498,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1450
1498
  ChatId: this.chatToken.chatId,
1451
1499
  EmailAddress: body.emailAddress,
1452
1500
  DefaultAttachmentMessage: body.attachmentMessage,
1453
- CustomerLocale: body.locale
1501
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1454
1502
  };
1455
1503
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1456
1504
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1500,36 +1548,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1500
1548
  });
1501
1549
  });
1502
1550
  };
1503
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1504
- if (protocol === void 0) { protocol = null; }
1551
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1552
+ if (optionalParams === void 0) { optionalParams = {}; }
1505
1553
  return __awaiter(this, void 0, void 0, function () {
1506
- var supportedChatAdapterProtocols;
1554
+ var protocol, supportedChatAdapterProtocols;
1507
1555
  var _this = this;
1508
1556
  return __generator(this, function (_a) {
1509
1557
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1510
1558
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1511
1559
  }
1560
+ protocol = optionalParams.protocol;
1512
1561
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1513
1562
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1514
1563
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1515
1564
  }
1516
1565
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1517
1566
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1518
- var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1567
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1519
1568
  var _this = this;
1520
1569
  var _a;
1521
1570
  return __generator(this, function (_b) {
1522
1571
  switch (_b.label) {
1523
1572
  case 0:
1524
- egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1525
- ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1526
- featuresOption = {
1527
- enableAdaptiveCards: true,
1528
- enableThreadMemberUpdateNotification: true,
1529
- enableLeaveThreadOnWindowClosed: false,
1530
- egressMiddleware: egressMiddlewares,
1531
- ingressMiddleware: ingressMiddlewares
1532
- };
1573
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1574
+ defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1575
+ defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1576
+ egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1577
+ ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1578
+ featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1579
+ ingressMiddleware: ingressMiddleware,
1580
+ egressMiddleware: egressMiddleware });
1533
1581
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1534
1582
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1535
1583
  ACSAdapter: acsAdapterCDNUrl
@@ -1540,7 +1588,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1540
1588
  try {
1541
1589
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1542
1590
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1543
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, undefined, // logger
1591
+ 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
1592
+ undefined, // logger
1544
1593
  featuresOption);
1545
1594
  resolve(adapter);
1546
1595
  }
@@ -1559,12 +1608,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1559
1608
  }
1560
1609
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1561
1610
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1562
- var ic3AdapterCDNUrl;
1611
+ var options, ic3AdapterCDNUrl;
1563
1612
  var _this = this;
1564
1613
  var _a;
1565
1614
  return __generator(this, function (_b) {
1566
1615
  switch (_b.label) {
1567
1616
  case 0:
1617
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1568
1618
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1569
1619
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1570
1620
  IC3Adapter: ic3AdapterCDNUrl
@@ -1573,17 +1623,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1573
1623
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1574
1624
  /* istanbul ignore next */
1575
1625
  _this.debug && console.debug('IC3Adapter loaded!');
1576
- var adapterConfig = {
1577
- chatToken: _this.chatToken,
1578
- userDisplayName: 'Customer',
1579
- userId: 'teamsvisitor',
1580
- sdkURL: _this.resolveIC3ClientUrl(),
1581
- sdk: _this.IC3Client
1582
- };
1626
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1627
+ );
1583
1628
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1584
1629
  adapter.logger = _this.ic3ClientLogger;
1585
- // Keep iframe communication alive to reuse the same IC3Client instance
1586
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1587
1630
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1588
1631
  resolve(adapter);
1589
1632
  }, function () {
@@ -1604,16 +1647,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
1604
1647
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1605
1648
  if (params === void 0) { params = {}; }
1606
1649
  return __awaiter(this, void 0, void 0, function () {
1607
- var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1650
+ var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1608
1651
  var _this = this;
1609
1652
  return __generator(this, function (_a) {
1610
1653
  switch (_a.label) {
1611
1654
  case 0:
1655
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1612
1656
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1613
- return [2 /*return*/, Promise.reject('VoiceVideoCalling is only supported on browser')];
1657
+ exceptionDetails = {
1658
+ response: "UnsupportedPlatform",
1659
+ message: "VoiceVideoCalling is only supported on browser"
1660
+ };
1661
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1662
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1663
+ });
1664
+ throw new Error(exceptionDetails.response);
1614
1665
  }
1615
1666
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1616
- return [2 /*return*/, Promise.reject('Voice and video call is not enabled')];
1667
+ exceptionDetails = {
1668
+ response: "FeatureDisabled",
1669
+ message: "Voice and video call is not enabled"
1670
+ };
1671
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1672
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1673
+ });
1674
+ throw new Error(exceptionDetails.response);
1617
1675
  }
1618
1676
  return [4 /*yield*/, this.getChatConfig()];
1619
1677
  case 1:
@@ -1623,25 +1681,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
1623
1681
  widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
1624
1682
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1625
1683
  if (result && result.length) {
1626
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1627
- var LiveChatWidgetLibCDNUrl;
1684
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
1685
+ var LiveChatWidgetLibCDNUrl, defaultParams;
1628
1686
  var _this = this;
1629
1687
  var _a;
1630
1688
  return __generator(this, function (_b) {
1631
1689
  switch (_b.label) {
1632
1690
  case 0:
1633
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1634
1691
  LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1635
1692
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1636
1693
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1637
1694
  });
1695
+ defaultParams = {
1696
+ logger: this.callingSdkLogger
1697
+ };
1638
1698
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
1639
1699
  var VoiceVideoCalling;
1640
1700
  return __generator(this, function (_a) {
1641
1701
  switch (_a.label) {
1642
1702
  case 0:
1643
1703
  this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!");
1644
- return [4 /*yield*/, createVoiceVideoCalling_1.default(params)];
1704
+ return [4 /*yield*/, createVoiceVideoCalling_1.default(__assign(__assign({}, params), defaultParams))];
1645
1705
  case 1:
1646
1706
  VoiceVideoCalling = _a.sent();
1647
1707
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
@@ -1654,13 +1714,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1654
1714
  var exceptionDetails;
1655
1715
  return __generator(this, function (_a) {
1656
1716
  exceptionDetails = {
1657
- response: "VoiceVideoCallingLoadFailed"
1717
+ response: "VoiceVideoCallingLoadFailed",
1718
+ message: "Failed to load VoiceVideoCalling"
1658
1719
  };
1659
1720
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1660
1721
  ExceptionDetails: JSON.stringify(exceptionDetails)
1661
1722
  });
1662
- reject('Failed to load VoiceVideoCalling');
1663
- return [2 /*return*/];
1723
+ throw new Error(exceptionDetails.response);
1664
1724
  });
1665
1725
  }); })];
1666
1726
  case 1:
@@ -1677,7 +1737,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1677
1737
  };
1678
1738
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1679
1739
  return __awaiter(this, void 0, void 0, function () {
1680
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, chatWidgetLanguage, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, msdyn_localeid, localeId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1740
+ var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1681
1741
  return __generator(this, function (_a) {
1682
1742
  switch (_a.label) {
1683
1743
  case 0:
@@ -1687,11 +1747,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1687
1747
  _a.label = 1;
1688
1748
  case 1:
1689
1749
  _a.trys.push([1, 6, , 7]);
1690
- chatConfig = this.liveChatConfig;
1691
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1750
+ liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
1692
1751
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1693
- msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1694
- localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
1695
1752
  if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1696
1753
  return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1697
1754
  case 2:
@@ -1701,7 +1758,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1701
1758
  surveyInviteLinkRequest = {
1702
1759
  "FormId": msfp_sourcesurveyidentifier,
1703
1760
  "ConversationId": conversationId,
1704
- "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1761
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
1705
1762
  };
1706
1763
  optionalParams = {
1707
1764
  "requestId": this.requestId
@@ -1790,7 +1847,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1790
1847
  this.debug && console.debug('IC3Client');
1791
1848
  // Use IC3Client if browser is detected
1792
1849
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1793
- var ic3ClientCDNUrl;
1850
+ var ic3ClientCDNUrl, IC3Client;
1794
1851
  var _this = this;
1795
1852
  var _a;
1796
1853
  return __generator(this, function (_b) {
@@ -1801,6 +1858,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1801
1858
  IC3Client: ic3ClientCDNUrl
1802
1859
  });
1803
1860
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1861
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1862
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1863
+ hostType: HostType_1.default.IFrame,
1864
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1865
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1866
+ })];
1867
+ case 1:
1868
+ IC3Client = _b.sent();
1869
+ return [2 /*return*/, resolve(IC3Client)];
1870
+ case 2:
1804
1871
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1805
1872
  var ic3sdk, IC3SDKProvider, IC3Client;
1806
1873
  return __generator(this, function (_a) {
@@ -1837,7 +1904,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1837
1904
  });
1838
1905
  reject('Failed to load IC3Client');
1839
1906
  })];
1840
- case 1:
1907
+ case 3:
1841
1908
  _b.sent();
1842
1909
  return [2 /*return*/];
1843
1910
  }
@@ -1849,15 +1916,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1849
1916
  };
1850
1917
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1851
1918
  return __awaiter(this, void 0, void 0, function () {
1852
- 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;
1853
- return __generator(this, function (_b) {
1854
- switch (_b.label) {
1919
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1920
+ return __generator(this, function (_a) {
1921
+ switch (_a.label) {
1855
1922
  case 0:
1856
- _b.trys.push([0, 8, , 9]);
1923
+ _a.trys.push([0, 4, , 5]);
1857
1924
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1858
1925
  case 1:
1859
- liveChatConfig = _b.sent();
1860
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1926
+ liveChatConfig = _a.sent();
1927
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1928
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1929
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1861
1930
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1862
1931
  /* istanbul ignore next */
1863
1932
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1880,47 +1949,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1880
1949
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1881
1950
  this.preChatSurvey = preChatSurvey;
1882
1951
  }
1883
- if (!this.authSettings) return [3 /*break*/, 7];
1884
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1885
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1886
- _b.label = 2;
1952
+ if (!this.authSettings) return [3 /*break*/, 3];
1953
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1887
1954
  case 2:
1888
- _b.trys.push([2, 4, , 5]);
1889
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1955
+ _a.sent();
1956
+ _a.label = 3;
1890
1957
  case 3:
1891
- token = _b.sent();
1892
- if (token) {
1893
- this.authenticatedUserToken = token;
1894
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1895
- }
1896
- else {
1897
- exceptionDetails = {
1898
- response: "UndefinedAuthToken"
1899
- };
1900
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1901
- ExceptionDetails: JSON.stringify(exceptionDetails)
1902
- });
1903
- }
1904
- return [3 /*break*/, 5];
1905
- case 4:
1906
- _a = _b.sent();
1907
- exceptionDetails = {
1908
- response: "GetAuthTokenFailed"
1909
- };
1910
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1911
- ExceptionDetails: JSON.stringify(exceptionDetails)
1912
- });
1913
- return [3 /*break*/, 5];
1914
- case 5: return [3 /*break*/, 7];
1915
- case 6:
1916
- exceptionDetails = {
1917
- response: "GetAuthTokenNotFound"
1918
- };
1919
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1920
- ExceptionDetails: JSON.stringify(exceptionDetails)
1921
- });
1922
- _b.label = 7;
1923
- case 7:
1924
1958
  if (this.preChatSurvey) {
1925
1959
  /* istanbul ignore next */
1926
1960
  this.debug && console.log('Prechat Survey!');
@@ -1928,11 +1962,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1928
1962
  this.callingOption = msdyn_callingoptions;
1929
1963
  this.liveChatConfig = liveChatConfig;
1930
1964
  return [2 /*return*/, this.liveChatConfig];
1931
- case 8:
1932
- error_18 = _b.sent();
1965
+ case 4:
1966
+ error_18 = _a.sent();
1933
1967
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1934
1968
  return [2 /*return*/, error_18];
1935
- case 9: return [2 /*return*/];
1969
+ case 5: return [2 /*return*/];
1936
1970
  }
1937
1971
  });
1938
1972
  });
@@ -2014,6 +2048,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2014
2048
  });
2015
2049
  });
2016
2050
  };
2051
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2052
+ return __awaiter(this, void 0, void 0, function () {
2053
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2054
+ return __generator(this, function (_b) {
2055
+ switch (_b.label) {
2056
+ case 0:
2057
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2058
+ this.chatSDKConfig.getAuthToken = provider;
2059
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2060
+ _b.label = 1;
2061
+ case 1:
2062
+ _b.trys.push([1, 3, , 4]);
2063
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2064
+ case 2:
2065
+ token = _b.sent();
2066
+ if (token) {
2067
+ this.authenticatedUserToken = token;
2068
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2069
+ }
2070
+ else {
2071
+ exceptionDetails = {
2072
+ response: "UndefinedAuthToken"
2073
+ };
2074
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2075
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2076
+ });
2077
+ }
2078
+ return [3 /*break*/, 4];
2079
+ case 3:
2080
+ _a = _b.sent();
2081
+ exceptionDetails = {
2082
+ response: "GetAuthTokenFailed"
2083
+ };
2084
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2085
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2086
+ });
2087
+ return [3 /*break*/, 4];
2088
+ case 4: return [3 /*break*/, 6];
2089
+ case 5:
2090
+ exceptionDetails = {
2091
+ response: "GetAuthTokenNotFound"
2092
+ };
2093
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2094
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2095
+ });
2096
+ _b.label = 6;
2097
+ case 6: return [2 /*return*/];
2098
+ }
2099
+ });
2100
+ });
2101
+ };
2017
2102
  return OmnichannelChatSDK;
2018
2103
  }());
2019
2104
  exports.default = OmnichannelChatSDK;