@microsoft/omnichannel-chat-widget 1.8.4-main.cbab5fc → 1.8.4-main.cd79f08

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 (81) hide show
  1. package/README.md +12 -3
  2. package/lib/cjs/common/Constants.js +2 -0
  3. package/lib/cjs/common/facades/FacadeChatSDK.js +235 -9
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +13 -0
  5. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +7 -7
  6. package/lib/cjs/common/utils/xssUtils.js +23 -51
  7. package/lib/cjs/common/utils.js +15 -2
  8. package/lib/cjs/components/errorboundary/ErrorBoundary.js +2 -1
  9. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +9 -1
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +23 -6
  11. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +9 -0
  13. package/lib/cjs/components/livechatwidget/common/authHelper.js +44 -4
  14. package/lib/cjs/components/livechatwidget/common/createAdapter.js +3 -2
  15. package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +36 -4
  16. package/lib/cjs/components/livechatwidget/common/startChat.js +31 -14
  17. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +62 -2
  18. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +6 -4
  19. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +0 -1
  20. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +42 -27
  21. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +117 -16
  22. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +3 -1
  23. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +13 -2
  24. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +160 -167
  25. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +1 -1
  26. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -0
  27. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
  28. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +6 -1
  29. package/lib/cjs/contexts/createReducer.js +15 -0
  30. package/lib/cjs/controller/componentController.js +13 -1
  31. package/lib/cjs/plugins/newMessageEventHandler.js +20 -3
  32. package/lib/esm/common/Constants.js +2 -0
  33. package/lib/esm/common/facades/FacadeChatSDK.js +236 -10
  34. package/lib/esm/common/telemetry/TelemetryConstants.js +13 -0
  35. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +7 -7
  36. package/lib/esm/common/utils/xssUtils.js +23 -51
  37. package/lib/esm/common/utils.js +12 -1
  38. package/lib/esm/components/errorboundary/ErrorBoundary.js +4 -2
  39. package/lib/esm/components/livechatwidget/LiveChatWidget.js +9 -1
  40. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +23 -6
  41. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +1 -0
  42. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +9 -0
  43. package/lib/esm/components/livechatwidget/common/authHelper.js +44 -4
  44. package/lib/esm/components/livechatwidget/common/createAdapter.js +3 -2
  45. package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +33 -2
  46. package/lib/esm/components/livechatwidget/common/startChat.js +31 -14
  47. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +62 -2
  48. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +6 -4
  49. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -2
  50. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +43 -28
  51. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +117 -16
  52. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +3 -1
  53. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +13 -2
  54. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +160 -171
  55. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +1 -1
  56. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -0
  57. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware.js +1 -0
  58. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
  59. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +6 -1
  60. package/lib/esm/contexts/createReducer.js +15 -0
  61. package/lib/esm/controller/componentController.js +13 -1
  62. package/lib/esm/plugins/newMessageEventHandler.js +20 -3
  63. package/lib/types/common/Constants.d.ts +2 -0
  64. package/lib/types/common/facades/FacadeChatSDK.d.ts +29 -0
  65. package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +3 -1
  66. package/lib/types/common/telemetry/TelemetryConstants.d.ts +13 -2
  67. package/lib/types/common/utils/xssUtils.d.ts +5 -21
  68. package/lib/types/common/utils.d.ts +9 -1
  69. package/lib/types/components/errorboundary/ErrorBoundary.d.ts +1 -1
  70. package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +1 -0
  71. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +2 -1
  72. package/lib/types/components/livechatwidget/common/authHelper.d.ts +9 -2
  73. package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +11 -0
  74. package/lib/types/components/livechatwidget/interfaces/IBotAuthActivitySubscriberOptionalParams.d.ts +1 -0
  75. package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +2 -0
  76. package/lib/types/components/webchatcontainerstateful/interfaces/IBotAuthConfig.d.ts +7 -0
  77. package/lib/types/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.d.ts +1 -1
  78. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +14 -38
  79. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  80. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
  81. package/package.json +15 -6
@@ -44,7 +44,7 @@ const extractSasUrl = async attachment => {
44
44
  }
45
45
  return sasUrl;
46
46
  };
47
- const fetchBotAuthConfig = async (retries, interval) => {
47
+ const fetchBotAuthConfig = async (retries, interval, fallback) => {
48
48
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
49
49
  Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderFetchConfig
50
50
  });
@@ -60,13 +60,23 @@ const fetchBotAuthConfig = async (retries, interval) => {
60
60
  });
61
61
  if (retries === 1) {
62
62
  // Base Case
63
- throw new Error();
63
+ if (response !== undefined) {
64
+ return response;
65
+ }
66
+ if (fallback !== undefined) {
67
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.WARN, {
68
+ Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderNotFound,
69
+ Description: `Failed to fetch bot auth config after maximum retries. Using fallback value: ${fallback}`
70
+ });
71
+ return fallback;
72
+ }
73
+ throw new Error("Failed to fetch bot auth config after maximum retries");
64
74
  }
65
75
  await delay(interval);
66
76
  if (response !== undefined) {
67
77
  return response;
68
78
  }
69
- return await fetchBotAuthConfig(--retries, interval);
79
+ return await fetchBotAuthConfig(--retries, interval, fallback);
70
80
  };
71
81
  let BotAuthActivitySubscriber = /*#__PURE__*/function () {
72
82
  function BotAuthActivitySubscriber() {
@@ -76,6 +86,7 @@ let BotAuthActivitySubscriber = /*#__PURE__*/function () {
76
86
  _defineProperty(this, "signInCardSeen", void 0);
77
87
  _defineProperty(this, "fetchBotAuthConfigRetries", void 0);
78
88
  _defineProperty(this, "fetchBotAuthConfigRetryInterval", void 0);
89
+ _defineProperty(this, "fallbackShowSignInCard", void 0);
79
90
  this.signInCardSeen = new Set();
80
91
  this.fetchBotAuthConfigRetries = 3;
81
92
  this.fetchBotAuthConfigRetryInterval = 1000;
@@ -85,6 +96,11 @@ let BotAuthActivitySubscriber = /*#__PURE__*/function () {
85
96
  if (optionalParams.fetchBotAuthConfigRetryInterval) {
86
97
  this.fetchBotAuthConfigRetryInterval = optionalParams.fetchBotAuthConfigRetryInterval;
87
98
  }
99
+ this.fallbackShowSignInCard = optionalParams.fallbackShowSignInCard;
100
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
101
+ Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderFetchConfig,
102
+ Description: `BotAuthActivitySubscriber initialized with fallbackShowSignInCard: ${optionalParams.fallbackShowSignInCard}`
103
+ });
88
104
  }
89
105
  _createClass(BotAuthActivitySubscriber, [{
90
106
  key: "applicable",
@@ -129,7 +145,7 @@ let BotAuthActivitySubscriber = /*#__PURE__*/function () {
129
145
  _omnichannelChatComponents.BroadcastService.postMessage(event);
130
146
  }
131
147
  try {
132
- const response = await fetchBotAuthConfig(this.fetchBotAuthConfigRetries, this.fetchBotAuthConfigRetryInterval);
148
+ const response = await fetchBotAuthConfig(this.fetchBotAuthConfigRetries, this.fetchBotAuthConfigRetryInterval, this.fallbackShowSignInCard);
133
149
  if (response === false) {
134
150
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
135
151
  Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderHideCard
@@ -140,9 +156,10 @@ let BotAuthActivitySubscriber = /*#__PURE__*/function () {
140
156
  });
141
157
  return activity;
142
158
  }
143
- } catch {
159
+ } catch (e) {
144
160
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
145
- Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderNotFound
161
+ Event: _TelemetryConstants.TelemetryEvent.SetBotAuthProviderNotFound,
162
+ ExceptionDetails: e instanceof Error ? e.message : JSON.stringify(e)
146
163
  });
147
164
  //this is to ensure listener continues waiting for response
148
165
  if (this.signInCardSeen.has(signInId)) {
@@ -10,6 +10,7 @@ var ChatWidgetEvents;
10
10
  ChatWidgetEvents["FETCH_PERSISTENT_CHAT_HISTORY"] = "CHAT_WIDGET/FETCH_PERSISTENT_CHAT_HISTORY";
11
11
  ChatWidgetEvents["NO_MORE_HISTORY_AVAILABLE"] = "CHAT_WIDGET/NO_MORE_HISTORY_AVAILABLE";
12
12
  ChatWidgetEvents["HISTORY_LOAD_ERROR"] = "CHAT_WIDGET/HISTORY_LOAD_ERROR";
13
+ ChatWidgetEvents["HISTORY_BATCH_LOADED"] = "CHAT_WIDGET/HISTORY_BATCH_LOADED";
13
14
  })(ChatWidgetEvents || (ChatWidgetEvents = {}));
14
15
  var _default = ChatWidgetEvents;
15
16
  exports.default = _default;
@@ -133,6 +133,12 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
133
133
  }
134
134
  const messagesDescOrder = (_ref = [...messages]) === null || _ref === void 0 ? void 0 : _ref.reverse();
135
135
  this.processHistoryMessages(messagesDescOrder);
136
+
137
+ // Signal that a batch of history messages has been added to the store.
138
+ // LazyLoadActivity subscribes to this to apply scroll anchoring after render.
139
+ (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.HISTORY_BATCH_LOADED, {
140
+ messageCount: messages.length
141
+ });
136
142
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
137
143
  Event: _TelemetryConstants.TelemetryEvent.LCWPersistentHistoryPullCompleted,
138
144
  Description: "History pull completed successfully",
@@ -241,6 +247,9 @@ let PersistentConversationHandler = /*#__PURE__*/function () {
241
247
  value: function processMessageToActivity(message) {
242
248
  try {
243
249
  const activity = (0, _convertPersistentChatHistoryMessageToActivity.default)(message);
250
+ if (!activity) {
251
+ return null;
252
+ }
244
253
  activity.id = activity.id || `activity-${this.count}`;
245
254
  activity.channelData = {
246
255
  ...activity.channelData,
@@ -3,11 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.removeAuthTokenProvider = exports.handleAuthentication = exports.getAuthClientFunction = void 0;
6
+ exports.removeAuthTokenProvider = exports.isMidAuthEnabled = exports.handleAuthentication = exports.getAuthClientFunction = void 0;
7
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
8
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
9
9
  var _Constants = require("../../../common/Constants");
10
10
  var _utils = require("../../../common/utils");
11
+ /**
12
+ * Check if mid-auth is enabled based on chatConfig.
13
+ * Mid-auth flag lives under LiveWSAndLiveChatEngJoin.msdyn_authenticatedsigninoptional.
14
+ */
15
+ const isMidAuthEnabled = chatConfig => {
16
+ var _chatConfig$LiveWSAnd, _value$toString, _value$toString$call$, _value$toString$call;
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ const value = chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_authenticatedsigninoptional;
19
+ return (value === null || value === void 0 ? void 0 : (_value$toString = value.toString) === null || _value$toString === void 0 ? void 0 : (_value$toString$call$ = (_value$toString$call = _value$toString.call(value)).toLowerCase) === null || _value$toString$call$ === void 0 ? void 0 : _value$toString$call$.call(_value$toString$call)) === "true";
20
+ };
21
+ exports.isMidAuthEnabled = isMidAuthEnabled;
11
22
  const getAuthClientFunction = chatConfig => {
12
23
  let authClientFunction = undefined;
13
24
  if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
@@ -19,12 +30,17 @@ const getAuthClientFunction = chatConfig => {
19
30
  exports.getAuthClientFunction = getAuthClientFunction;
20
31
  const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
21
32
  var _chatSDK$chatSDKConfi;
33
+ const midAuthEnabled = isMidAuthEnabled(chatConfig);
22
34
  const authClientFunction = getAuthClientFunction(chatConfig);
23
35
  if (getAuthToken && authClientFunction) {
24
36
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
25
37
  Event: _TelemetryConstants.TelemetryEvent.GetAuthTokenCalled
26
38
  });
27
- const token = await getAuthToken(authClientFunction);
39
+
40
+ // Only pass isMidAuthEnabled option when mid-auth is enabled.
41
+ const token = midAuthEnabled ? await getAuthToken(authClientFunction, {
42
+ isMidAuthEnabled: midAuthEnabled
43
+ }) : await getAuthToken(authClientFunction);
28
44
  if (!(0, _utils.isNullOrEmptyString)(token)) {
29
45
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
46
  chatSDK.setAuthTokenProvider(async () => {
@@ -35,8 +51,21 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
35
51
  "token": token
36
52
  };
37
53
  } else {
38
- // instead of returning false, it's more appropiate to thrown an error to force error handling on the caller side
39
- // this will help to avoid the error to be ignored and the chat to be started
54
+ // For mid-auth scenarios, empty token means "user not signed in" - this is expected behavior.
55
+ // Return result: true with empty token so caller can decide to proceed unauthenticated.
56
+ if (midAuthEnabled) {
57
+ // Expected behavior for mid-auth: user not signed in
58
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
59
+ Event: _TelemetryConstants.TelemetryEvent.GetAuthTokenCalled,
60
+ Description: "Mid-auth: token provider returned empty; user not signed in"
61
+ });
62
+ return {
63
+ "result": true,
64
+ "token": null
65
+ };
66
+ }
67
+
68
+ // For non-mid-auth scenarios, empty token is an error
40
69
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
41
70
  Event: _TelemetryConstants.TelemetryEvent.ReceivedNullOrEmptyToken
42
71
  });
@@ -46,6 +75,17 @@ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
46
75
  var _chatSDK$chatSDKConfi2;
47
76
  const token = await ((_chatSDK$chatSDKConfi2 = chatSDK.chatSDKConfig) === null || _chatSDK$chatSDKConfi2 === void 0 ? void 0 : _chatSDK$chatSDKConfi2.getAuthToken());
48
77
  if ((0, _utils.isNullOrEmptyString)(token)) {
78
+ // For mid-auth scenarios, empty token from SDK's getAuthToken is also expected
79
+ if (midAuthEnabled) {
80
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
81
+ Event: _TelemetryConstants.TelemetryEvent.GetAuthTokenCalled,
82
+ Description: "Mid-auth: SDK getAuthToken returned empty; user not signed in"
83
+ });
84
+ return {
85
+ "result": true,
86
+ "token": null
87
+ };
88
+ }
49
89
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
50
90
  Event: _TelemetryConstants.TelemetryEvent.ReceivedNullOrEmptyToken,
51
91
  Description: "getAuthToken in chat SDK returns empty string"
@@ -45,10 +45,11 @@ const createAdapter = async (facadeChatSDK, props) => {
45
45
  //so far, there is no need to convert to the shim adapter when using visual tests
46
46
  const isMocked = facadeChatSDK.getChatSDK() instanceof _mockchatsdk.MockChatSDK;
47
47
  if (isMocked !== true) {
48
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4;
48
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6;
49
49
  const botAuthActivitySubscriberOptionalParams = {
50
50
  fetchBotAuthConfigRetries: (props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.botAuthConfig) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.fetchBotAuthConfigRetries) || defaultBotAuthConfig.fetchBotAuthConfigRetries,
51
- fetchBotAuthConfigRetryInterval: (props === null || props === void 0 ? void 0 : (_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : (_props$webChatContain4 = _props$webChatContain3.botAuthConfig) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.fetchBotAuthConfigRetryInterval) || defaultBotAuthConfig.fetchBotAuthConfigRetryInterval
51
+ fetchBotAuthConfigRetryInterval: (props === null || props === void 0 ? void 0 : (_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : (_props$webChatContain4 = _props$webChatContain3.botAuthConfig) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.fetchBotAuthConfigRetryInterval) || defaultBotAuthConfig.fetchBotAuthConfigRetryInterval,
52
+ fallbackShowSignInCard: props === null || props === void 0 ? void 0 : (_props$webChatContain5 = props.webChatContainerProps) === null || _props$webChatContain5 === void 0 ? void 0 : (_props$webChatContain6 = _props$webChatContain5.botAuthConfig) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.fallbackShowSignInCard
52
53
  };
53
54
  adapter = new _ChatAdapterShim.ChatAdapterShim(adapter);
54
55
  adapter.addSubscriber(new _AddActivitySubscriber.AddActivitySubscriber());
@@ -3,15 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isPostChatSurveyEnabled = exports.isPersistentChatEnabled = exports.getPostChatSurveyConfig = void 0;
7
- var _Constants = require("../../../common/Constants");
6
+ exports.shouldLoadPersistentChatHistory = exports.isPostChatSurveyEnabled = exports.isPersistentChatEnabled = exports.getPostChatSurveyConfig = void 0;
8
7
  var _utils = require("../../../common/utils");
8
+ var _Constants = require("../../../common/Constants");
9
9
  const isPostChatSurveyEnabled = async facadeChatSDK => {
10
10
  var _chatConfig$LiveWSAnd;
11
11
  const chatConfig = await facadeChatSDK.getLiveChatConfig();
12
12
  const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
13
13
  return postChatEnabled === "true";
14
14
  };
15
+
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
17
  exports.isPostChatSurveyEnabled = isPostChatSurveyEnabled;
16
18
  const getPostChatSurveyConfig = async facadeChatSDK => {
17
19
  var _chatConfig$LiveWSAnd2, _chatConfig$LiveWSAnd3, _chatConfig$LiveWSAnd4, _chatConfig$LiveWSAnd5, _chatConfig$LiveWSAnd6, _chatConfig$LiveWSAnd7, _chatConfig$LiveWSAnd8, _chatConfig$LiveWSAnd9, _chatConfig$LiveWSAnd10;
@@ -34,6 +36,36 @@ const isPersistentChatEnabled = conversationMode => {
34
36
  if ((0, _utils.isNullOrUndefined)(conversationMode)) {
35
37
  return false;
36
38
  }
37
- return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString().toLowerCase()) === _Constants.ConversationMode.Persistent;
39
+ return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString()) === _Constants.ConversationMode.Persistent;
40
+ };
41
+
42
+ /**
43
+ * Determines if persistent chat history should be loaded based on all required conditions.
44
+ *
45
+ * @param extendedChatConfig - The extended chat configuration object
46
+ * @returns true if ALL conditions are met:
47
+ * 1. Conversation mode must be Persistent ("192350001")
48
+ * 2. History is enabled in admin config (msdyn_enablepersistentchatpreviousconversations)
49
+ * 3. History is enabled via feature flag (lcwPersistentChatHistoryEnabled)
50
+ */
51
+ exports.isPersistentChatEnabled = isPersistentChatEnabled;
52
+ const shouldLoadPersistentChatHistory = extendedChatConfig => {
53
+ var _extendedChatConfig$L, _extendedChatConfig$L2, _extendedChatConfig$L3;
54
+ // CRITICAL: First check if conversation mode is persistent
55
+ // Only persistent mode ("192350001") should allow history loading
56
+ const isPersistentChatEnabledForWidget = isPersistentChatEnabled(extendedChatConfig === null || extendedChatConfig === void 0 ? void 0 : (_extendedChatConfig$L = extendedChatConfig.LiveWSAndLiveChatEngJoin) === null || _extendedChatConfig$L === void 0 ? void 0 : _extendedChatConfig$L.msdyn_conversationmode);
57
+ if (!isPersistentChatEnabledForWidget) {
58
+ return false;
59
+ }
60
+
61
+ // Check if history is enabled in admin config (handles both boolean and string "true"/"false")
62
+ const isHistoryEnabledInConfig = (0, _utils.parseBooleanFromConfig)(extendedChatConfig === null || extendedChatConfig === void 0 ? void 0 : (_extendedChatConfig$L2 = extendedChatConfig.LiveWSAndLiveChatEngJoin) === null || _extendedChatConfig$L2 === void 0 ? void 0 : _extendedChatConfig$L2.msdyn_enablepersistentchatpreviousconversations);
63
+ if (!isHistoryEnabledInConfig) {
64
+ return false;
65
+ }
66
+
67
+ // Check if history is enabled via feature flag (handles both boolean and string "true"/"false")
68
+ const isHistoryEnabledViaFCB = (0, _utils.parseBooleanFromConfig)(extendedChatConfig === null || extendedChatConfig === void 0 ? void 0 : (_extendedChatConfig$L3 = extendedChatConfig.LcwFcbConfiguration) === null || _extendedChatConfig$L3 === void 0 ? void 0 : _extendedChatConfig$L3.lcwPersistentChatHistoryEnabled);
69
+ return isHistoryEnabledViaFCB;
38
70
  };
39
- exports.isPersistentChatEnabled = isPersistentChatEnabled;
71
+ exports.shouldLoadPersistentChatHistory = shouldLoadPersistentChatHistory;
@@ -20,6 +20,7 @@ var _createAdapter = require("./createAdapter");
20
20
  var _newMessageEventHandler = require("../../../plugins/newMessageEventHandler");
21
21
  var _FirstMessageTrackerFromBot = require("../../../firstresponselatency/FirstMessageTrackerFromBot");
22
22
  var _liveChatConfigUtils = require("./liveChatConfigUtils");
23
+ var _authHelper = require("./authHelper");
23
24
  var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
24
25
  var _persistentChatHelper = require("./persistentChatHelper");
25
26
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
@@ -65,7 +66,7 @@ const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapte
65
66
  exports.prepareStartChat = prepareStartChat;
66
67
  const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
67
68
  var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2, _state$appStates2;
68
- // This reset needs to be done before to load prechat, because the conversation state changes from close to prechat
69
+ // Reset before loading prechat to avoid starting chat with previous requestId
69
70
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
70
71
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
71
72
  (0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
@@ -199,7 +200,7 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
199
200
  });
200
201
  }
201
202
  try {
202
- var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
203
+ var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3, _state$domainStates8;
203
204
  // Set custom context params
204
205
  await setCustomContextParams(state, props);
205
206
  const defaultOptionalParams = {
@@ -208,9 +209,25 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
208
209
  portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
209
210
  };
210
211
  const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
212
+
213
+ // MID-AUTH: Add wasAuthenticated flag for reconnect scenarios
214
+ // Tells FacadeChatSDK whether the previous session was authenticated
215
+ // Used to detect auth transitions (Auth->Unauth) and decide whether to call authenticateChat
216
+ const midAuthEnabled = (0, _authHelper.isMidAuthEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : _state$domainStates8.liveChatConfig);
217
+ if (midAuthEnabled) {
218
+ var _state$appStates4, _persistedState$appSt;
219
+ const isUserAuthenticated = (state === null || state === void 0 ? void 0 : (_state$appStates4 = state.appStates) === null || _state$appStates4 === void 0 ? void 0 : _state$appStates4.isUserAuthenticated) === true || (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.isUserAuthenticated) === true;
220
+ startChatOptionalParams.wasAuthenticated = isUserAuthenticated;
221
+ }
222
+
211
223
  // startTime is used to determine if a message is history or new, better to be set before creating the adapter to get bandwidth
212
224
  const startTime = new Date().getTime();
213
225
  (0, _FirstMessageTrackerFromBot.createTrackingForFirstMessage)();
226
+
227
+ // FacadeChatSDK.startChat() handles:
228
+ // 1. tokenRing() - checks authentication, calls handleAuthentication() if needed
229
+ // 2. Mid-auth: If no token, sets deferInitialAuth=true for unauthenticated flow
230
+ // 3. Mid-auth: On reconnect with valid token, calls authenticateChat to upgrade conversation
214
231
  await facadeChatSDK.startChat(startChatOptionalParams);
215
232
  (0, _startChatErrorHandler.logStartChatComplete)();
216
233
  isStartChatSuccessful = true;
@@ -298,15 +315,15 @@ const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, st
298
315
  };
299
316
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
317
  const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
301
- var _state$appStates4, _persistedState$domai6, _persistedState$appSt;
318
+ var _state$appStates5, _persistedState$domai6, _persistedState$appSt2;
302
319
  // By pass this function in case of popout chat
303
- if ((state === null || state === void 0 ? void 0 : (_state$appStates4 = state.appStates) === null || _state$appStates4 === void 0 ? void 0 : _state$appStates4.hideStartChatButton) === true) {
320
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates5 = state.appStates) === null || _state$appStates5 === void 0 ? void 0 : _state$appStates5.hideStartChatButton) === true) {
304
321
  return false;
305
322
  }
306
323
  const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
307
324
 
308
325
  //Connect to only active chat session
309
- if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === _ConversationState.ConversationState.Active) {
326
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt2 = persistedState.appStates) === null || _persistedState$appSt2 === void 0 ? void 0 : _persistedState$appSt2.conversationState) === _ConversationState.ConversationState.Active) {
310
327
  var _persistedState$domai7;
311
328
  dispatch({
312
329
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -323,11 +340,11 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
323
340
 
324
341
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
325
342
  const setCustomContextParams = async (state, props) => {
326
- var _state$domainStates8, _persistedState$domai8;
327
- if (state !== null && state !== void 0 && (_state$domainStates8 = state.domainStates) !== null && _state$domainStates8 !== void 0 && _state$domainStates8.customContext) {
328
- var _state$domainStates9;
343
+ var _state$domainStates9, _persistedState$domai8;
344
+ if (state !== null && state !== void 0 && (_state$domainStates9 = state.domainStates) !== null && _state$domainStates9 !== void 0 && _state$domainStates9.customContext) {
345
+ var _state$domainStates10;
329
346
  optionalParams = Object.assign({}, optionalParams, {
330
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.customContext))
347
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates10 = state.domainStates) === null || _state$domainStates10 === void 0 ? void 0 : _state$domainStates10.customContext))
331
348
  });
332
349
  return;
333
350
  }
@@ -360,9 +377,9 @@ const canStartPopoutChat = async props => {
360
377
  }
361
378
  popoutWidgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props, true);
362
379
  if (!(0, _utils.isNullOrEmptyString)(popoutWidgetInstanceId)) {
363
- var _persistedState$domai9, _persistedState$appSt2;
380
+ var _persistedState$domai9, _persistedState$appSt3;
364
381
  const persistedState = (0, _utils.getStateFromCache)(popoutWidgetInstanceId);
365
- if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt2 = persistedState.appStates) === null || _persistedState$appSt2 === void 0 ? void 0 : _persistedState$appSt2.conversationState) === _ConversationState.ConversationState.Active) {
382
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt3 = persistedState.appStates) === null || _persistedState$appSt3 === void 0 ? void 0 : _persistedState$appSt3.conversationState) === _ConversationState.ConversationState.Active) {
366
383
  // Initiate popout chat
367
384
  _omnichannelChatComponents.BroadcastService.postMessage({
368
385
  eventName: _TelemetryConstants.BroadcastEvent.InitiateStartChatInPopoutMode
@@ -375,9 +392,9 @@ const canStartPopoutChat = async props => {
375
392
 
376
393
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
377
394
  const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
378
- var _state$domainStates10, _state$domainStates11, _state$domainStates12;
379
- const requestIdFromCache = (_state$domainStates10 = state.domainStates) === null || _state$domainStates10 === void 0 ? void 0 : (_state$domainStates11 = _state$domainStates10.liveChatContext) === null || _state$domainStates11 === void 0 ? void 0 : _state$domainStates11.requestId;
380
- const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates12 = state.domainStates) === null || _state$domainStates12 === void 0 ? void 0 : _state$domainStates12.liveChatContext;
395
+ var _state$domainStates11, _state$domainStates12, _state$domainStates13;
396
+ const requestIdFromCache = (_state$domainStates11 = state.domainStates) === null || _state$domainStates11 === void 0 ? void 0 : (_state$domainStates12 = _state$domainStates11.liveChatContext) === null || _state$domainStates12 === void 0 ? void 0 : _state$domainStates12.requestId;
397
+ const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates13 = state.domainStates) === null || _state$domainStates13 === void 0 ? void 0 : _state$domainStates13.liveChatContext;
381
398
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
399
  let conversationDetails = undefined;
383
400
  // Preserve current requestId
@@ -54,6 +54,7 @@ var _initConfirmationPropsComposer = require("../common/initConfirmationPropsCom
54
54
  var _initWebChatComposer = require("../common/initWebChatComposer");
55
55
  var _defaultCacheManager = require("../../../common/storage/default/defaultCacheManager");
56
56
  var _setPostChatContextAndLoadSurvey = require("../common/setPostChatContextAndLoadSurvey");
57
+ var _liveChatConfigUtils = require("../common/liveChatConfigUtils");
57
58
  var _startProactiveChat = require("../common/startProactiveChat");
58
59
  var _useChatAdapterStore = _interopRequireDefault(require("../../../hooks/useChatAdapterStore"));
59
60
  var _useChatContextStore = _interopRequireDefault(require("../../../hooks/useChatContextStore"));
@@ -736,7 +737,15 @@ const LiveChatWidgetStateful = props => {
736
737
  if (state.appStates.isMinimized) {
737
738
  _ActivityStreamHandler.ActivityStreamHandler.cork();
738
739
  } else {
739
- setTimeout(() => _ActivityStreamHandler.ActivityStreamHandler.uncork(), 500);
740
+ var _state$domainStates4;
741
+ const extendedChatConfig = state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : _state$domainStates4.liveChatConfig;
742
+ if ((0, _liveChatConfigUtils.shouldLoadPersistentChatHistory)(extendedChatConfig)) {
743
+ requestAnimationFrame(() => {
744
+ setTimeout(() => _ActivityStreamHandler.ActivityStreamHandler.uncork(), 500);
745
+ });
746
+ } else {
747
+ setTimeout(() => _ActivityStreamHandler.ActivityStreamHandler.uncork(), 500);
748
+ }
740
749
  }
741
750
  }, [state.appStates.isMinimized]);
742
751
 
@@ -814,7 +823,7 @@ const LiveChatWidgetStateful = props => {
814
823
 
815
824
  // In conversational survey, we need to check post chat survey logics before we set ConversationState to InActive
816
825
  // Hence setting ConversationState to InActive will be done later in the post chat flows
817
- if (!isConversationalSurveyEnabled && (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta12 = inMemoryState.appStates) === null || _inMemoryState$appSta12 === void 0 ? void 0 : _inMemoryState$appSta12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta13 = inMemoryState.appStates) === null || _inMemoryState$appSta13 === void 0 ? void 0 : _inMemoryState$appSta13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot) {
826
+ if (!isConversationalSurveyEnabled && ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta12 = inMemoryState.appStates) === null || _inMemoryState$appSta12 === void 0 ? void 0 : _inMemoryState$appSta12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta13 = inMemoryState.appStates) === null || _inMemoryState$appSta13 === void 0 ? void 0 : _inMemoryState$appSta13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot)) {
818
827
  dispatch({
819
828
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
820
829
  payload: _ConversationState.ConversationState.InActive
@@ -875,6 +884,37 @@ const LiveChatWidgetStateful = props => {
875
884
  }
876
885
  }, [state.appStates.chatDisconnectEventReceived]);
877
886
 
887
+ // Auth state change listeners (broadcast by FacadeChatSDK.startChat())
888
+ (0, _react2.useEffect)(() => {
889
+ const authSucceededSub = _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.MidConversationAuthSucceeded).subscribe(msg => {
890
+ var _msg$payload15;
891
+ if (msg !== null && msg !== void 0 && (_msg$payload15 = msg.payload) !== null && _msg$payload15 !== void 0 && _msg$payload15.isAuthenticated) {
892
+ // Only store boolean flag, NOT the token - token is managed by FacadeChatSDK
893
+ dispatch({
894
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_USER_AUTHENTICATED,
895
+ payload: true
896
+ });
897
+ }
898
+ });
899
+
900
+ // Auth reset: only update the boolean flag here.
901
+ // We do NOT clear widget state/cache/adapter because this fires DURING startChat(),
902
+ // which will handle state transitions. FacadeChatSDK has already cleared SDK internals.
903
+ const authResetSub = _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.MidConversationAuthReset).subscribe(msg => {
904
+ var _msg$payload16;
905
+ if ((msg === null || msg === void 0 ? void 0 : (_msg$payload16 = msg.payload) === null || _msg$payload16 === void 0 ? void 0 : _msg$payload16.isAuthenticated) === false) {
906
+ dispatch({
907
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_USER_AUTHENTICATED,
908
+ payload: false
909
+ });
910
+ }
911
+ });
912
+ return () => {
913
+ authSucceededSub.unsubscribe();
914
+ authResetSub.unsubscribe();
915
+ };
916
+ }, [dispatch]);
917
+
878
918
  // if props state gets updates we need to update the renderingMiddlewareProps in the state
879
919
  (0, _react2.useEffect)(() => {
880
920
  var _props$webChatContain16;
@@ -893,6 +933,25 @@ const LiveChatWidgetStateful = props => {
893
933
  }
894
934
  });
895
935
  }, []);
936
+
937
+ // Reliable browser close detection via visibilitychange + sendBeacon
938
+ // visibilitychange fires while the page is still alive (unlike beforeunload),
939
+ // so telemetry calls complete reliably. False positives (tab switch, minimize)
940
+ // are filtered in Kusto by checking if this is the last event in the session.
941
+ (0, _react2.useEffect)(() => {
942
+ const handleVisibilityChange = () => {
943
+ if (document.visibilityState === "hidden" && state.appStates.conversationState === _ConversationState.ConversationState.Active) {
944
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
945
+ Event: _TelemetryConstants.TelemetryEvent.BrowserTabHidden,
946
+ Description: "Browser tab hidden during active conversation"
947
+ });
948
+ }
949
+ };
950
+ document.addEventListener("visibilitychange", handleVisibilityChange);
951
+ return () => {
952
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
953
+ };
954
+ }, [state.appStates.conversationState]);
896
955
  const initiateEndChatOnBrowserUnload = () => {
897
956
  var _DataStoreManager$cli;
898
957
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -963,6 +1022,7 @@ const LiveChatWidgetStateful = props => {
963
1022
  // React to dynamic bot avatar initials updates from context
964
1023
  (0, _react2.useEffect)(() => {
965
1024
  if (state.domainStates.botAvatarInitials && state.domainStates.botAvatarInitials !== webChatStyles.botAvatarInitials) {
1025
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
966
1026
  setWebChatStyles(styles => ({
967
1027
  ...styles,
968
1028
  botAvatarInitials: state.domainStates.botAvatarInitials
@@ -31,7 +31,7 @@ const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, co
31
31
  return `${surveyInviteLink}&${surveyLinkParams.toString()}`;
32
32
  };
33
33
  const PostChatSurveyPaneStateful = props => {
34
- var _props$styleProps, _state$appStates, _props$controlProps;
34
+ var _props$styleProps, _state$appStates, _state$domainStates$p, _props$controlProps;
35
35
  (0, _react.useEffect)(() => {
36
36
  uiTimer = (0, _utils.createTimer)();
37
37
  _TelemetryHelper.TelemetryHelper.logLoadingEventToAllTelemetry(_TelemetryConstants.LogLevel.INFO, {
@@ -48,13 +48,15 @@ const PostChatSurveyPaneStateful = props => {
48
48
  });
49
49
  let surveyInviteLink = "";
50
50
  const surveyMode = (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.selectedSurveyMode) === _PostChatSurveyMode.PostChatSurveyMode.Embed;
51
- if (state.domainStates.postChatContext.botSurveyInviteLink &&
51
+ if ((_state$domainStates$p = state.domainStates.postChatContext) !== null && _state$domainStates$p !== void 0 && _state$domainStates$p.botSurveyInviteLink &&
52
52
  // Bot survey enabled
53
53
  state.appStates.postChatParticipantType === _Constants.ParticipantType.Bot) {
54
+ var _state$domainStates$p2, _state$domainStates$p3;
54
55
  // Only Bot has engaged
55
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
56
+ surveyInviteLink = generateSurveyInviteLink((_state$domainStates$p2 = state.domainStates.postChatContext) === null || _state$domainStates$p2 === void 0 ? void 0 : _state$domainStates$p2.botSurveyInviteLink, surveyMode, (_state$domainStates$p3 = state.domainStates.postChatContext) === null || _state$domainStates$p3 === void 0 ? void 0 : _state$domainStates$p3.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
56
57
  } else {
57
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
58
+ var _state$domainStates$p4, _state$domainStates$p5;
59
+ surveyInviteLink = generateSurveyInviteLink((_state$domainStates$p4 = state.domainStates.postChatContext) === null || _state$domainStates$p4 === void 0 ? void 0 : _state$domainStates$p4.surveyInviteLink, surveyMode, (_state$domainStates$p5 = state.domainStates.postChatContext) === null || _state$domainStates$p5 === void 0 ? void 0 : _state$domainStates$p5.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
58
60
  }
59
61
  if (props.copilotSurveyContext) {
60
62
  surveyInviteLink = `${surveyInviteLink}&mcs_additionalcontext=${JSON.stringify(props.copilotSurveyContext)}`;
@@ -122,7 +122,6 @@ const ProactiveChatPaneStateful = props => {
122
122
  bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ? state.appStates.proactiveChatStates.proactiveChatBodyTitle : proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText
123
123
  };
124
124
  (0, _react.useEffect)(() => {
125
- (0, _utils.setFocusOnElement)(document.getElementById(controlProps.id + "-startbutton"));
126
125
  _TelemetryManager.TelemetryTimers.ProactiveChatScreenTimer = (0, _utils.createTimer)();
127
126
  const timeoutEvent = setTimeout(() => {
128
127
  handleProactiveChatInviteTimeout();