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