@microsoft/omnichannel-chat-sdk 1.0.1-main.40a9d72 → 1.0.1-main.6219e16

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.
@@ -75,6 +75,7 @@ var LiveChatVersion_1 = require("./core/LiveChatVersion");
75
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
76
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
77
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
78
+ var OmnichannelErrorCodes_1 = require("./core/OmnichannelErrorCodes");
78
79
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
79
80
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
80
81
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
@@ -298,47 +299,55 @@ var OmnichannelChatSDK = /** @class */ (function () {
298
299
  });
299
300
  };
300
301
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
301
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
302
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
302
303
  if (optionalParams === void 0) { optionalParams = {}; }
303
304
  return __awaiter(this, void 0, void 0, function () {
304
- 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;
305
+ var shouldReinitIC3Client, _s, reconnectableChatsParams, reconnectableChatsResponse, _t, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _u, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _v, error_8, exceptionDetails;
305
306
  var _this = this;
306
- return __generator(this, function (_s) {
307
- switch (_s.label) {
307
+ return __generator(this, function (_w) {
308
+ switch (_w.label) {
308
309
  case 0:
309
310
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
310
311
  RequestId: this.requestId
311
312
  });
313
+ shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
314
+ if (!shouldReinitIC3Client) return [3 /*break*/, 2];
315
+ _s = this;
316
+ return [4 /*yield*/, this.getIC3Client()];
317
+ case 1:
318
+ _s.IC3Client = _w.sent();
319
+ _w.label = 2;
320
+ case 2:
312
321
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
313
322
  this.reconnectId = optionalParams.reconnectId;
314
323
  }
315
- if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
316
- _s.label = 1;
317
- case 1:
318
- _s.trys.push([1, 3, , 4]);
324
+ if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
325
+ _w.label = 3;
326
+ case 3:
327
+ _w.trys.push([3, 5, , 6]);
319
328
  reconnectableChatsParams = {
320
329
  authenticatedUserToken: this.authenticatedUserToken
321
330
  };
322
331
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
323
- case 2:
324
- reconnectableChatsResponse = _s.sent();
332
+ case 4:
333
+ reconnectableChatsResponse = _w.sent();
325
334
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
326
335
  this.reconnectId = reconnectableChatsResponse.reconnectid;
327
336
  }
328
- return [3 /*break*/, 4];
329
- case 3:
330
- _p = _s.sent();
337
+ return [3 /*break*/, 6];
338
+ case 5:
339
+ _t = _w.sent();
331
340
  exceptionDetails = {
332
341
  response: "OCClientGetReconnectableChatsFailed"
333
342
  };
334
343
  throw Error(exceptionDetails.response);
335
- case 4:
336
- if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 6];
344
+ case 6:
345
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 8];
337
346
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
338
347
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
339
348
  return [4 /*yield*/, this.getConversationDetails()];
340
- case 5:
341
- conversationDetails = _s.sent();
349
+ case 7:
350
+ conversationDetails = _w.sent();
342
351
  if (Object.keys(conversationDetails).length === 0) {
343
352
  exceptionDetails = {
344
353
  response: "InvalidConversation"
@@ -363,14 +372,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
363
372
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
364
373
  throw Error(exceptionDetails.response);
365
374
  }
366
- _s.label = 6;
367
- case 6:
368
- if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
369
- return [4 /*yield*/, this.getChatToken(false)];
370
- case 7:
371
- _s.sent();
372
- _s.label = 8;
375
+ _w.label = 8;
373
376
  case 8:
377
+ if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 10];
378
+ return [4 /*yield*/, this.getChatToken(false)];
379
+ case 9:
380
+ _w.sent();
381
+ _w.label = 10;
382
+ case 10:
374
383
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
375
384
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
376
385
  (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
@@ -410,28 +419,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
410
419
  if (this.authenticatedUserToken) {
411
420
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
412
421
  }
413
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 12];
414
- _s.label = 9;
415
- case 9:
416
- _s.trys.push([9, 11, , 12]);
417
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
418
- case 10:
419
- _s.sent();
420
- return [3 /*break*/, 12];
422
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 14];
423
+ _w.label = 11;
421
424
  case 11:
422
- error_3 = _s.sent();
425
+ _w.trys.push([11, 13, , 14]);
426
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
427
+ case 12:
428
+ _w.sent();
429
+ return [3 /*break*/, 14];
430
+ case 13:
431
+ error_3 = _w.sent();
423
432
  exceptionDetails = {
424
433
  response: "OCClientSessionInitFailed"
425
434
  };
435
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
436
+ if (((_j = error_3) === null || _j === void 0 ? void 0 : _j.isAxiosError) && ((_l = (_k = error_3.response) === null || _k === void 0 ? void 0 : _k.headers) === null || _l === void 0 ? void 0 : _l.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
437
+ exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
438
+ exceptionDetails.message = 'Widget used outside of operating hours';
439
+ console.error(exceptionDetails.message);
440
+ }
426
441
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
427
442
  RequestId: this.requestId,
428
443
  ChatId: this.chatToken.chatId,
429
444
  ExceptionDetails: JSON.stringify(exceptionDetails)
430
445
  });
431
- console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
432
- return [2 /*return*/, error_3];
433
- case 12:
434
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
446
+ throw new Error(exceptionDetails.response);
447
+ case 14:
448
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 25];
435
449
  chatAdapterConfig = {
436
450
  token: this.chatToken.token,
437
451
  id: this.chatToken.visitorId || 'teamsvisitor',
@@ -439,18 +453,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
439
453
  environmentUrl: this.chatToken.acsEndpoint,
440
454
  pollingInterval: 1000
441
455
  };
442
- _s.label = 13;
443
- case 13:
444
- _s.trys.push([13, 15, , 16]);
445
- return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
456
+ _w.label = 15;
457
+ case 15:
458
+ _w.trys.push([15, 17, , 18]);
459
+ return [4 /*yield*/, ((_m = this.ACSClient) === null || _m === void 0 ? void 0 : _m.initialize({
446
460
  token: chatAdapterConfig.token,
447
461
  environmentUrl: chatAdapterConfig.environmentUrl
448
462
  }))];
449
- case 14:
450
- _s.sent();
451
- return [3 /*break*/, 16];
452
- case 15:
453
- error_4 = _s.sent();
463
+ case 16:
464
+ _w.sent();
465
+ return [3 /*break*/, 18];
466
+ case 17:
467
+ error_4 = _w.sent();
454
468
  exceptionDetails = {
455
469
  response: "ACSClientInitializeFailed"
456
470
  };
@@ -461,23 +475,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
461
475
  });
462
476
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
463
477
  return [2 /*return*/, error_4];
464
- case 16:
465
- _s.trys.push([16, 18, , 19]);
466
- _q = this;
467
- return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
478
+ case 18:
479
+ _w.trys.push([18, 20, , 21]);
480
+ _u = this;
481
+ return [4 /*yield*/, ((_o = this.ACSClient) === null || _o === void 0 ? void 0 : _o.joinConversation({
468
482
  id: chatAdapterConfig.id,
469
483
  threadId: chatAdapterConfig.threadId,
470
484
  pollingInterval: chatAdapterConfig.pollingInterval
471
485
  }))];
472
- case 17:
473
- _q.conversation = (_s.sent());
486
+ case 19:
487
+ _u.conversation = (_w.sent());
474
488
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
475
489
  RequestId: this.requestId,
476
490
  ChatId: this.chatToken.chatId
477
491
  });
478
- return [3 /*break*/, 19];
479
- case 18:
480
- error_5 = _s.sent();
492
+ return [3 /*break*/, 21];
493
+ case 20:
494
+ error_5 = _w.sent();
481
495
  exceptionDetails = {
482
496
  response: "ACSClientJoinConversationFailed"
483
497
  };
@@ -488,16 +502,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
488
502
  });
489
503
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
490
504
  throw Error(exceptionDetails.response);
491
- case 19:
492
- _s.trys.push([19, 21, , 22]);
493
- return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
505
+ case 21:
506
+ _w.trys.push([21, 23, , 24]);
507
+ return [4 /*yield*/, ((_p = this.AMSClient) === null || _p === void 0 ? void 0 : _p.initialize({
494
508
  chatToken: this.chatToken
495
509
  }))];
496
- case 20:
497
- _s.sent();
498
- return [3 /*break*/, 22];
499
- case 21:
500
- error_6 = _s.sent();
510
+ case 22:
511
+ _w.sent();
512
+ return [3 /*break*/, 24];
513
+ case 23:
514
+ error_6 = _w.sent();
501
515
  exceptionDetails = {
502
516
  response: "AMSClientInitializeFailed"
503
517
  };
@@ -507,19 +521,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
507
521
  ExceptionDetails: JSON.stringify(exceptionDetails)
508
522
  });
509
523
  throw Error(exceptionDetails.response);
510
- case 22: return [3 /*break*/, 29];
511
- case 23:
512
- _s.trys.push([23, 25, , 26]);
524
+ case 24: return [3 /*break*/, 31];
525
+ case 25:
526
+ _w.trys.push([25, 27, , 28]);
513
527
  return [4 /*yield*/, this.IC3Client.initialize({
514
528
  token: this.chatToken.token,
515
529
  regionGtms: this.chatToken.regionGTMS,
516
530
  visitor: true
517
531
  })];
518
- case 24:
519
- _s.sent();
520
- return [3 /*break*/, 26];
521
- case 25:
522
- error_7 = _s.sent();
532
+ case 26:
533
+ _w.sent();
534
+ return [3 /*break*/, 28];
535
+ case 27:
536
+ error_7 = _w.sent();
523
537
  exceptionDetails = {
524
538
  response: "IC3ClientInitializeFailed"
525
539
  };
@@ -530,19 +544,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
530
544
  });
531
545
  console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
532
546
  return [2 /*return*/, error_7];
533
- case 26:
534
- _s.trys.push([26, 28, , 29]);
535
- _r = this;
547
+ case 28:
548
+ _w.trys.push([28, 30, , 31]);
549
+ _v = this;
536
550
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
537
- case 27:
538
- _r.conversation = _s.sent();
551
+ case 29:
552
+ _v.conversation = _w.sent();
539
553
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
540
554
  RequestId: this.requestId,
541
555
  ChatId: this.chatToken.chatId
542
556
  });
543
- return [3 /*break*/, 29];
544
- case 28:
545
- error_8 = _s.sent();
557
+ return [3 /*break*/, 31];
558
+ case 30:
559
+ error_8 = _w.sent();
546
560
  exceptionDetails = {
547
561
  response: "IC3ClientJoinConversationFailed"
548
562
  };
@@ -553,8 +567,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
553
567
  });
554
568
  console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
555
569
  return [2 /*return*/, error_8];
556
- case 29:
557
- if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
570
+ case 31:
571
+ if (this.isPersistentChat && !((_q = this.chatSDKConfig.persistentChat) === null || _q === void 0 ? void 0 : _q.disable)) {
558
572
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
559
573
  return __generator(this, function (_a) {
560
574
  switch (_a.label) {
@@ -565,7 +579,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
565
579
  return [2 /*return*/];
566
580
  }
567
581
  });
568
- }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
582
+ }); }, (_r = this.chatSDKConfig.persistentChat) === null || _r === void 0 ? void 0 : _r.tokenUpdateTime);
569
583
  }
570
584
  return [2 /*return*/];
571
585
  }
@@ -612,6 +626,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
612
626
  this.requestId = ocsdk_1.uuidv4();
613
627
  this.chatToken = {};
614
628
  this.reconnectId = null;
629
+ if (this.IC3Client) {
630
+ this.IC3Client.dispose();
631
+ !platform_1.default.isNode() && !platform_1.default.isReactNative() && WebUtils_1.removeElementById(this.IC3Client.id);
632
+ this.IC3Client = null;
633
+ }
615
634
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
616
635
  (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
617
636
  (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
@@ -673,22 +692,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
673
692
  });
674
693
  };
675
694
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
676
- var _a, _b;
695
+ var _a, _b, _c, _d;
677
696
  return __awaiter(this, void 0, void 0, function () {
678
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
679
- return __generator(this, function (_c) {
680
- switch (_c.label) {
697
+ var getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
698
+ return __generator(this, function (_e) {
699
+ switch (_e.label) {
681
700
  case 0:
682
701
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetConversationDetails, {
683
702
  RequestId: this.requestId,
684
703
  ChatId: ((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) || '',
685
704
  });
686
- _c.label = 1;
705
+ getLWIDetailsOptionalParams = {};
706
+ if (this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable) && this.reconnectId) {
707
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
708
+ }
709
+ if (this.isChatReconnect && !((_c = this.chatSDKConfig.chatReconnect) === null || _c === void 0 ? void 0 : _c.disable) && !this.isPersistentChat && this.reconnectId) {
710
+ getLWIDetailsOptionalParams.reconnectId = this.reconnectId;
711
+ }
712
+ if (this.authenticatedUserToken) {
713
+ getLWIDetailsOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
714
+ }
715
+ _e.label = 1;
687
716
  case 1:
688
- _c.trys.push([1, 3, , 4]);
689
- return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
717
+ _e.trys.push([1, 3, , 4]);
718
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId, getLWIDetailsOptionalParams)];
690
719
  case 2:
691
- lwiDetails = _c.sent();
720
+ lwiDetails = _e.sent();
692
721
  state = lwiDetails.State, conversationId = lwiDetails.ConversationId, agentAcceptedOn = lwiDetails.AgentAcceptedOn;
693
722
  liveWorkItemDetails = {
694
723
  state: state,
@@ -699,11 +728,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
699
728
  }
700
729
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetConversationDetails, {
701
730
  RequestId: this.requestId,
702
- ChatId: ((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId) || '',
731
+ ChatId: ((_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId) || '',
703
732
  });
704
733
  return [2 /*return*/, liveWorkItemDetails];
705
734
  case 3:
706
- error_10 = _c.sent();
735
+ error_10 = _e.sent();
707
736
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
708
737
  RequestId: this.requestId,
709
738
  ChatId: this.chatToken.chatId || '',
@@ -1509,36 +1538,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1509
1538
  });
1510
1539
  });
1511
1540
  };
1512
- OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1513
- if (protocol === void 0) { protocol = null; }
1541
+ OmnichannelChatSDK.prototype.createChatAdapter = function (optionalParams) {
1542
+ if (optionalParams === void 0) { optionalParams = {}; }
1514
1543
  return __awaiter(this, void 0, void 0, function () {
1515
- var supportedChatAdapterProtocols;
1544
+ var protocol, supportedChatAdapterProtocols;
1516
1545
  var _this = this;
1517
1546
  return __generator(this, function (_a) {
1518
1547
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1519
1548
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1520
1549
  }
1550
+ protocol = optionalParams.protocol;
1521
1551
  supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1522
1552
  if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1523
1553
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1524
1554
  }
1525
1555
  if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1526
1556
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1527
- var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1557
+ var options, egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1528
1558
  var _this = this;
1529
1559
  var _a;
1530
1560
  return __generator(this, function (_b) {
1531
1561
  switch (_b.label) {
1532
1562
  case 0:
1563
+ options = optionalParams.ACSAdapter ? optionalParams.ACSAdapter.options : {};
1533
1564
  egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1534
1565
  ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1535
- featuresOption = {
1536
- enableAdaptiveCards: true,
1537
- enableThreadMemberUpdateNotification: true,
1538
- enableLeaveThreadOnWindowClosed: false,
1539
- egressMiddleware: egressMiddlewares,
1540
- ingressMiddleware: ingressMiddlewares
1541
- };
1566
+ featuresOption = __assign({ enableAdaptiveCards: true, enableThreadMemberUpdateNotification: true, enableLeaveThreadOnWindowClosed: false, egressMiddleware: egressMiddlewares, ingressMiddleware: ingressMiddlewares }, options // overrides
1567
+ );
1542
1568
  acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1543
1569
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1544
1570
  ACSAdapter: acsAdapterCDNUrl
@@ -1549,7 +1575,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1549
1575
  try {
1550
1576
  var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1551
1577
  var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1552
- 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
1578
+ 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
1579
+ undefined, // logger
1553
1580
  featuresOption);
1554
1581
  resolve(adapter);
1555
1582
  }
@@ -1568,12 +1595,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
1568
1595
  }
1569
1596
  else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1570
1597
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1571
- var ic3AdapterCDNUrl;
1598
+ var options, ic3AdapterCDNUrl;
1572
1599
  var _this = this;
1573
1600
  var _a;
1574
1601
  return __generator(this, function (_b) {
1575
1602
  switch (_b.label) {
1576
1603
  case 0:
1604
+ options = optionalParams.IC3Adapter ? optionalParams.IC3Adapter.options : {};
1577
1605
  ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1578
1606
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1579
1607
  IC3Adapter: ic3AdapterCDNUrl
@@ -1582,17 +1610,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1582
1610
  return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1583
1611
  /* istanbul ignore next */
1584
1612
  _this.debug && console.debug('IC3Adapter loaded!');
1585
- var adapterConfig = {
1586
- chatToken: _this.chatToken,
1587
- userDisplayName: 'Customer',
1588
- userId: 'teamsvisitor',
1589
- sdkURL: _this.resolveIC3ClientUrl(),
1590
- sdk: _this.IC3Client
1591
- };
1613
+ var adapterConfig = __assign({ chatToken: _this.chatToken, userDisplayName: 'Customer', userId: _this.chatToken.visitorId || 'teamsvisitor', sdkURL: _this.resolveIC3ClientUrl(), sdk: _this.IC3Client }, options // overrides
1614
+ );
1592
1615
  var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1593
1616
  adapter.logger = _this.ic3ClientLogger;
1594
- // Keep iframe communication alive to reuse the same IC3Client instance
1595
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1596
1617
  _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1597
1618
  resolve(adapter);
1598
1619
  }, function () {
@@ -1796,7 +1817,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1796
1817
  this.debug && console.debug('IC3Client');
1797
1818
  // Use IC3Client if browser is detected
1798
1819
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1799
- var ic3ClientCDNUrl;
1820
+ var ic3ClientCDNUrl, IC3Client;
1800
1821
  var _this = this;
1801
1822
  var _a;
1802
1823
  return __generator(this, function (_b) {
@@ -1807,6 +1828,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1807
1828
  IC3Client: ic3ClientCDNUrl
1808
1829
  });
1809
1830
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetIC3Client);
1831
+ if (!this.IC3SDKProvider) return [3 /*break*/, 2];
1832
+ return [4 /*yield*/, this.IC3SDKProvider.getSDK({
1833
+ hostType: HostType_1.default.IFrame,
1834
+ protocolType: ProtocoleType_1.default.IC3V1SDK,
1835
+ logger: this.ic3ClientLogger // eslint-disable-line @typescript-eslint/no-explicit-any
1836
+ })];
1837
+ case 1:
1838
+ IC3Client = _b.sent();
1839
+ return [2 /*return*/, resolve(IC3Client)];
1840
+ case 2:
1810
1841
  window.addEventListener("ic3:sdk:load", function () { return __awaiter(_this, void 0, void 0, function () {
1811
1842
  var ic3sdk, IC3SDKProvider, IC3Client;
1812
1843
  return __generator(this, function (_a) {
@@ -1843,7 +1874,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1843
1874
  });
1844
1875
  reject('Failed to load IC3Client');
1845
1876
  })];
1846
- case 1:
1877
+ case 3:
1847
1878
  _b.sent();
1848
1879
  return [2 /*return*/];
1849
1880
  }
@@ -1855,14 +1886,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
1855
1886
  };
1856
1887
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1857
1888
  return __awaiter(this, void 0, void 0, function () {
1858
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
1859
- return __generator(this, function (_b) {
1860
- switch (_b.label) {
1889
+ var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1890
+ return __generator(this, function (_a) {
1891
+ switch (_a.label) {
1861
1892
  case 0:
1862
- _b.trys.push([0, 8, , 9]);
1893
+ _a.trys.push([0, 4, , 5]);
1863
1894
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1864
1895
  case 1:
1865
- liveChatConfig = _b.sent();
1896
+ liveChatConfig = _a.sent();
1866
1897
  dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
1867
1898
  msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1868
1899
  this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
@@ -1888,47 +1919,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1888
1919
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1889
1920
  this.preChatSurvey = preChatSurvey;
1890
1921
  }
1891
- if (!this.authSettings) return [3 /*break*/, 7];
1892
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1893
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1894
- _b.label = 2;
1922
+ if (!this.authSettings) return [3 /*break*/, 3];
1923
+ return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
1895
1924
  case 2:
1896
- _b.trys.push([2, 4, , 5]);
1897
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1925
+ _a.sent();
1926
+ _a.label = 3;
1898
1927
  case 3:
1899
- token = _b.sent();
1900
- if (token) {
1901
- this.authenticatedUserToken = token;
1902
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1903
- }
1904
- else {
1905
- exceptionDetails = {
1906
- response: "UndefinedAuthToken"
1907
- };
1908
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1909
- ExceptionDetails: JSON.stringify(exceptionDetails)
1910
- });
1911
- }
1912
- return [3 /*break*/, 5];
1913
- case 4:
1914
- _a = _b.sent();
1915
- exceptionDetails = {
1916
- response: "GetAuthTokenFailed"
1917
- };
1918
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1919
- ExceptionDetails: JSON.stringify(exceptionDetails)
1920
- });
1921
- return [3 /*break*/, 5];
1922
- case 5: return [3 /*break*/, 7];
1923
- case 6:
1924
- exceptionDetails = {
1925
- response: "GetAuthTokenNotFound"
1926
- };
1927
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1928
- ExceptionDetails: JSON.stringify(exceptionDetails)
1929
- });
1930
- _b.label = 7;
1931
- case 7:
1932
1928
  if (this.preChatSurvey) {
1933
1929
  /* istanbul ignore next */
1934
1930
  this.debug && console.log('Prechat Survey!');
@@ -1936,11 +1932,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1936
1932
  this.callingOption = msdyn_callingoptions;
1937
1933
  this.liveChatConfig = liveChatConfig;
1938
1934
  return [2 /*return*/, this.liveChatConfig];
1939
- case 8:
1940
- error_18 = _b.sent();
1935
+ case 4:
1936
+ error_18 = _a.sent();
1941
1937
  console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1942
1938
  return [2 /*return*/, error_18];
1943
- case 9: return [2 /*return*/];
1939
+ case 5: return [2 /*return*/];
1944
1940
  }
1945
1941
  });
1946
1942
  });
@@ -2022,6 +2018,57 @@ var OmnichannelChatSDK = /** @class */ (function () {
2022
2018
  });
2023
2019
  });
2024
2020
  };
2021
+ OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider) {
2022
+ return __awaiter(this, void 0, void 0, function () {
2023
+ var token, exceptionDetails, _a, exceptionDetails, exceptionDetails;
2024
+ return __generator(this, function (_b) {
2025
+ switch (_b.label) {
2026
+ case 0:
2027
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
2028
+ this.chatSDKConfig.getAuthToken = provider;
2029
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 5];
2030
+ _b.label = 1;
2031
+ case 1:
2032
+ _b.trys.push([1, 3, , 4]);
2033
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
2034
+ case 2:
2035
+ token = _b.sent();
2036
+ if (token) {
2037
+ this.authenticatedUserToken = token;
2038
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
2039
+ }
2040
+ else {
2041
+ exceptionDetails = {
2042
+ response: "UndefinedAuthToken"
2043
+ };
2044
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2045
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2046
+ });
2047
+ }
2048
+ return [3 /*break*/, 4];
2049
+ case 3:
2050
+ _a = _b.sent();
2051
+ exceptionDetails = {
2052
+ response: "GetAuthTokenFailed"
2053
+ };
2054
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2055
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2056
+ });
2057
+ return [3 /*break*/, 4];
2058
+ case 4: return [3 /*break*/, 6];
2059
+ case 5:
2060
+ exceptionDetails = {
2061
+ response: "GetAuthTokenNotFound"
2062
+ };
2063
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2064
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2065
+ });
2066
+ _b.label = 6;
2067
+ case 6: return [2 /*return*/];
2068
+ }
2069
+ });
2070
+ });
2071
+ };
2025
2072
  return OmnichannelChatSDK;
2026
2073
  }());
2027
2074
  exports.default = OmnichannelChatSDK;