@microsoft/omnichannel-chat-sdk 1.0.1-main.c789d78 → 1.0.1-main.d137e38

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 (39) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/README.md +39 -40
  3. package/lib/OmnichannelChatSDK.d.ts +3 -3
  4. package/lib/OmnichannelChatSDK.js +196 -234
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/config/settings.d.ts +1 -1
  7. package/lib/config/settings.js +1 -1
  8. package/lib/config/settings.js.map +1 -1
  9. package/lib/core/ChatConfig.d.ts +3 -0
  10. package/lib/core/messaging/ACSClient.js +1 -1
  11. package/lib/core/messaging/ACSClient.js.map +1 -1
  12. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  13. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  14. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  15. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  16. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  17. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  18. package/lib/telemetry/AriaTelemetry.js +5 -0
  19. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  20. package/lib/telemetry/ScenarioMarker.d.ts +2 -0
  21. package/lib/telemetry/ScenarioMarker.js +7 -3
  22. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  23. package/lib/telemetry/TelemetryEvent.d.ts +1 -3
  24. package/lib/telemetry/TelemetryEvent.js +0 -2
  25. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +760 -1075
  27. package/lib/utils/WebUtils.d.ts +3 -1
  28. package/lib/utils/WebUtils.js +8 -2
  29. package/lib/utils/WebUtils.js.map +1 -1
  30. package/lib/utils/libraries.d.ts +1 -3
  31. package/lib/utils/libraries.js +2 -11
  32. package/lib/utils/libraries.js.map +1 -1
  33. package/lib/utils/locale.d.ts +1 -0
  34. package/lib/utils/locale.js +2 -1
  35. package/lib/utils/locale.js.map +1 -1
  36. package/lib/utils/loggers.d.ts +8 -0
  37. package/lib/utils/loggers.js +24 -0
  38. package/lib/utils/loggers.js.map +1 -1
  39. package/package.json +2 -2
@@ -58,7 +58,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
58
58
  var loggers_1 = require("./utils/loggers");
59
59
  var ACSClient_1 = require("./core/messaging/ACSClient");
60
60
  var ocsdk_1 = require("@microsoft/ocsdk");
61
- var libraries_1 = require("./utils/libraries");
62
61
  var platform_1 = require("./utils/platform");
63
62
  var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
64
63
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
@@ -66,6 +65,8 @@ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
66
65
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
67
66
  var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
68
67
  var ConversationMode_1 = require("./core/ConversationMode");
68
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
69
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
70
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
71
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
@@ -85,6 +86,7 @@ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
85
86
  var MessageTags_1 = require("./core/messaging/MessageTags");
86
87
  var locale_1 = require("./utils/locale");
87
88
  var utilities_1 = require("./utils/utilities");
89
+ var libraries_1 = require("./utils/libraries");
88
90
  var WebUtils_1 = require("./utils/WebUtils");
89
91
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
90
92
  var OmnichannelChatSDK = /** @class */ (function () {
@@ -107,11 +109,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
107
109
  this.reconnectId = null;
108
110
  this.refreshTokenTimer = null;
109
111
  this.debug = false;
112
+ this.runtimeId = ocsdk_1.uuidv4();
110
113
  this.omnichannelConfig = omnichannelConfig;
111
114
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
112
115
  );
113
116
  this.isInitialized = false;
114
117
  this.liveChatVersion = LiveChatVersion_1.default.V1;
118
+ this.localeId = locale_1.defaultLocaleId;
115
119
  this.requestId = ocsdk_1.uuidv4();
116
120
  this.chatToken = {};
117
121
  this.liveChatConfig = {};
@@ -129,6 +133,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
129
133
  this.ocSdkLogger.useTelemetry(this.telemetry);
130
134
  this.acsClientLogger.useTelemetry(this.telemetry);
131
135
  this.acsAdapterLogger.useTelemetry(this.telemetry);
136
+ this.scenarioMarker.setRuntimeId(this.runtimeId);
137
+ this.ic3ClientLogger.setRuntimeId(this.runtimeId);
138
+ this.ocSdkLogger.setRuntimeId(this.runtimeId);
139
+ this.acsClientLogger.setRuntimeId(this.runtimeId);
140
+ this.acsAdapterLogger.setRuntimeId(this.runtimeId);
132
141
  OmnichannelConfigValidator_1.default(omnichannelConfig);
133
142
  SDKConfigValidators_1.default(chatSDKConfig);
134
143
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -292,44 +301,52 @@ var OmnichannelChatSDK = /** @class */ (function () {
292
301
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
293
302
  if (optionalParams === void 0) { optionalParams = {}; }
294
303
  return __awaiter(this, void 0, void 0, function () {
295
- var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
304
+ var shouldReinitIC3Client, _p, reconnectableChatsParams, reconnectableChatsResponse, _q, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _r, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _s, error_8, exceptionDetails;
296
305
  var _this = this;
297
- return __generator(this, function (_s) {
298
- switch (_s.label) {
306
+ return __generator(this, function (_t) {
307
+ switch (_t.label) {
299
308
  case 0:
300
309
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
301
310
  RequestId: this.requestId
302
311
  });
312
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
313
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
314
+ _p = this;
315
+ return [4 /*yield*/, this.getIC3Client()];
316
+ case 1:
317
+ _p.IC3Client = _t.sent();
318
+ _t.label = 2;
319
+ case 2:
303
320
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
304
321
  this.reconnectId = optionalParams.reconnectId;
305
322
  }
306
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
307
- _s.label = 1;
308
- case 1:
309
- _s.trys.push([1, 3, , 4]);
323
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
324
+ _t.label = 3;
325
+ case 3:
326
+ _t.trys.push([3, 5, , 6]);
310
327
  reconnectableChatsParams = {
311
328
  authenticatedUserToken: this.authenticatedUserToken
312
329
  };
313
330
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
314
- case 2:
315
- reconnectableChatsResponse = _s.sent();
331
+ case 4:
332
+ reconnectableChatsResponse = _t.sent();
316
333
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
317
334
  this.reconnectId = reconnectableChatsResponse.reconnectid;
318
335
  }
319
- return [3 /*break*/, 4];
320
- case 3:
321
- _p = _s.sent();
336
+ return [3 /*break*/, 6];
337
+ case 5:
338
+ _q = _t.sent();
322
339
  exceptionDetails = {
323
340
  response: "OCClientGetReconnectableChatsFailed"
324
341
  };
325
342
  throw Error(exceptionDetails.response);
326
- case 4:
327
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
343
+ case 6:
344
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
328
345
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
329
346
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
330
347
  return [4 /*yield*/, this.getConversationDetails()];
331
- case 5:
332
- conversationDetails = _s.sent();
348
+ case 7:
349
+ conversationDetails = _t.sent();
333
350
  if (Object.keys(conversationDetails).length === 0) {
334
351
  exceptionDetails = {
335
352
  response: "InvalidConversation"
@@ -354,14 +371,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
354
371
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
355
372
  throw Error(exceptionDetails.response);
356
373
  }
357
- _s.label = 6;
358
- case 6:
359
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
360
- return [4 /*yield*/, this.getChatToken(false)];
361
- case 7:
362
- _s.sent();
363
- _s.label = 8;
374
+ _t.label = 8;
364
375
  case 8:
376
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
377
+ return [4 /*yield*/, this.getChatToken(false)];
378
+ case 9:
379
+ _t.sent();
380
+ _t.label = 10;
381
+ case 10:
365
382
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
366
383
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
367
384
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
@@ -369,6 +386,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
369
386
  sessionInitOptionalParams = {
370
387
  initContext: {}
371
388
  };
389
+ sessionInitOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(this.localeId);
372
390
  if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
373
391
  sessionInitOptionalParams.reconnectId = this.reconnectId;
374
392
  }
@@ -400,15 +418,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
400
418
  if (this.authenticatedUserToken) {
401
419
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
402
420
  }
403
- _s.label = 9;
404
- case 9:
405
- _s.trys.push([9, 11, , 12]);
406
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
407
- case 10:
408
- _s.sent();
409
- return [3 /*break*/, 12];
421
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
422
+ _t.label = 11;
410
423
  case 11:
411
- error_3 = _s.sent();
424
+ _t.trys.push([11, 13, , 14]);
425
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
426
+ case 12:
427
+ _t.sent();
428
+ return [3 /*break*/, 14];
429
+ case 13:
430
+ error_3 = _t.sent();
412
431
  exceptionDetails = {
413
432
  response: "OCClientSessionInitFailed"
414
433
  };
@@ -419,8 +438,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
419
438
  });
420
439
  console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
421
440
  return [2 /*return*/, error_3];
422
- case 12:
423
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
441
+ case 14:
442
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
424
443
  chatAdapterConfig = {
425
444
  token: this.chatToken.token,
426
445
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -428,18 +447,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
428
447
  environmentUrl: this.chatToken.acsEndpoint,
429
448
  pollingInterval: 1000
430
449
  };
431
- _s.label = 13;
432
- case 13:
433
- _s.trys.push([13, 15, , 16]);
450
+ _t.label = 15;
451
+ case 15:
452
+ _t.trys.push([15, 17, , 18]);
434
453
  return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
435
454
  token: chatAdapterConfig.token,
436
455
  environmentUrl: chatAdapterConfig.environmentUrl
437
456
  }))];
438
- case 14:
439
- _s.sent();
440
- return [3 /*break*/, 16];
441
- case 15:
442
- error_4 = _s.sent();
457
+ case 16:
458
+ _t.sent();
459
+ return [3 /*break*/, 18];
460
+ case 17:
461
+ error_4 = _t.sent();
443
462
  exceptionDetails = {
444
463
  response: "ACSClientInitializeFailed"
445
464
  };
@@ -450,23 +469,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
450
469
  });
451
470
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
452
471
  return [2 /*return*/, error_4];
453
- case 16:
454
- _s.trys.push([16, 18, , 19]);
455
- _q = this;
472
+ case 18:
473
+ _t.trys.push([18, 20, , 21]);
474
+ _r = this;
456
475
  return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
457
476
  id: chatAdapterConfig.id,
458
477
  threadId: chatAdapterConfig.threadId,
459
478
  pollingInterval: chatAdapterConfig.pollingInterval
460
479
  }))];
461
- case 17:
462
- _q.conversation = (_s.sent());
480
+ case 19:
481
+ _r.conversation = (_t.sent());
463
482
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
464
483
  RequestId: this.requestId,
465
484
  ChatId: this.chatToken.chatId
466
485
  });
467
- return [3 /*break*/, 19];
468
- case 18:
469
- error_5 = _s.sent();
486
+ return [3 /*break*/, 21];
487
+ case 20:
488
+ error_5 = _t.sent();
470
489
  exceptionDetails = {
471
490
  response: "ACSClientJoinConversationFailed"
472
491
  };
@@ -477,16 +496,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
477
496
  });
478
497
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
479
498
  throw Error(exceptionDetails.response);
480
- case 19:
481
- _s.trys.push([19, 21, , 22]);
499
+ case 21:
500
+ _t.trys.push([21, 23, , 24]);
482
501
  return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
483
502
  chatToken: this.chatToken
484
503
  }))];
485
- case 20:
486
- _s.sent();
487
- return [3 /*break*/, 22];
488
- case 21:
489
- error_6 = _s.sent();
504
+ case 22:
505
+ _t.sent();
506
+ return [3 /*break*/, 24];
507
+ case 23:
508
+ error_6 = _t.sent();
490
509
  exceptionDetails = {
491
510
  response: "AMSClientInitializeFailed"
492
511
  };
@@ -496,19 +515,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
496
515
  ExceptionDetails: JSON.stringify(exceptionDetails)
497
516
  });
498
517
  throw Error(exceptionDetails.response);
499
- case 22: return [3 /*break*/, 29];
500
- case 23:
501
- _s.trys.push([23, 25, , 26]);
518
+ case 24: return [3 /*break*/, 31];
519
+ case 25:
520
+ _t.trys.push([25, 27, , 28]);
502
521
  return [4 /*yield*/, this.IC3Client.initialize({
503
522
  token: this.chatToken.token,
504
523
  regionGtms: this.chatToken.regionGTMS,
505
524
  visitor: true
506
525
  })];
507
- case 24:
508
- _s.sent();
509
- return [3 /*break*/, 26];
510
- case 25:
511
- error_7 = _s.sent();
526
+ case 26:
527
+ _t.sent();
528
+ return [3 /*break*/, 28];
529
+ case 27:
530
+ error_7 = _t.sent();
512
531
  exceptionDetails = {
513
532
  response: "IC3ClientInitializeFailed"
514
533
  };
@@ -519,19 +538,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
519
538
  });
520
539
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
521
540
  return [2 /*return*/, error_7];
522
- case 26:
523
- _s.trys.push([26, 28, , 29]);
524
- _r = this;
541
+ case 28:
542
+ _t.trys.push([28, 30, , 31]);
543
+ _s = this;
525
544
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
526
- case 27:
527
- _r.conversation = _s.sent();
545
+ case 29:
546
+ _s.conversation = _t.sent();
528
547
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
529
548
  RequestId: this.requestId,
530
549
  ChatId: this.chatToken.chatId
531
550
  });
532
- return [3 /*break*/, 29];
533
- case 28:
534
- error_8 = _s.sent();
551
+ return [3 /*break*/, 31];
552
+ case 30:
553
+ error_8 = _t.sent();
535
554
  exceptionDetails = {
536
555
  response: "IC3ClientJoinConversationFailed"
537
556
  };
@@ -542,7 +561,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
542
561
  });
543
562
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
544
563
  return [2 /*return*/, error_8];
545
- case 29:
564
+ case 31:
546
565
  if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
547
566
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
548
567
  return __generator(this, function (_a) {
@@ -580,6 +599,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
580
599
  }
581
600
  if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
582
601
  isChatReconnect = this.reconnectId !== null ? true : false;
602
+ this.requestId = isChatReconnect ? this.reconnectId : this.requestId; // Chat Reconnect session to close
583
603
  sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
584
604
  }
585
605
  if (this.authenticatedUserToken) {
@@ -600,6 +620,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
600
620
  this.requestId = ocsdk_1.uuidv4();
601
621
  this.chatToken = {};
602
622
  this.reconnectId = null;
623
+ this.IC3Client.dispose();
624
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
625
+ this.IC3Client = null;
603
626
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
604
627
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
605
628
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -897,6 +920,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
897
920
  sendMessageRequest = {
898
921
  content: message.content,
899
922
  };
923
+ sendMessageRequest.metadata = {
924
+ widgetId: this.omnichannelConfig.widgetId,
925
+ clientMessageId: Date.now().toString()
926
+ };
927
+ if (message.metadata) {
928
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
929
+ }
900
930
  _e.label = 1;
901
931
  case 1:
902
932
  _e.trys.push([1, 3, , 4]);
@@ -1279,7 +1309,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1279
1309
  };
1280
1310
  sendMessageRequest = {
1281
1311
  content: '',
1282
- metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
1312
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1283
1313
  };
1284
1314
  messageToSend = {
1285
1315
  content: "",
@@ -1440,7 +1470,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1440
1470
  ChatId: this.chatToken.chatId,
1441
1471
  EmailAddress: body.emailAddress,
1442
1472
  DefaultAttachmentMessage: body.attachmentMessage,
1443
- CustomerLocale: body.locale
1473
+ CustomerLocale: body.locale || locale_1.getLocaleStringFromId(this.localeId)
1444
1474
  };
1445
1475
  emailResponse = this.OCClient.emailTranscript(this.requestId, this.chatToken.token, emailRequestBody, emailTranscriptOptionalParams);
1446
1476
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
@@ -1505,16 +1535,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
1505
1535
  }
1506
1536
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1507
1537
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1508
- var featuresOption, acsAdapterCDNUrl;
1538
+ var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1509
1539
  var _this = this;
1510
1540
  var _a;
1511
1541
  return __generator(this, function (_b) {
1512
1542
  switch (_b.label) {
1513
1543
  case 0:
1544
+ egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1545
+ ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1514
1546
  featuresOption = {
1515
- enableAdaptiveCards: false,
1547
+ enableAdaptiveCards: true,
1516
1548
  enableThreadMemberUpdateNotification: true,
1517
- enableLeaveThreadOnWindowClosed: false
1549
+ enableLeaveThreadOnWindowClosed: false,
1550
+ egressMiddleware: egressMiddlewares,
1551
+ ingressMiddleware: ingressMiddlewares
1518
1552
  };
1519
1553
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1520
1554
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
@@ -1526,7 +1560,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1526
1560
  try {
1527
1561
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1528
1562
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1529
- var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, featuresOption);
1563
+ 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
1564
+ featuresOption);
1530
1565
  resolve(adapter);
1531
1566
  }
1532
1567
  catch (_a) {
@@ -1567,8 +1602,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1567
1602
  };
1568
1603
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1569
1604
  adapter.logger = _this.ic3ClientLogger;
1570
- // Keep iframe communication alive to reuse the same IC3Client instance
1571
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1572
1605
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1573
1606
  resolve(adapter);
1574
1607
  }, function () {
@@ -1662,7 +1695,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1662
1695
  };
1663
1696
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1664
1697
  return __awaiter(this, void 0, void 0, function () {
1665
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, chatWidgetLanguage, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, msdyn_localeid, localeId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1698
+ var conversationId, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1666
1699
  return __generator(this, function (_a) {
1667
1700
  switch (_a.label) {
1668
1701
  case 0:
@@ -1672,11 +1705,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1672
1705
  _a.label = 1;
1673
1706
  case 1:
1674
1707
  _a.trys.push([1, 6, , 7]);
1675
- chatConfig = this.liveChatConfig;
1676
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1708
+ liveWSAndLiveChatEngJoin = this.liveChatConfig.LiveWSAndLiveChatEngJoin;
1677
1709
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1678
- msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1679
- localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
1680
1710
  if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1681
1711
  return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1682
1712
  case 2:
@@ -1686,7 +1716,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1686
1716
  surveyInviteLinkRequest = {
1687
1717
  "FormId": msfp_sourcesurveyidentifier,
1688
1718
  "ConversationId": conversationId,
1689
- "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1719
+ "OCLocaleCode": locale_1.getLocaleStringFromId(this.localeId) || locale_1.getLocaleStringFromId(locale_1.defaultLocaleId)
1690
1720
  };
1691
1721
  optionalParams = {
1692
1722
  "requestId": this.requestId
@@ -1749,102 +1779,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1749
1779
  });
1750
1780
  });
1751
1781
  };
1752
- OmnichannelChatSDK.prototype.initializePostChatRenderer = function () {
1753
- return __awaiter(this, void 0, void 0, function () {
1754
- var msfpEmbedScript, elm, scriptNodes, styleNodes, i, node, tmpNode, tmpNode, i, node, tmpNode;
1755
- return __generator(this, function (_a) {
1756
- if (!platform_1.isBrowser()) {
1757
- return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
1758
- }
1759
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
1760
- RequestId: this.requestId
1761
- });
1762
- try {
1763
- msfpEmbedScript = libraries_1.getMsfpEmbedScript();
1764
- elm = document.createElement('div');
1765
- elm.innerHTML = msfpEmbedScript;
1766
- scriptNodes = elm.getElementsByTagName('script');
1767
- styleNodes = elm.getElementsByTagName('link');
1768
- for (i = 0; i < scriptNodes.length; i++) {
1769
- node = scriptNodes[i];
1770
- if (node.src) {
1771
- tmpNode = document.createElement('script');
1772
- tmpNode.type = node.type;
1773
- tmpNode.src = node.src;
1774
- tmpNode.async = false;
1775
- if (!window.document.head.contains(tmpNode)) {
1776
- document.getElementsByTagName('head')[0].appendChild(tmpNode);
1777
- }
1778
- }
1779
- if (node.innerHTML) {
1780
- tmpNode = document.createElement('script');
1781
- tmpNode.innerHTML = node.innerHTML;
1782
- tmpNode.async = false;
1783
- if (!window.document.head.contains(tmpNode)) {
1784
- window.document.head.appendChild(tmpNode);
1785
- }
1786
- }
1787
- }
1788
- for (i = 0; i < styleNodes.length; i++) {
1789
- node = styleNodes[i];
1790
- if (node.href) {
1791
- tmpNode = document.createElement('link');
1792
- tmpNode.type = node.type;
1793
- tmpNode.rel = node.rel;
1794
- tmpNode.href = node.href;
1795
- if (!window.document.head.contains(tmpNode)) {
1796
- document.getElementsByTagName('head')[0].appendChild(tmpNode);
1797
- }
1798
- }
1799
- }
1800
- }
1801
- catch (ex) {
1802
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializePostChatRenderer, {
1803
- RequestId: this.requestId,
1804
- ExceptionDetails: JSON.stringify(ex)
1805
- });
1806
- return [2 /*return*/, Promise.reject("Error occurred when initializer post chat renderer. " + JSON.stringify(ex))];
1807
- }
1808
- return [2 /*return*/];
1809
- });
1810
- });
1811
- };
1812
- OmnichannelChatSDK.prototype.renderPostChatSurvey = function (containerId, postChatContext) {
1813
- return __awaiter(this, void 0, void 0, function () {
1814
- var ex_2;
1815
- return __generator(this, function (_a) {
1816
- switch (_a.label) {
1817
- case 0:
1818
- if (!platform_1.isBrowser()) {
1819
- return [2 /*return*/, Promise.reject("In-line rendering is only supported on web browsers")];
1820
- }
1821
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1822
- RequestId: this.requestId
1823
- });
1824
- _a.label = 1;
1825
- case 1:
1826
- _a.trys.push([1, 3, , 4]);
1827
- if (!postChatContext) {
1828
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1829
- RequestId: this.requestId,
1830
- ExceptionDetails: "Post Chat Context is null."
1831
- });
1832
- return [2 /*return*/, Promise.reject("Post Chat Context is null.")];
1833
- }
1834
- return [4 /*yield*/, renderSurvey(containerId, postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.surveyInviteLink, "", "", postChatContext === null || postChatContext === void 0 ? void 0 : postChatContext.formsProLocale)];
1835
- case 2: return [2 /*return*/, _a.sent()];
1836
- case 3:
1837
- ex_2 = _a.sent();
1838
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.RenderPostChatSurvey, {
1839
- RequestId: this.requestId,
1840
- ExceptionDetails: JSON.stringify(ex_2)
1841
- });
1842
- return [2 /*return*/, Promise.reject("Error occurred when rendering post chat survey. " + JSON.stringify(ex_2))];
1843
- case 4: return [2 /*return*/];
1844
- }
1845
- });
1846
- });
1847
- };
1848
1782
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1849
1783
  return __awaiter(this, void 0, void 0, function () {
1850
1784
  var IC3Client;
@@ -1871,7 +1805,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1871
1805
  this.debug && console.debug('IC3Client');
1872
1806
  // Use IC3Client if browser is detected
1873
1807
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1874
- var ic3ClientCDNUrl;
1808
+ var ic3ClientCDNUrl, IC3Client;
1875
1809
  var _this = this;
1876
1810
  var _a;
1877
1811
  return __generator(this, function (_b) {
@@ -1882,6 +1816,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1882
1816
  IC3Client: ic3ClientCDNUrl
1883
1817
  });
1884
1818
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1819
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1820
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1821
+ hostType: HostType_1.default.IFrame,
1822
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1823
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1824
+ })];
1825
+ case 1:
1826
+ IC3Client = _b.sent();
1827
+ return [2 /*return*/, resolve(IC3Client)];
1828
+ case 2:
1885
1829
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1886
1830
  var ic3sdk, IC3SDKProvider, IC3Client;
1887
1831
  return __generator(this, function (_a) {
@@ -1918,7 +1862,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1918
1862
  });
1919
1863
  reject('Failed to load IC3Client');
1920
1864
  })];
1921
- case 1:
1865
+ case 3:
1922
1866
  _b.sent();
1923
1867
  return [2 /*return*/];
1924
1868
  }
@@ -1930,15 +1874,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1930
1874
  };
1931
1875
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1932
1876
  return __awaiter(this, void 0, void 0, function () {
1933
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1934
- return __generator(this, function (_b) {
1935
- switch (_b.label) {
1877
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1878
+ return __generator(this, function (_a) {
1879
+ switch (_a.label) {
1936
1880
  case 0:
1937
- _b.trys.push([0, 8, , 9]);
1881
+ _a.trys.push([0, 4, , 5]);
1938
1882
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1939
1883
  case 1:
1940
- liveChatConfig = _b.sent();
1941
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1884
+ liveChatConfig = _a.sent();
1885
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1886
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1887
+ this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
1942
1888
  this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1943
1889
  /* istanbul ignore next */
1944
1890
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
@@ -1961,47 +1907,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1961
1907
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1962
1908
  this.preChatSurvey = preChatSurvey;
1963
1909
  }
1964
- if (!this.authSettings) return [3 /*break*/, 7];
1965
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1966
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1967
- _b.label = 2;
1910
+ if (!this.authSettings) return [3 /*break*/, 3];
1911
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1968
1912
  case 2:
1969
- _b.trys.push([2, 4, , 5]);
1970
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1913
+ _a.sent();
1914
+ _a.label = 3;
1971
1915
  case 3:
1972
- token = _b.sent();
1973
- if (token) {
1974
- this.authenticatedUserToken = token;
1975
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1976
- }
1977
- else {
1978
- exceptionDetails = {
1979
- response: "UndefinedAuthToken"
1980
- };
1981
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1982
- ExceptionDetails: JSON.stringify(exceptionDetails)
1983
- });
1984
- }
1985
- return [3 /*break*/, 5];
1986
- case 4:
1987
- _a = _b.sent();
1988
- exceptionDetails = {
1989
- response: "GetAuthTokenFailed"
1990
- };
1991
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1992
- ExceptionDetails: JSON.stringify(exceptionDetails)
1993
- });
1994
- return [3 /*break*/, 5];
1995
- case 5: return [3 /*break*/, 7];
1996
- case 6:
1997
- exceptionDetails = {
1998
- response: "GetAuthTokenNotFound"
1999
- };
2000
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2001
- ExceptionDetails: JSON.stringify(exceptionDetails)
2002
- });
2003
- _b.label = 7;
2004
- case 7:
2005
1916
  if (this.preChatSurvey) {
2006
1917
  /* istanbul ignore next */
2007
1918
  this.debug && console.log('Prechat Survey!');
@@ -2009,11 +1920,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
2009
1920
  this.callingOption = msdyn_callingoptions;
2010
1921
  this.liveChatConfig = liveChatConfig;
2011
1922
  return [2 /*return*/, this.liveChatConfig];
2012
- case 8:
2013
- error_18 = _b.sent();
1923
+ case 4:
1924
+ error_18 = _a.sent();
2014
1925
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
2015
1926
  return [2 /*return*/, error_18];
2016
- case 9: return [2 /*return*/];
1927
+ case 5: return [2 /*return*/];
2017
1928
  }
2018
1929
  });
2019
1930
  });
@@ -2095,6 +2006,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2095
2006
  });
2096
2007
  });
2097
2008
  };
2009
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2010
+ return __awaiter(this, void 0, void 0, function () {
2011
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2012
+ return __generator(this, function (_b) {
2013
+ switch (_b.label) {
2014
+ case 0:
2015
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2016
+ this.chatSDKConfig.getAuthToken = provider;
2017
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2018
+ _b.label = 1;
2019
+ case 1:
2020
+ _b.trys.push([1, 3, , 4]);
2021
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2022
+ case 2:
2023
+ token = _b.sent();
2024
+ if (token) {
2025
+ this.authenticatedUserToken = token;
2026
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2027
+ }
2028
+ else {
2029
+ exceptionDetails = {
2030
+ response: "UndefinedAuthToken"
2031
+ };
2032
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2033
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2034
+ });
2035
+ }
2036
+ return [3 /*break*/, 4];
2037
+ case 3:
2038
+ _a = _b.sent();
2039
+ exceptionDetails = {
2040
+ response: "GetAuthTokenFailed"
2041
+ };
2042
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2043
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2044
+ });
2045
+ return [3 /*break*/, 4];
2046
+ case 4: return [3 /*break*/, 6];
2047
+ case 5:
2048
+ exceptionDetails = {
2049
+ response: "GetAuthTokenNotFound"
2050
+ };
2051
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2052
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2053
+ });
2054
+ _b.label = 6;
2055
+ case 6: return [2 /*return*/];
2056
+ }
2057
+ });
2058
+ });
2059
+ };
2098
2060
  return OmnichannelChatSDK;
2099
2061
  }());
2100
2062
  exports.default = OmnichannelChatSDK;