@microsoft/omnichannel-chat-sdk 1.0.1-main.8af1160 → 1.0.1-main.935a7e1

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 (69) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +115 -73
  3. package/lib/OmnichannelChatSDK.d.ts +10 -4
  4. package/lib/OmnichannelChatSDK.js +399 -199
  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 +5 -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/LiveWorkItemDetails.d.ts +2 -0
  17. package/lib/core/OmnichannelErrorCodes.d.ts +4 -0
  18. package/lib/core/OmnichannelErrorCodes.js +8 -0
  19. package/lib/core/OmnichannelErrorCodes.js.map +1 -0
  20. package/lib/core/PostChatContext.d.ts +6 -0
  21. package/lib/core/PostChatContext.js +3 -0
  22. package/lib/core/PostChatContext.js.map +1 -0
  23. package/lib/core/messaging/ACSClient.js +1 -1
  24. package/lib/core/messaging/ACSClient.js.map +1 -1
  25. package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +14 -0
  26. package/lib/core/messaging/ChatAdapterOptionalParams.js +3 -0
  27. package/lib/core/messaging/ChatAdapterOptionalParams.js.map +1 -0
  28. package/lib/core/messaging/MessageTags.d.ts +2 -0
  29. package/lib/core/messaging/MessageTags.js +4 -2
  30. package/lib/core/messaging/MessageTags.js.map +1 -1
  31. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -0
  32. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +34 -0
  33. package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js.map +1 -0
  34. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  35. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  36. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  37. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  38. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  39. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  40. package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -0
  41. package/lib/external/CallingSDK/ICallingSDKLogData.js +3 -0
  42. package/lib/external/CallingSDK/ICallingSDKLogData.js.map +1 -0
  43. package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +12 -0
  44. package/lib/index.d.ts +7 -6
  45. package/lib/index.js +13 -8
  46. package/lib/index.js.map +1 -1
  47. package/lib/telemetry/AriaTelemetry.d.ts +1 -0
  48. package/lib/telemetry/AriaTelemetry.js +55 -0
  49. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  50. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  51. package/lib/telemetry/ScenarioMarker.js +7 -3
  52. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  53. package/lib/telemetry/ScenarioType.d.ts +1 -0
  54. package/lib/telemetry/ScenarioType.js +1 -0
  55. package/lib/telemetry/ScenarioType.js.map +1 -1
  56. package/lib/telemetry/TelemetryEvent.d.ts +2 -1
  57. package/lib/telemetry/TelemetryEvent.js +1 -0
  58. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  59. package/lib/tsconfig.tsbuildinfo +1095 -1287
  60. package/lib/utils/WebUtils.d.ts +3 -1
  61. package/lib/utils/WebUtils.js +8 -2
  62. package/lib/utils/WebUtils.js.map +1 -1
  63. package/lib/utils/locale.d.ts +4 -0
  64. package/lib/utils/locale.js +61 -0
  65. package/lib/utils/locale.js.map +1 -0
  66. package/lib/utils/loggers.d.ts +25 -0
  67. package/lib/utils/loggers.js +93 -1
  68. package/lib/utils/loggers.js.map +1 -1
  69. package/package.json +2 -2
@@ -55,41 +55,46 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
55
55
  return r;
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ var loggers_1 = require("./utils/loggers");
58
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
+ var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var locale_1 = require("./utils/locale");
62
+ var WebUtils_1 = require("./utils/WebUtils");
63
+ var platform_1 = require("./utils/platform");
64
+ var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
59
65
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
60
66
  var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
61
67
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
62
68
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
63
69
  var ConversationMode_1 = require("./core/ConversationMode");
64
- var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
65
- var loggers_1 = require("./utils/loggers");
66
- var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
67
- var createTelemetry_1 = require("./utils/createTelemetry");
68
- var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
69
- var MessageTags_1 = require("./core/messaging/MessageTags");
70
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
71
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
72
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
73
- var utilities_1 = require("./utils/utilities");
74
- var libraries_1 = require("./utils/libraries");
75
- var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
73
+ var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
76
74
  var LiveChatVersion_1 = require("./core/LiveChatVersion");
77
- var WebUtils_1 = require("./utils/WebUtils");
75
+ var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
78
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
79
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
80
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
81
- var platform_1 = require("./utils/platform");
82
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
83
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
84
- var ocsdk_1 = require("@microsoft/ocsdk");
85
- var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
86
82
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
83
+ var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
84
+ var createChannelDataEgressMiddleware_1 = require("./external/ACSAdapter/createChannelDataEgressMiddleware");
85
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
86
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
87
+ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
88
+ var createTelemetry_1 = require("./utils/createTelemetry");
89
+ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
90
+ var MessageTags_1 = require("./core/messaging/MessageTags");
91
+ var utilities_1 = require("./utils/utilities");
92
+ var libraries_1 = require("./utils/libraries");
87
93
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
88
- var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
89
94
  var OmnichannelChatSDK = /** @class */ (function () {
90
95
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
91
96
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
92
- var _a, _b, _c, _d, _e, _f, _g;
97
+ var _a, _b, _c, _d, _e, _f, _g, _h;
93
98
  this.ACSClient = null;
94
99
  this.AMSClient = null;
95
100
  this.authSettings = null;
@@ -101,16 +106,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
101
106
  this.ocSdkLogger = null;
102
107
  this.acsClientLogger = null;
103
108
  this.acsAdapterLogger = null;
109
+ this.callingSdkLogger = null;
104
110
  this.isPersistentChat = false;
105
111
  this.isChatReconnect = false;
106
112
  this.reconnectId = null;
107
113
  this.refreshTokenTimer = null;
108
114
  this.debug = false;
115
+ this.runtimeId = ocsdk_1.uuidv4();
109
116
  this.omnichannelConfig = omnichannelConfig;
110
117
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
111
118
  );
112
119
  this.isInitialized = false;
113
120
  this.liveChatVersion = LiveChatVersion_1.default.V1;
121
+ this.localeId = locale_1.defaultLocaleId;
114
122
  this.requestId = ocsdk_1.uuidv4();
115
123
  this.chatToken = {};
116
124
  this.liveChatConfig = {};
@@ -123,11 +131,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
123
131
  this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
124
132
  this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
125
133
  this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
134
+ this.callingSdkLogger = loggers_1.createCallingSDKLogger(this.omnichannelConfig);
126
135
  this.scenarioMarker.useTelemetry(this.telemetry);
127
136
  this.ic3ClientLogger.useTelemetry(this.telemetry);
128
137
  this.ocSdkLogger.useTelemetry(this.telemetry);
129
138
  this.acsClientLogger.useTelemetry(this.telemetry);
130
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);
131
147
  OmnichannelConfigValidator_1.default(omnichannelConfig);
132
148
  SDKConfigValidators_1.default(chatSDKConfig);
133
149
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -138,10 +154,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
138
154
  (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
139
155
  (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
140
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);
141
158
  }
142
159
  /* istanbul ignore next */
143
160
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
144
- var _a, _b, _c, _d, _e, _f;
161
+ var _a, _b, _c, _d, _e, _f, _g;
145
162
  this.debug = flag;
146
163
  (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
147
164
  (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
@@ -150,6 +167,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
150
167
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
151
168
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
152
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);
153
171
  };
154
172
  OmnichannelChatSDK.prototype.initialize = function () {
155
173
  return __awaiter(this, void 0, void 0, function () {
@@ -288,47 +306,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
288
306
  });
289
307
  };
290
308
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
291
- 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;
292
310
  if (optionalParams === void 0) { optionalParams = {}; }
293
311
  return __awaiter(this, void 0, void 0, function () {
294
- var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
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;
295
313
  var _this = this;
296
- return __generator(this, function (_s) {
297
- switch (_s.label) {
314
+ return __generator(this, function (_x) {
315
+ switch (_x.label) {
298
316
  case 0:
299
317
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
300
318
  RequestId: this.requestId
301
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:
302
328
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
303
329
  this.reconnectId = optionalParams.reconnectId;
304
330
  }
305
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
306
- _s.label = 1;
307
- case 1:
308
- _s.trys.push([1, 3, , 4]);
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]);
309
335
  reconnectableChatsParams = {
310
336
  authenticatedUserToken: this.authenticatedUserToken
311
337
  };
312
338
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
313
- case 2:
314
- reconnectableChatsResponse = _s.sent();
339
+ case 4:
340
+ reconnectableChatsResponse = _x.sent();
315
341
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
316
342
  this.reconnectId = reconnectableChatsResponse.reconnectid;
317
343
  }
318
- return [3 /*break*/, 4];
319
- case 3:
320
- _p = _s.sent();
344
+ return [3 /*break*/, 6];
345
+ case 5:
346
+ _u = _x.sent();
321
347
  exceptionDetails = {
322
348
  response: "OCClientGetReconnectableChatsFailed"
323
349
  };
324
350
  throw Error(exceptionDetails.response);
325
- case 4:
326
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
351
+ case 6:
352
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
327
353
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
328
354
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
329
355
  return [4 /*yield*/, this.getConversationDetails()];
330
- case 5:
331
- conversationDetails = _s.sent();
356
+ case 7:
357
+ conversationDetails = _x.sent();
332
358
  if (Object.keys(conversationDetails).length === 0) {
333
359
  exceptionDetails = {
334
360
  response: "InvalidConversation"
@@ -353,25 +379,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
353
379
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
354
380
  throw Error(exceptionDetails.response);
355
381
  }
356
- _s.label = 6;
357
- case 6:
358
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
359
- return [4 /*yield*/, this.getChatToken(false)];
360
- case 7:
361
- _s.sent();
362
- _s.label = 8;
382
+ _x.label = 8;
363
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:
364
390
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
365
391
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
366
392
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
367
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 || '');
368
395
  sessionInitOptionalParams = {
369
396
  initContext: {}
370
397
  };
371
- 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)) {
372
400
  sessionInitOptionalParams.reconnectId = this.reconnectId;
373
401
  }
374
- 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) {
375
403
  sessionInitOptionalParams.reconnectId = this.reconnectId;
376
404
  }
377
405
  if (optionalParams.customContext) {
@@ -399,27 +427,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
399
427
  if (this.authenticatedUserToken) {
400
428
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
401
429
  }
402
- _s.label = 9;
403
- case 9:
404
- _s.trys.push([9, 11, , 12]);
405
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
406
- case 10:
407
- _s.sent();
408
- return [3 /*break*/, 12];
430
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
431
+ _x.label = 11;
409
432
  case 11:
410
- 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();
411
440
  exceptionDetails = {
412
441
  response: "OCClientSessionInitFailed"
413
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
+ }
414
449
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
415
450
  RequestId: this.requestId,
416
451
  ChatId: this.chatToken.chatId,
417
452
  ExceptionDetails: JSON.stringify(exceptionDetails)
418
453
  });
419
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
420
- return [2 /*return*/, error_3];
421
- case 12:
422
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
454
+ throw new Error(exceptionDetails.response);
455
+ case 14:
456
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
423
457
  chatAdapterConfig = {
424
458
  token: this.chatToken.token,
425
459
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -427,18 +461,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
427
461
  environmentUrl: this.chatToken.acsEndpoint,
428
462
  pollingInterval: 1000
429
463
  };
430
- _s.label = 13;
431
- case 13:
432
- _s.trys.push([13, 15, , 16]);
433
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
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({
434
468
  token: chatAdapterConfig.token,
435
469
  environmentUrl: chatAdapterConfig.environmentUrl
436
470
  }))];
437
- case 14:
438
- _s.sent();
439
- return [3 /*break*/, 16];
440
- case 15:
441
- error_4 = _s.sent();
471
+ case 16:
472
+ _x.sent();
473
+ return [3 /*break*/, 18];
474
+ case 17:
475
+ error_4 = _x.sent();
442
476
  exceptionDetails = {
443
477
  response: "ACSClientInitializeFailed"
444
478
  };
@@ -449,23 +483,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
449
483
  });
450
484
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
451
485
  return [2 /*return*/, error_4];
452
- case 16:
453
- _s.trys.push([16, 18, , 19]);
454
- _q = this;
455
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
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({
456
490
  id: chatAdapterConfig.id,
457
491
  threadId: chatAdapterConfig.threadId,
458
492
  pollingInterval: chatAdapterConfig.pollingInterval
459
493
  }))];
460
- case 17:
461
- _q.conversation = (_s.sent());
494
+ case 19:
495
+ _v.conversation = (_x.sent());
462
496
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
463
497
  RequestId: this.requestId,
464
498
  ChatId: this.chatToken.chatId
465
499
  });
466
- return [3 /*break*/, 19];
467
- case 18:
468
- error_5 = _s.sent();
500
+ return [3 /*break*/, 21];
501
+ case 20:
502
+ error_5 = _x.sent();
469
503
  exceptionDetails = {
470
504
  response: "ACSClientJoinConversationFailed"
471
505
  };
@@ -476,16 +510,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
476
510
  });
477
511
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
478
512
  throw Error(exceptionDetails.response);
479
- case 19:
480
- _s.trys.push([19, 21, , 22]);
481
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
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({
482
516
  chatToken: this.chatToken
483
517
  }))];
484
- case 20:
485
- _s.sent();
486
- return [3 /*break*/, 22];
487
- case 21:
488
- error_6 = _s.sent();
518
+ case 22:
519
+ _x.sent();
520
+ return [3 /*break*/, 24];
521
+ case 23:
522
+ error_6 = _x.sent();
489
523
  exceptionDetails = {
490
524
  response: "AMSClientInitializeFailed"
491
525
  };
@@ -495,19 +529,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
495
529
  ExceptionDetails: JSON.stringify(exceptionDetails)
496
530
  });
497
531
  throw Error(exceptionDetails.response);
498
- case 22: return [3 /*break*/, 29];
499
- case 23:
500
- _s.trys.push([23, 25, , 26]);
532
+ case 24: return [3 /*break*/, 31];
533
+ case 25:
534
+ _x.trys.push([25, 27, , 28]);
501
535
  return [4 /*yield*/, this.IC3Client.initialize({
502
536
  token: this.chatToken.token,
503
537
  regionGtms: this.chatToken.regionGTMS,
504
538
  visitor: true
505
539
  })];
506
- case 24:
507
- _s.sent();
508
- return [3 /*break*/, 26];
509
- case 25:
510
- error_7 = _s.sent();
540
+ case 26:
541
+ _x.sent();
542
+ return [3 /*break*/, 28];
543
+ case 27:
544
+ error_7 = _x.sent();
511
545
  exceptionDetails = {
512
546
  response: "IC3ClientInitializeFailed"
513
547
  };
@@ -518,19 +552,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
518
552
  });
519
553
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
520
554
  return [2 /*return*/, error_7];
521
- case 26:
522
- _s.trys.push([26, 28, , 29]);
523
- _r = this;
555
+ case 28:
556
+ _x.trys.push([28, 30, , 31]);
557
+ _w = this;
524
558
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
525
- case 27:
526
- _r.conversation = _s.sent();
559
+ case 29:
560
+ _w.conversation = _x.sent();
527
561
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
528
562
  RequestId: this.requestId,
529
563
  ChatId: this.chatToken.chatId
530
564
  });
531
- return [3 /*break*/, 29];
532
- case 28:
533
- error_8 = _s.sent();
565
+ return [3 /*break*/, 31];
566
+ case 30:
567
+ error_8 = _x.sent();
534
568
  exceptionDetails = {
535
569
  response: "IC3ClientJoinConversationFailed"
536
570
  };
@@ -541,8 +575,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
541
575
  });
542
576
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
543
577
  return [2 /*return*/, error_8];
544
- case 29:
545
- 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)) {
546
580
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
547
581
  return __generator(this, function (_a) {
548
582
  switch (_a.label) {
@@ -553,7 +587,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
553
587
  return [2 /*return*/];
554
588
  }
555
589
  });
556
- }); }, (_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);
557
591
  }
558
592
  return [2 /*return*/];
559
593
  }
@@ -561,11 +595,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
561
595
  });
562
596
  };
563
597
  OmnichannelChatSDK.prototype.endChat = function () {
564
- 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;
565
599
  return __awaiter(this, void 0, void 0, function () {
566
600
  var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
567
- return __generator(this, function (_m) {
568
- switch (_m.label) {
601
+ return __generator(this, function (_p) {
602
+ switch (_p.label) {
569
603
  case 0:
570
604
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
571
605
  RequestId: this.requestId,
@@ -579,17 +613,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
579
613
  }
580
614
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
581
615
  isChatReconnect = this.reconnectId !== null ? true : false;
616
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
582
617
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
583
618
  }
584
619
  if (this.authenticatedUserToken) {
585
620
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
586
621
  }
587
- _m.label = 1;
622
+ _p.label = 1;
588
623
  case 1:
589
- _m.trys.push([1, 3, , 4]);
624
+ _p.trys.push([1, 3, , 4]);
590
625
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
591
626
  case 2:
592
- _m.sent();
627
+ _p.sent();
593
628
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
594
629
  RequestId: this.requestId,
595
630
  ChatId: this.chatToken.chatId
@@ -599,6 +634,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
599
634
  this.requestId = ocsdk_1.uuidv4();
600
635
  this.chatToken = {};
601
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
+ }
602
642
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
603
643
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
604
644
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -607,9 +647,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
607
647
  (_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
608
648
  (_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
609
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('');
610
652
  return [3 /*break*/, 4];
611
653
  case 3:
612
- error_9 = _m.sent();
654
+ error_9 = _p.sent();
613
655
  exceptionDetails = {
614
656
  response: "OCClientSessionCloseFailed"
615
657
  };
@@ -660,23 +702,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
660
702
  });
661
703
  };
662
704
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
663
- var _a, _b;
705
+ var _a, _b, _c, _d;
664
706
  return __awaiter(this, void 0, void 0, function () {
665
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
666
- return __generator(this, function (_c) {
667
- switch (_c.label) {
707
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_10;
708
+ return __generator(this, function (_e) {
709
+ switch (_e.label) {
668
710
  case 0:
669
711
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
670
712
  RequestId: this.requestId,
671
713
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
672
714
  });
673
- _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;
674
726
  case 1:
675
- _c.trys.push([1, 3, , 4]);
676
- 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)];
677
729
  case 2:
678
- lwiDetails = _c.sent();
679
- 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;
680
732
  liveWorkItemDetails = {
681
733
  state: state,
682
734
  conversationId: conversationId
@@ -684,13 +736,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
684
736
  if (agentAcceptedOn) {
685
737
  liveWorkItemDetails.agentAcceptedOn = agentAcceptedOn;
686
738
  }
739
+ if (canRenderPostChat) {
740
+ liveWorkItemDetails.canRenderPostChat = canRenderPostChat;
741
+ }
742
+ if (participantType) {
743
+ liveWorkItemDetails.participantType = participantType;
744
+ }
687
745
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
688
746
  RequestId: this.requestId,
689
- 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) || '',
690
748
  });
691
749
  return [2 /*return*/, liveWorkItemDetails];
692
750
  case 3:
693
- error_10 = _c.sent();
751
+ error_10 = _e.sent();
694
752
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
695
753
  RequestId: this.requestId,
696
754
  ChatId: this.chatToken.chatId || '',
@@ -896,6 +954,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
896
954
  sendMessageRequest = {
897
955
  content: message.content,
898
956
  };
957
+ sendMessageRequest.metadata = {
958
+ widgetId: this.omnichannelConfig.widgetId,
959
+ clientMessageId: Date.now().toString()
960
+ };
961
+ if (message.metadata) {
962
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
963
+ }
899
964
  _e.label = 1;
900
965
  case 1:
901
966
  _e.trys.push([1, 3, , 4]);
@@ -1278,7 +1343,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1278
1343
  };
1279
1344
  sendMessageRequest = {
1280
1345
  content: '',
1281
- metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
1346
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1282
1347
  };
1283
1348
  messageToSend = {
1284
1349
  content: "",
@@ -1439,7 +1504,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1439
1504
  ChatId: this.chatToken.chatId,
1440
1505
  EmailAddress: body.emailAddress,
1441
1506
  DefaultAttachmentMessage: body.attachmentMessage,
1442
- CustomerLocale: body.locale
1507
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1443
1508
  };
1444
1509
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1445
1510
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1489,32 +1554,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1489
1554
  });
1490
1555
  });
1491
1556
  };
1492
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1493
- if (protocol === void 0) { protocol = null; }
1557
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1558
+ if (optionalParams === void 0) { optionalParams = {}; }
1494
1559
  return __awaiter(this, void 0, void 0, function () {
1495
- var supportedChatAdapterProtocols;
1560
+ var protocol, supportedChatAdapterProtocols;
1496
1561
  var _this = this;
1497
1562
  return __generator(this, function (_a) {
1498
1563
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1499
1564
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1500
1565
  }
1566
+ protocol = optionalParams.protocol;
1501
1567
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1502
1568
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1503
1569
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1504
1570
  }
1505
1571
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1506
1572
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1507
- var featuresOption, acsAdapterCDNUrl;
1573
+ var options, defaultEgressMiddlewares, defaultIngressMiddlewares, egressMiddleware, ingressMiddleware, featuresOption, acsAdapterCDNUrl;
1508
1574
  var _this = this;
1509
1575
  var _a;
1510
1576
  return __generator(this, function (_b) {
1511
1577
  switch (_b.label) {
1512
1578
  case 0:
1513
- featuresOption = {
1514
- enableAdaptiveCards: false,
1515
- enableThreadMemberUpdateNotification: true,
1516
- enableLeaveThreadOnWindowClosed: false
1517
- };
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 });
1518
1587
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1519
1588
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1520
1589
  ACSAdapter: acsAdapterCDNUrl
@@ -1525,7 +1594,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1525
1594
  try {
1526
1595
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1527
1596
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1528
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, featuresOption);
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
1599
+ featuresOption);
1529
1600
  resolve(adapter);
1530
1601
  }
1531
1602
  catch (_a) {
@@ -1543,12 +1614,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1543
1614
  }
1544
1615
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1545
1616
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1546
- var ic3AdapterCDNUrl;
1617
+ var options, ic3AdapterCDNUrl;
1547
1618
  var _this = this;
1548
1619
  var _a;
1549
1620
  return __generator(this, function (_b) {
1550
1621
  switch (_b.label) {
1551
1622
  case 0:
1623
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1552
1624
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1553
1625
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1554
1626
  IC3Adapter: ic3AdapterCDNUrl
@@ -1557,17 +1629,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1557
1629
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1558
1630
  /* istanbul ignore next */
1559
1631
  _this.debug && console.debug('IC3Adapter loaded!');
1560
- var adapterConfig = {
1561
- chatToken: _this.chatToken,
1562
- userDisplayName: 'Customer',
1563
- userId: 'teamsvisitor',
1564
- sdkURL: _this.resolveIC3ClientUrl(),
1565
- sdk: _this.IC3Client
1566
- };
1632
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1633
+ );
1567
1634
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1568
1635
  adapter.logger = _this.ic3ClientLogger;
1569
- // Keep iframe communication alive to reuse the same IC3Client instance
1570
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1571
1636
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1572
1637
  resolve(adapter);
1573
1638
  }, function () {
@@ -1588,16 +1653,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
1588
1653
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1589
1654
  if (params === void 0) { params = {}; }
1590
1655
  return __awaiter(this, void 0, void 0, function () {
1591
- var chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1656
+ var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1592
1657
  var _this = this;
1593
1658
  return __generator(this, function (_a) {
1594
1659
  switch (_a.label) {
1595
1660
  case 0:
1661
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1596
1662
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1597
- 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);
1598
1671
  }
1599
1672
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1600
- 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);
1601
1681
  }
1602
1682
  return [4 /*yield*/, this.getChatConfig()];
1603
1683
  case 1:
@@ -1607,25 +1687,27 @@ var OmnichannelChatSDK = /** @class */ (function () {
1607
1687
  widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
1608
1688
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1609
1689
  if (result && result.length) {
1610
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1611
- var LiveChatWidgetLibCDNUrl;
1690
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
1691
+ var LiveChatWidgetLibCDNUrl, defaultParams;
1612
1692
  var _this = this;
1613
1693
  var _a;
1614
1694
  return __generator(this, function (_b) {
1615
1695
  switch (_b.label) {
1616
1696
  case 0:
1617
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1618
1697
  LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1619
1698
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1620
1699
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1621
1700
  });
1701
+ defaultParams = {
1702
+ logger: this.callingSdkLogger
1703
+ };
1622
1704
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
1623
1705
  var VoiceVideoCalling;
1624
1706
  return __generator(this, function (_a) {
1625
1707
  switch (_a.label) {
1626
1708
  case 0:
1627
1709
  this.debug && console.debug(LiveChatWidgetLibCDNUrl + " loaded!");
1628
- return [4 /*yield*/, createVoiceVideoCalling_1.default(params)];
1710
+ return [4 /*yield*/, createVoiceVideoCalling_1.default(__assign(__assign({}, params), defaultParams))];
1629
1711
  case 1:
1630
1712
  VoiceVideoCalling = _a.sent();
1631
1713
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
@@ -1638,13 +1720,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1638
1720
  var exceptionDetails;
1639
1721
  return __generator(this, function (_a) {
1640
1722
  exceptionDetails = {
1641
- response: "VoiceVideoCallingLoadFailed"
1723
+ response: "VoiceVideoCallingLoadFailed",
1724
+ message: "Failed to load VoiceVideoCalling"
1642
1725
  };
1643
1726
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1644
1727
  ExceptionDetails: JSON.stringify(exceptionDetails)
1645
1728
  });
1646
- reject('Failed to load VoiceVideoCalling');
1647
- return [2 /*return*/];
1729
+ throw new Error(exceptionDetails.response);
1648
1730
  });
1649
1731
  }); })];
1650
1732
  case 1:
@@ -1659,6 +1741,96 @@ var OmnichannelChatSDK = /** @class */ (function () {
1659
1741
  });
1660
1742
  });
1661
1743
  };
1744
+ OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1745
+ return __awaiter(this, void 0, void 0, function () {
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;
1747
+ return __generator(this, function (_a) {
1748
+ switch (_a.label) {
1749
+ case 0:
1750
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1751
+ RequestId: this.requestId
1752
+ });
1753
+ _a.label = 1;
1754
+ case 1:
1755
+ _a.trys.push([1, 6, , 7]);
1756
+ chatConfig = this.liveChatConfig;
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()];
1761
+ case 2:
1762
+ liveWorkItemDetails = _a.sent();
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;
1766
+ surveyInviteLinkRequest = {
1767
+ "FormId": participantType === "Bot" ? msfp_botsourcesurveyidentifier : msfp_sourcesurveyidentifier,
1768
+ "ConversationId": conversationId,
1769
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId)
1770
+ };
1771
+ optionalParams = {
1772
+ "requestId": this.requestId
1773
+ };
1774
+ if (this.authenticatedUserToken) {
1775
+ optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1776
+ }
1777
+ ownerId = participantType === "Bot" ? postConversationBotSurveyOwnerId : postConversationSurveyOwnerId;
1778
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(ownerId, surveyInviteLinkRequest, optionalParams)];
1779
+ case 3:
1780
+ surveyInviteLinkResponse = _a.sent();
1781
+ surveyInviteLink = void 0, formsProLocale = void 0;
1782
+ if (surveyInviteLinkResponse != null) {
1783
+ if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1784
+ surveyInviteLink = surveyInviteLinkResponse.inviteList[0].invitationLink;
1785
+ }
1786
+ else {
1787
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1788
+ ConversationId: conversationId,
1789
+ RequestId: this.requestId,
1790
+ ExceptionDetails: "Survey Invite link failed to send response."
1791
+ });
1792
+ return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1793
+ }
1794
+ if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1795
+ formsProLocale = surveyInviteLinkResponse.formsProLocaleCode;
1796
+ }
1797
+ postChatContext = {
1798
+ participantJoined: participantJoined,
1799
+ participantType: participantType,
1800
+ surveyInviteLink: surveyInviteLink,
1801
+ formsProLocale: formsProLocale
1802
+ };
1803
+ return [2 /*return*/, Promise.resolve(postChatContext)];
1804
+ }
1805
+ else {
1806
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1807
+ ConversationId: conversationId,
1808
+ RequestId: this.requestId,
1809
+ ExceptionDetails: "surveyInviteLinkResponse is null."
1810
+ });
1811
+ return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1812
+ }
1813
+ return [3 /*break*/, 5];
1814
+ case 4:
1815
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1816
+ RequestId: this.requestId,
1817
+ ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1818
+ });
1819
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1820
+ case 5: return [3 /*break*/, 7];
1821
+ case 6:
1822
+ ex_1 = _a.sent();
1823
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1824
+ ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
1825
+ RequestId: this.requestId,
1826
+ ExceptionDetails: JSON.stringify(ex_1)
1827
+ });
1828
+ return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1829
+ case 7: return [2 /*return*/];
1830
+ }
1831
+ });
1832
+ });
1833
+ };
1662
1834
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1663
1835
  return __awaiter(this, void 0, void 0, function () {
1664
1836
  var IC3Client;
@@ -1685,7 +1857,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1685
1857
  this.debug && console.debug('IC3Client');
1686
1858
  // Use IC3Client if browser is detected
1687
1859
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1688
- var ic3ClientCDNUrl;
1860
+ var ic3ClientCDNUrl, IC3Client;
1689
1861
  var _this = this;
1690
1862
  var _a;
1691
1863
  return __generator(this, function (_b) {
@@ -1696,6 +1868,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1696
1868
  IC3Client: ic3ClientCDNUrl
1697
1869
  });
1698
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:
1699
1881
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1700
1882
  var ic3sdk, IC3SDKProvider, IC3Client;
1701
1883
  return __generator(this, function (_a) {
@@ -1732,7 +1914,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1732
1914
  });
1733
1915
  reject('Failed to load IC3Client');
1734
1916
  })];
1735
- case 1:
1917
+ case 3:
1736
1918
  _b.sent();
1737
1919
  return [2 /*return*/];
1738
1920
  }
@@ -1744,15 +1926,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1744
1926
  };
1745
1927
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1746
1928
  return __awaiter(this, void 0, void 0, function () {
1747
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1748
- return __generator(this, function (_b) {
1749
- switch (_b.label) {
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) {
1750
1932
  case 0:
1751
- _b.trys.push([0, 8, , 9]);
1933
+ _a.trys.push([0, 4, , 5]);
1752
1934
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1753
1935
  case 1:
1754
- liveChatConfig = _b.sent();
1755
- 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;
1756
1940
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1757
1941
  /* istanbul ignore next */
1758
1942
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1775,47 +1959,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1775
1959
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1776
1960
  this.preChatSurvey = preChatSurvey;
1777
1961
  }
1778
- if (!this.authSettings) return [3 /*break*/, 7];
1779
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1780
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1781
- _b.label = 2;
1962
+ if (!this.authSettings) return [3 /*break*/, 3];
1963
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1782
1964
  case 2:
1783
- _b.trys.push([2, 4, , 5]);
1784
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1965
+ _a.sent();
1966
+ _a.label = 3;
1785
1967
  case 3:
1786
- token = _b.sent();
1787
- if (token) {
1788
- this.authenticatedUserToken = token;
1789
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1790
- }
1791
- else {
1792
- exceptionDetails = {
1793
- response: "UndefinedAuthToken"
1794
- };
1795
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1796
- ExceptionDetails: JSON.stringify(exceptionDetails)
1797
- });
1798
- }
1799
- return [3 /*break*/, 5];
1800
- case 4:
1801
- _a = _b.sent();
1802
- exceptionDetails = {
1803
- response: "GetAuthTokenFailed"
1804
- };
1805
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1806
- ExceptionDetails: JSON.stringify(exceptionDetails)
1807
- });
1808
- return [3 /*break*/, 5];
1809
- case 5: return [3 /*break*/, 7];
1810
- case 6:
1811
- exceptionDetails = {
1812
- response: "GetAuthTokenNotFound"
1813
- };
1814
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1815
- ExceptionDetails: JSON.stringify(exceptionDetails)
1816
- });
1817
- _b.label = 7;
1818
- case 7:
1819
1968
  if (this.preChatSurvey) {
1820
1969
  /* istanbul ignore next */
1821
1970
  this.debug && console.log('Prechat Survey!');
@@ -1823,11 +1972,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1823
1972
  this.callingOption = msdyn_callingoptions;
1824
1973
  this.liveChatConfig = liveChatConfig;
1825
1974
  return [2 /*return*/, this.liveChatConfig];
1826
- case 8:
1827
- error_18 = _b.sent();
1975
+ case 4:
1976
+ error_18 = _a.sent();
1828
1977
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1829
1978
  return [2 /*return*/, error_18];
1830
- case 9: return [2 /*return*/];
1979
+ case 5: return [2 /*return*/];
1831
1980
  }
1832
1981
  });
1833
1982
  });
@@ -1909,6 +2058,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
1909
2058
  });
1910
2059
  });
1911
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
+ };
1912
2112
  return OmnichannelChatSDK;
1913
2113
  }());
1914
2114
  exports.default = OmnichannelChatSDK;