@microsoft/omnichannel-chat-sdk 1.0.1-main.90a4f94 → 1.0.1-main.91ec7fb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +69 -59
  3. package/lib/OmnichannelChatSDK.d.ts +6 -1
  4. package/lib/OmnichannelChatSDK.js +301 -206
  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/LiveWorkItemDetails.d.ts +2 -0
  14. package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
  15. package/lib/core/OmnichannelErrorCodes.js +8 -0
  16. package/lib/core/OmnichannelErrorCodes.js.map +1 -0
  17. package/lib/core/PostChatContext.d.ts +1 -0
  18. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  19. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  20. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  21. package/lib/core/messaging/MessageTags.d.ts +2 -0
  22. package/lib/core/messaging/MessageTags.js +4 -2
  23. package/lib/core/messaging/MessageTags.js.map +1 -1
  24. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
  25. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
  26. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js.map +1 -0
  27. package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -0
  28. package/lib/external/CallingSDK/ICallingSDKLogData.js +3 -0
  29. package/lib/external/CallingSDK/ICallingSDKLogData.js.map +1 -0
  30. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  31. package/lib/telemetry/AriaTelemetry.d.ts +1 -0
  32. package/lib/telemetry/AriaTelemetry.js +55 -0
  33. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  34. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  35. package/lib/telemetry/ScenarioMarker.js +7 -3
  36. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  37. package/lib/telemetry/ScenarioType.d.ts +1 -0
  38. package/lib/telemetry/ScenarioType.js +1 -0
  39. package/lib/telemetry/ScenarioType.js.map +1 -1
  40. package/lib/tsconfig.tsbuildinfo +149 -55
  41. package/lib/utils/WebUtils.d.ts +3 -1
  42. package/lib/utils/WebUtils.js +8 -2
  43. package/lib/utils/WebUtils.js.map +1 -1
  44. package/lib/utils/locale.d.ts +1 -0
  45. package/lib/utils/locale.js +2 -1
  46. package/lib/utils/locale.js.map +1 -1
  47. package/lib/utils/loggers.d.ts +25 -0
  48. package/lib/utils/loggers.js +93 -1
  49. package/lib/utils/loggers.js.map +1 -1
  50. package/package.json +1 -1
@@ -58,6 +58,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
58
58
  var loggers_1 = require("./utils/loggers");
59
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
60
  var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var locale_1 = require("./utils/locale");
62
+ var WebUtils_1 = require("./utils/WebUtils");
61
63
  var platform_1 = require("./utils/platform");
62
64
  var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
63
65
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
@@ -65,8 +67,6 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
65
67
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
66
68
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
67
69
  var ConversationMode_1 = require("./core/ConversationMode");
68
- var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
- var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
70
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
71
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
72
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
@@ -75,24 +75,26 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
75
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
76
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
77
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
78
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
79
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
80
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
81
82
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
82
83
  var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
85
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
86
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
83
87
  var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
84
88
  var createTelemetry_1 = require("./utils/createTelemetry");
85
89
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
86
90
  var MessageTags_1 = require("./core/messaging/MessageTags");
87
- var locale_1 = require("./utils/locale");
88
91
  var utilities_1 = require("./utils/utilities");
89
92
  var libraries_1 = require("./utils/libraries");
90
- var WebUtils_1 = require("./utils/WebUtils");
91
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
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,23 +702,33 @@ 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, canRenderPostChat, participantType, 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();
683
- state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
730
+ lwiDetails = _e.sent();
731
+ state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn, canRenderPostChat = lwiDetails.CanRenderPostChat, participantType = lwiDetails.ParticipantType;
684
732
  liveWorkItemDetails = {
685
733
  state: state,
686
734
  conversationId: conversationId
@@ -688,13 +736,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
688
736
  if (agentAcceptedOn) {
689
737
  liveWorkItemDetails.agentAcceptedOn = agentAcceptedOn;
690
738
  }
739
+ if (canRenderPostChat) {
740
+ liveWorkItemDetails.canRenderPostChat = canRenderPostChat;
741
+ }
742
+ if (participantType) {
743
+ liveWorkItemDetails.participantType = participantType;
744
+ }
691
745
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
692
746
  RequestId: this.requestId,
693
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
747
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
694
748
  });
695
749
  return [2 /*return*/, liveWorkItemDetails];
696
750
  case 3:
697
- error_10 = _c.sent();
751
+ error_10 = _e.sent();
698
752
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
699
753
  RequestId: this.requestId,
700
754
  ChatId: this.chatToken.chatId || '',
@@ -1450,7 +1504,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1450
1504
  ChatId: this.chatToken.chatId,
1451
1505
  EmailAddress: body.emailAddress,
1452
1506
  DefaultAttachmentMessage: body.attachmentMessage,
1453
- CustomerLocale: body.locale
1507
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1454
1508
  };
1455
1509
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1456
1510
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1500,36 +1554,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1500
1554
  });
1501
1555
  });
1502
1556
  };
1503
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1504
- if (protocol === void 0) { protocol = null; }
1557
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1558
+ if (optionalParams === void 0) { optionalParams = {}; }
1505
1559
  return __awaiter(this, void 0, void 0, function () {
1506
- var supportedChatAdapterProtocols;
1560
+ var protocol, supportedChatAdapterProtocols;
1507
1561
  var _this = this;
1508
1562
  return __generator(this, function (_a) {
1509
1563
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1510
1564
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1511
1565
  }
1566
+ protocol = optionalParams.protocol;
1512
1567
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1513
1568
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1514
1569
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1515
1570
  }
1516
1571
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1517
1572
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1518
- var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1573
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1519
1574
  var _this = this;
1520
1575
  var _a;
1521
1576
  return __generator(this, function (_b) {
1522
1577
  switch (_b.label) {
1523
1578
  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
- };
1579
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1580
+ defaultEgressMiddlewares = [createChannelDataEgressMiddleware_1.default({ widgetId: this.omnichannelConfig.widgetId }), createFormatEgressTagsMiddleware_1.default()];
1581
+ defaultIngressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1582
+ egressMiddleware = (options === null || options === void 0 ? void 0 : options.egressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultEgressMiddlewares) : __spreadArrays(defaultEgressMiddlewares);
1583
+ ingressMiddleware = (options === null || options === void 0 ? void 0 : options.ingressMiddleware) ? __spreadArrays(options.egressMiddleware, defaultIngressMiddlewares) : __spreadArrays(defaultIngressMiddlewares);
1584
+ featuresOption = __assign(__assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false }, options), { // overrides
1585
+ ingressMiddleware: ingressMiddleware,
1586
+ egressMiddleware: egressMiddleware });
1533
1587
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1534
1588
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1535
1589
  ACSAdapter: acsAdapterCDNUrl
@@ -1540,7 +1594,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1540
1594
  try {
1541
1595
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1542
1596
  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
1597
+ var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, // chatClient
1598
+ undefined, // logger
1544
1599
  featuresOption);
1545
1600
  resolve(adapter);
1546
1601
  }
@@ -1559,12 +1614,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1559
1614
  }
1560
1615
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1561
1616
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1562
- var ic3AdapterCDNUrl;
1617
+ var options, ic3AdapterCDNUrl;
1563
1618
  var _this = this;
1564
1619
  var _a;
1565
1620
  return __generator(this, function (_b) {
1566
1621
  switch (_b.label) {
1567
1622
  case 0:
1623
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1568
1624
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1569
1625
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1570
1626
  IC3Adapter: ic3AdapterCDNUrl
@@ -1573,17 +1629,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1573
1629
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1574
1630
  /* istanbul ignore next */
1575
1631
  _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
- };
1632
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1633
+ );
1583
1634
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1584
1635
  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
1636
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1588
1637
  resolve(adapter);
1589
1638
  }, function () {
@@ -1604,16 +1653,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
1604
1653
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1605
1654
  if (params === void 0) { params = {}; }
1606
1655
  return __awaiter(this, void 0, void 0, function () {
1607
- var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1656
+ var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1608
1657
  var _this = this;
1609
1658
  return __generator(this, function (_a) {
1610
1659
  switch (_a.label) {
1611
1660
  case 0:
1661
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1612
1662
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1613
- return [2 /*return*/, Promise.reject('VoiceVideoCalling is only supported on browser')];
1663
+ exceptionDetails = {
1664
+ response: "UnsupportedPlatform",
1665
+ message: "VoiceVideoCalling is only supported on browser"
1666
+ };
1667
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1668
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1669
+ });
1670
+ throw new Error(exceptionDetails.response);
1614
1671
  }
1615
1672
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1616
- return [2 /*return*/, Promise.reject('Voice and video call is not enabled')];
1673
+ exceptionDetails = {
1674
+ response: "FeatureDisabled",
1675
+ message: "Voice and video call is not enabled"
1676
+ };
1677
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1678
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1679
+ });
1680
+ throw new Error(exceptionDetails.response);
1617
1681
  }
1618
1682
  return [4 /*yield*/, this.getChatConfig()];
1619
1683
  case 1:
@@ -1623,25 +1687,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
1623
1687
  widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
1624
1688
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1625
1689
  if (result && result.length) {
1626
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1627
- var LiveChatWidgetLibCDNUrl;
1690
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
1691
+ var LiveChatWidgetLibCDNUrl, defaultParams;
1628
1692
  var _this = this;
1629
1693
  var _a;
1630
1694
  return __generator(this, function (_b) {
1631
1695
  switch (_b.label) {
1632
1696
  case 0:
1633
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1634
1697
  LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1635
1698
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1636
1699
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1637
1700
  });
1701
+ defaultParams = {
1702
+ logger: this.callingSdkLogger
1703
+ };
1638
1704
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
1639
1705
  var VoiceVideoCalling;
1640
1706
  return __generator(this, function (_a) {
1641
1707
  switch (_a.label) {
1642
1708
  case 0:
1643
1709
  this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!");
1644
- return [4 /*yield*/, createVoiceVideoCalling_1.default(params)];
1710
+ return [4 /*yield*/, createVoiceVideoCalling_1.default(__assign(__assign({}, params), defaultParams))];
1645
1711
  case 1:
1646
1712
  VoiceVideoCalling = _a.sent();
1647
1713
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
@@ -1654,13 +1720,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1654
1720
  var exceptionDetails;
1655
1721
  return __generator(this, function (_a) {
1656
1722
  exceptionDetails = {
1657
- response: "VoiceVideoCallingLoadFailed"
1723
+ response: "VoiceVideoCallingLoadFailed",
1724
+ message: "Failed to load VoiceVideoCalling"
1658
1725
  };
1659
1726
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1660
1727
  ExceptionDetails: JSON.stringify(exceptionDetails)
1661
1728
  });
1662
- reject('Failed to load VoiceVideoCalling');
1663
- return [2 /*return*/];
1729
+ throw new Error(exceptionDetails.response);
1664
1730
  });
1665
1731
  }); })];
1666
1732
  case 1:
@@ -1677,7 +1743,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1677
1743
  };
1678
1744
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1679
1745
  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;
1746
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, liveWorkItemDetails, participantJoined, participantType, surveyInviteLinkRequest, optionalParams, ownerId, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1681
1747
  return __generator(this, function (_a) {
1682
1748
  switch (_a.label) {
1683
1749
  case 0:
@@ -1688,20 +1754,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1688
1754
  case 1:
1689
1755
  _a.trys.push([1, 6, , 7]);
1690
1756
  chatConfig = this.liveChatConfig;
1691
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1692
- 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
- if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1696
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1757
+ liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
1758
+ msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId;
1759
+ if (!(msdyn_postconversationsurveyenable === "true")) return [3 /*break*/, 4];
1760
+ return [4 /*yield*/, this.getConversationDetails()];
1697
1761
  case 2:
1698
1762
  liveWorkItemDetails = _a.sent();
1699
- participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) && (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) === "True";
1700
- conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.ConversationId;
1763
+ participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.canRenderPostChat) === "True";
1764
+ participantType = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.participantType;
1765
+ conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.conversationId;
1701
1766
  surveyInviteLinkRequest = {
1702
- "FormId": msfp_sourcesurveyidentifier,
1767
+ "FormId": participantType === "Bot" ? msfp_botsourcesurveyidentifier : msfp_sourcesurveyidentifier,
1703
1768
  "ConversationId": conversationId,
1704
- "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1769
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1705
1770
  };
1706
1771
  optionalParams = {
1707
1772
  "requestId": this.requestId
@@ -1709,7 +1774,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1709
1774
  if (this.authenticatedUserToken) {
1710
1775
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1711
1776
  }
1712
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, surveyInviteLinkRequest)];
1777
+ ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1778
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1713
1779
  case 3:
1714
1780
  surveyInviteLinkResponse = _a.sent();
1715
1781
  surveyInviteLink = void 0, formsProLocale = void 0;
@@ -1730,6 +1796,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1730
1796
  }
1731
1797
  postChatContext = {
1732
1798
  participantJoined: participantJoined,
1799
+ participantType: participantType,
1733
1800
  surveyInviteLink: surveyInviteLink,
1734
1801
  formsProLocale: formsProLocale
1735
1802
  };
@@ -1754,7 +1821,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1754
1821
  case 6:
1755
1822
  ex_1 = _a.sent();
1756
1823
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1757
- ConversationId: conversationId,
1824
+ ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1758
1825
  RequestId: this.requestId,
1759
1826
  ExceptionDetails: JSON.stringify(ex_1)
1760
1827
  });
@@ -1790,7 +1857,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1790
1857
  this.debug && console.debug('IC3Client');
1791
1858
  // Use IC3Client if browser is detected
1792
1859
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1793
- var ic3ClientCDNUrl;
1860
+ var ic3ClientCDNUrl, IC3Client;
1794
1861
  var _this = this;
1795
1862
  var _a;
1796
1863
  return __generator(this, function (_b) {
@@ -1801,6 +1868,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1801
1868
  IC3Client: ic3ClientCDNUrl
1802
1869
  });
1803
1870
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1871
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1872
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1873
+ hostType: HostType_1.default.IFrame,
1874
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1875
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1876
+ })];
1877
+ case 1:
1878
+ IC3Client = _b.sent();
1879
+ return [2 /*return*/, resolve(IC3Client)];
1880
+ case 2:
1804
1881
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1805
1882
  var ic3sdk, IC3SDKProvider, IC3Client;
1806
1883
  return __generator(this, function (_a) {
@@ -1837,7 +1914,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1837
1914
  });
1838
1915
  reject('Failed to load IC3Client');
1839
1916
  })];
1840
- case 1:
1917
+ case 3:
1841
1918
  _b.sent();
1842
1919
  return [2 /*return*/];
1843
1920
  }
@@ -1849,15 +1926,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1849
1926
  };
1850
1927
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1851
1928
  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) {
1929
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1930
+ return __generator(this, function (_a) {
1931
+ switch (_a.label) {
1855
1932
  case 0:
1856
- _b.trys.push([0, 8, , 9]);
1933
+ _a.trys.push([0, 4, , 5]);
1857
1934
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1858
1935
  case 1:
1859
- liveChatConfig = _b.sent();
1860
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1936
+ liveChatConfig = _a.sent();
1937
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1938
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1939
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1861
1940
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1862
1941
  /* istanbul ignore next */
1863
1942
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1880,47 +1959,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1880
1959
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1881
1960
  this.preChatSurvey = preChatSurvey;
1882
1961
  }
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;
1962
+ if (!this.authSettings) return [3 /*break*/, 3];
1963
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1887
1964
  case 2:
1888
- _b.trys.push([2, 4, , 5]);
1889
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1965
+ _a.sent();
1966
+ _a.label = 3;
1890
1967
  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
1968
  if (this.preChatSurvey) {
1925
1969
  /* istanbul ignore next */
1926
1970
  this.debug && console.log('Prechat Survey!');
@@ -1928,11 +1972,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1928
1972
  this.callingOption = msdyn_callingoptions;
1929
1973
  this.liveChatConfig = liveChatConfig;
1930
1974
  return [2 /*return*/, this.liveChatConfig];
1931
- case 8:
1932
- error_18 = _b.sent();
1975
+ case 4:
1976
+ error_18 = _a.sent();
1933
1977
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1934
1978
  return [2 /*return*/, error_18];
1935
- case 9: return [2 /*return*/];
1979
+ case 5: return [2 /*return*/];
1936
1980
  }
1937
1981
  });
1938
1982
  });
@@ -2014,6 +2058,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2014
2058
  });
2015
2059
  });
2016
2060
  };
2061
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2062
+ return __awaiter(this, void 0, void 0, function () {
2063
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2064
+ return __generator(this, function (_b) {
2065
+ switch (_b.label) {
2066
+ case 0:
2067
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2068
+ this.chatSDKConfig.getAuthToken = provider;
2069
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2070
+ _b.label = 1;
2071
+ case 1:
2072
+ _b.trys.push([1, 3, , 4]);
2073
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2074
+ case 2:
2075
+ token = _b.sent();
2076
+ if (token) {
2077
+ this.authenticatedUserToken = token;
2078
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2079
+ }
2080
+ else {
2081
+ exceptionDetails = {
2082
+ response: "UndefinedAuthToken"
2083
+ };
2084
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2085
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2086
+ });
2087
+ }
2088
+ return [3 /*break*/, 4];
2089
+ case 3:
2090
+ _a = _b.sent();
2091
+ exceptionDetails = {
2092
+ response: "GetAuthTokenFailed"
2093
+ };
2094
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2095
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2096
+ });
2097
+ return [3 /*break*/, 4];
2098
+ case 4: return [3 /*break*/, 6];
2099
+ case 5:
2100
+ exceptionDetails = {
2101
+ response: "GetAuthTokenNotFound"
2102
+ };
2103
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2104
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2105
+ });
2106
+ _b.label = 6;
2107
+ case 6: return [2 /*return*/];
2108
+ }
2109
+ });
2110
+ });
2111
+ };
2017
2112
  return OmnichannelChatSDK;
2018
2113
  }());
2019
2114
  exports.default = OmnichannelChatSDK;