@microsoft/omnichannel-chat-widget 0.1.0-main.4188c11 → 0.1.0-main.592da7b

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 (62) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +14 -2
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +15 -3
  4. package/lib/cjs/common/utils.js +16 -2
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  7. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -1
  8. package/lib/cjs/components/livechatwidget/common/endChat.js +24 -6
  9. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -3
  10. package/lib/cjs/components/livechatwidget/common/startChat.js +86 -31
  11. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +142 -45
  12. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -6
  13. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  14. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  15. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  16. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  17. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  18. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  19. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  20. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  21. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  22. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
  23. package/lib/cjs/contexts/createReducer.js +8 -0
  24. package/lib/cjs/controller/componentController.js +1 -1
  25. package/lib/esm/common/Constants.js +14 -2
  26. package/lib/esm/common/telemetry/TelemetryConstants.js +15 -3
  27. package/lib/esm/common/utils.js +7 -0
  28. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  29. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  30. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -1
  31. package/lib/esm/components/livechatwidget/common/endChat.js +21 -6
  32. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +7 -4
  33. package/lib/esm/components/livechatwidget/common/startChat.js +85 -34
  34. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +134 -46
  35. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -8
  36. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  37. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  38. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  39. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  40. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  41. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  42. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  43. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  44. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  45. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
  46. package/lib/esm/contexts/createReducer.js +8 -0
  47. package/lib/esm/controller/componentController.js +1 -1
  48. package/lib/types/common/Constants.d.ts +7 -1
  49. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  50. package/lib/types/common/telemetry/TelemetryConstants.d.ts +16 -4
  51. package/lib/types/common/utils.d.ts +2 -0
  52. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  53. package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
  54. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  55. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  56. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  57. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  58. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  59. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  60. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  61. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  62. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
- import { ChatSDKError, Constants } from "../../../common/Constants";
2
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
1
+ import { ChatSDKError } from "../../../common/Constants";
2
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
@@ -9,10 +9,13 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
9
9
  import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
10
10
  import { createAdapter } from "./createAdapter";
11
11
  import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
12
- import { createTimer } from "../../../common/utils";
12
+ import { createTimer, getWidgetCacheId } from "../../../common/utils";
13
13
  import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
14
14
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
15
- import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
16
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+
18
+ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
19
 
17
20
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
18
21
  var _props$reconnectChatP;
@@ -27,11 +30,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
27
30
 
28
31
  await handleRedirectUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
29
32
  } else {
30
- // Getting PreChat Survey Context
31
- const parseToJson = false;
32
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
33
- const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
34
-
33
+ // Getting reconnectId for authenticated chat
35
34
  const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
36
35
 
37
36
  if (reconnectId) {
@@ -43,23 +42,35 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
43
42
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
44
43
  payload: ConversationState.ReconnectChat
45
44
  });
46
- } else if (showPrechat) {
47
- dispatch({
48
- type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
49
- payload: preChatSurveyResponse
50
- });
51
- dispatch({
52
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
53
- payload: ConversationState.Prechat
54
- });
55
45
  } else {
56
- dispatch({
57
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
58
- payload: ConversationState.Loading
59
- });
60
- await initStartChat(chatSDK, dispatch, setAdapter);
46
+ setCustomContextParams(props, chatSDK);
47
+ setupChatState(chatSDK, dispatch, setAdapter, state.appStates.conversationState === ConversationState.ProactiveChat, state.appStates.proactiveChatStates.proactiveChatEnablePrechat);
61
48
  }
62
49
  }
50
+ };
51
+
52
+ const setupChatState = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
53
+ // Getting PreChat Survey Context
54
+ const parseToJson = false;
55
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
56
+ const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
57
+
58
+ if (showPrechat) {
59
+ dispatch({
60
+ type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
61
+ payload: preChatSurveyResponse
62
+ });
63
+ dispatch({
64
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
65
+ payload: ConversationState.Prechat
66
+ });
67
+ } else {
68
+ dispatch({
69
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
70
+ payload: ConversationState.Loading
71
+ });
72
+ await initStartChat(chatSDK, dispatch, setAdapter);
73
+ }
63
74
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
75
 
65
76
 
@@ -67,12 +78,29 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
67
78
  try {
68
79
  var _newAdapter$activity$, _TelemetryTimers$Widg;
69
80
 
81
+ let isStartChatSuccessful = false;
82
+
83
+ if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
84
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
85
+
86
+ // Broadcasting limited cached chat details
87
+ BroadcastService.postMessage({
88
+ eventName: BroadcastEvent.ChatRetrievedFromCache,
89
+ payload: {
90
+ chatId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.liveChatContext) === null || _persistedState$domai2 === void 0 ? void 0 : (_persistedState$domai3 = _persistedState$domai2.chatToken) === null || _persistedState$domai3 === void 0 ? void 0 : _persistedState$domai3.chatId,
91
+ requestId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai4 = persistedState.domainStates) === null || _persistedState$domai4 === void 0 ? void 0 : (_persistedState$domai5 = _persistedState$domai4.liveChatContext) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.requestId
92
+ }
93
+ });
94
+ }
95
+
70
96
  try {
71
97
  TelemetryTimers.WidgetLoadTimer = createTimer();
72
98
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
73
99
  Event: TelemetryEvent.StartChatSDKCall
74
100
  });
75
- await chatSDK.startChat(params);
101
+ optionalParams = Object.assign({}, params, optionalParams);
102
+ await chatSDK.startChat(optionalParams);
103
+ isStartChatSuccessful = true;
76
104
  } catch (error) {
77
105
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
78
106
  Event: TelemetryEvent.StartChatMethodException,
@@ -80,6 +108,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
80
108
  exception: `Failed to setup startChat: ${error}`
81
109
  }
82
110
  });
111
+ isStartChatSuccessful = false;
83
112
  }
84
113
 
85
114
  const newAdapter = await createAdapter(chatSDK);
@@ -107,10 +136,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
107
136
  await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
108
137
  await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
109
138
 
110
- dispatch({
111
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
112
- payload: ConversationState.Active
113
- });
139
+ if (isStartChatSuccessful) {
140
+ dispatch({
141
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
142
+ payload: ConversationState.Active
143
+ });
144
+ }
114
145
  } else {
115
146
  dispatch({
116
147
  type: LiveChatWidgetActionType.SET_WIDGET_STATE,
@@ -143,25 +174,28 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
143
174
  payload: ConversationState.OutOfOffice
144
175
  });
145
176
  }
177
+ } finally {
178
+ optionalParams = {};
146
179
  }
147
180
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
181
 
149
182
 
150
183
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
151
- var _DataStoreManager$cli, _persistedState$domai;
184
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
152
185
 
153
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
186
+ const widgetStateEventName = getWidgetCacheId((chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId) ?? "", (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId) ?? "");
187
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
154
188
  const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
155
189
 
156
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
157
- var _persistedState$domai2;
190
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
191
+ var _persistedState$domai7;
158
192
 
159
193
  dispatch({
160
194
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
161
195
  payload: ConversationState.Loading
162
196
  });
163
197
  const optionalParams = {
164
- liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
198
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
165
199
  };
166
200
  await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
167
201
  return true;
@@ -170,4 +204,21 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
170
204
  }
171
205
  };
172
206
 
173
- export { prepareStartChat, initStartChat };
207
+ const setCustomContextParams = (props, chatSDK) => {
208
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _DataStoreManager$cli2, _props$chatConfig, _persistedState$domai8;
209
+
210
+ // Add custom context if any only for unauthenticated chat
211
+ const widgetStateEventName = getWidgetCacheId((chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId) ?? "", (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId) ?? "");
212
+ const widgetStateFromCache = (_DataStoreManager$cli2 = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.getData(widgetStateEventName, "localStorage");
213
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
214
+
215
+ if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && persistedState !== null && persistedState !== void 0 && (_persistedState$domai8 = persistedState.domainStates) !== null && _persistedState$domai8 !== void 0 && _persistedState$domai8.customContext) {
216
+ var _persistedState$domai9;
217
+
218
+ optionalParams = Object.assign({}, optionalParams, {
219
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
220
+ });
221
+ }
222
+ };
223
+
224
+ export { prepareStartChat, initStartChat, setupChatState };
@@ -4,9 +4,9 @@ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/teleme
4
4
  import { BroadcastService, decodeComponentString } from "@microsoft/omnichannel-chat-components";
5
5
  import { Stack } from "@fluentui/react";
6
6
  import React, { useEffect, useRef, useState } from "react";
7
- import { createTimer, getLocaleDirection } from "../../../common/utils";
7
+ import { createTimer, getLocaleDirection, getWidgetCacheId, getWidgetEndChatEventName } from "../../../common/utils";
8
8
  import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
9
- import { initStartChat, prepareStartChat } from "../common/startChat";
9
+ import { initStartChat, prepareStartChat, setupChatState } from "../common/startChat";
10
10
  import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
11
11
  import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
12
12
  import ChatButtonStateful from "../../chatbuttonstateful/ChatButtonStateful";
@@ -44,7 +44,7 @@ import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
44
44
  import useChatContextStore from "../../../hooks/useChatContextStore";
45
45
  import useChatSDKStore from "../../../hooks/useChatSDKStore";
46
46
  export const LiveChatWidgetStateful = props => {
47
- var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$componentOverr, _props$controlProps6, _props$componentOverr2, _props$controlProps7, _props$componentOverr3, _props$controlProps8, _props$componentOverr4, _props$controlProps9, _props$componentOverr5, _props$controlProps10, _props$componentOverr6, _props$controlProps11, _props$componentOverr7, _props$controlProps12, _props$controlProps13, _props$componentOverr8, _props$controlProps14, _props$componentOverr9, _props$controlProps15, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
47
+ var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$controlProps6, _props$componentOverr, _props$controlProps7, _props$componentOverr2, _props$controlProps8, _props$componentOverr3, _props$controlProps9, _props$componentOverr4, _props$controlProps10, _props$componentOverr5, _props$controlProps11, _props$componentOverr6, _props$controlProps12, _props$componentOverr7, _props$controlProps13, _props$controlProps14, _props$componentOverr8, _props$controlProps15, _props$componentOverr9, _props$controlProps16, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
48
48
 
49
49
  const [state, dispatch] = useChatContextStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
50
 
@@ -68,6 +68,33 @@ export const LiveChatWidgetStateful = props => {
68
68
  TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
69
69
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
70
70
  const currentMessageCountRef = useRef(0);
71
+ let widgetStateEventName = "";
72
+
73
+ const initiateEndChatOnBrowserUnload = () => {
74
+ var _DataStoreManager$cli;
75
+
76
+ const persistedState = getStateFromCache(); // End chat if the chat is still active and browser closed
77
+
78
+ if (persistedState.appStates.conversationState === ConversationState.Active) {
79
+ //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
80
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
81
+ } // Clean local storage
82
+
83
+
84
+ (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage");
85
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+
87
+
88
+ const getStateFromCache = () => {
89
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli2;
90
+
91
+ // Getting updated state from cache
92
+ const widgetStateEventName = getWidgetCacheId((chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId) ?? "", (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId) ?? "");
93
+ const widgetStateFromCache = (_DataStoreManager$cli2 = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.getData(widgetStateEventName, "localStorage");
94
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
95
+ return persistedState;
96
+ };
97
+
71
98
  useEffect(() => {
72
99
  var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
73
100
 
@@ -114,11 +141,16 @@ export const LiveChatWidgetStateful = props => {
114
141
  };
115
142
  initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
116
143
  }
117
- }, []);
144
+ }, []); // useEffect for when skip chat button rendering
145
+
118
146
  useEffect(() => {
119
147
  if (state.appStates.skipChatButtonRendering) {
120
148
  var _props$reconnectChatP3;
121
149
 
150
+ BroadcastService.postMessage({
151
+ eventName: BroadcastEvent.ChatInitiated
152
+ });
153
+
122
154
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
123
155
  var _props$reconnectChatP4, _props$reconnectChatP5;
124
156
 
@@ -139,17 +171,16 @@ export const LiveChatWidgetStateful = props => {
139
171
  eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
140
172
  };
141
173
  BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
142
- dispatch({
143
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
144
- payload: ConversationState.Loading
145
- });
146
- initStartChat(chatSDK, dispatch, setAdapter);
174
+ setupChatState(chatSDK, dispatch, setAdapter);
147
175
  }
148
176
  });
149
177
  }
150
178
  }
151
- }, [state.appStates.skipChatButtonRendering]);
179
+ }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
180
+
152
181
  useEffect(() => {
182
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
183
+
153
184
  // Add the custom context on receiving the SetCustomContext event
154
185
  BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
155
186
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
@@ -161,7 +192,7 @@ export const LiveChatWidgetStateful = props => {
161
192
  payload: msg === null || msg === void 0 ? void 0 : msg.payload
162
193
  });
163
194
  });
164
- BroadcastService.getMessageByEventName("StartProactiveChat").subscribe(msg => {
195
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
165
196
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
166
197
  Event: TelemetryEvent.StartProactiveChatEventReceived,
167
198
  Description: "Start proactive chat event received."
@@ -177,30 +208,46 @@ export const LiveChatWidgetStateful = props => {
177
208
  Description: "Start proactive chat method called, when chat was already triggered."
178
209
  });
179
210
  }
180
- }); // start chat from SDK Event
211
+ }); // Start chat from SDK Event
181
212
 
182
- BroadcastService.getMessageByEventName("StartChat").subscribe(() => {
213
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
183
214
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
184
215
  Event: TelemetryEvent.StartChatEventRecevied,
185
216
  Description: "Start chat event received."
186
217
  });
218
+ const persistedState = getStateFromCache();
187
219
 
188
- if (state.appStates.isMinimized) {
220
+ if (persistedState && (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat)) {
221
+ // Embedded mode
222
+ BroadcastService.postMessage({
223
+ eventName: BroadcastEvent.ChatInitiated
224
+ });
225
+ prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
226
+ } else if (!persistedState) {
227
+ // Popout chat
228
+ BroadcastService.postMessage({
229
+ eventName: BroadcastEvent.ChatInitiated
230
+ });
231
+ prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
232
+ } else {
233
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
234
+
235
+ // Minimize to Maximize
189
236
  dispatch({
190
237
  type: LiveChatWidgetActionType.SET_MINIMIZED,
191
238
  payload: false
192
239
  });
193
- } else {
194
- prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
240
+ BroadcastService.postMessage({
241
+ eventName: BroadcastEvent.MaximizeChat,
242
+ payload: {
243
+ height: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.widgetSize) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.height,
244
+ width: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai3 = persistedState.domainStates) === null || _persistedState$domai3 === void 0 ? void 0 : (_persistedState$domai4 = _persistedState$domai3.widgetSize) === null || _persistedState$domai4 === void 0 ? void 0 : _persistedState$domai4.width
245
+ }
246
+ });
195
247
  }
196
- }); // end chat from SDK Event
197
-
198
- BroadcastService.getMessageByEventName("EndChat").subscribe(async () => {
199
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
200
- Event: TelemetryEvent.EndChatEventReceived,
201
- Description: "End chat event received."
202
- });
248
+ }); // End chat
203
249
 
250
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
204
251
  if (canEndChat.current) {
205
252
  prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
206
253
  } else {
@@ -208,17 +255,52 @@ export const LiveChatWidgetStateful = props => {
208
255
  const skipCloseChat = false;
209
256
  endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
210
257
  }
258
+
259
+ BroadcastService.postMessage({
260
+ eventName: BroadcastEvent.CloseChat
261
+ });
211
262
  });
263
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
264
+ initiateEndChatOnBrowserUnload();
265
+ }); // reset proactive chat params
266
+
267
+ BroadcastService.getMessageByEventName(BroadcastEvent.ResetProactiveChatParams).subscribe(async () => {
268
+ dispatch({
269
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
270
+ payload: {
271
+ proactiveChatBodyTitle: "",
272
+ proactiveChatEnablePrechat: false,
273
+ proactiveChatInNewWindow: false
274
+ }
275
+ });
276
+ }); // Listen to end chat event from other tabs
277
+
278
+ const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId);
279
+ BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
280
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
281
+ }); // Close popout window
282
+
212
283
  window.addEventListener("beforeunload", () => {
284
+ TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
285
+ Event: TelemetryEvent.WindowClosed,
286
+ Description: "Closed window."
287
+ });
213
288
  disposeTelemetryLoggers();
214
289
  });
215
290
 
216
291
  if (state.appStates.conversationEndedByAgent) {
217
292
  endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
218
- }
293
+ } //Listen to WidgetSize
294
+
295
+
296
+ BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
297
+ dispatch({
298
+ type: LiveChatWidgetActionType.SET_WIDGET_SIZE,
299
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
300
+ });
301
+ });
219
302
  }, []);
220
303
  useEffect(() => {
221
- canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
222
304
  canEndChat.current = state.appStates.conversationState === ConversationState.Active;
223
305
 
224
306
  if (state.appStates.conversationState === ConversationState.Active) {
@@ -239,7 +321,10 @@ export const LiveChatWidgetStateful = props => {
239
321
  });
240
322
  });
241
323
  }
242
- }, [state.appStates.conversationState]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
324
+ }, [state.appStates.conversationState]);
325
+ useEffect(() => {
326
+ canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
327
+ }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
243
328
 
244
329
  useEffect(() => {
245
330
  currentMessageCountRef.current = -1;
@@ -256,7 +341,7 @@ export const LiveChatWidgetStateful = props => {
256
341
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
257
342
 
258
343
  useEffect(() => {
259
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
344
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
260
345
  const customEvent = {
261
346
  elementType: ElementType.Custom,
262
347
  eventName: BroadcastEvent.UnreadMessageCount,
@@ -271,7 +356,19 @@ export const LiveChatWidgetStateful = props => {
271
356
  setWebChatStyles({ ...webChatStyles,
272
357
  ...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
273
358
  });
274
- }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
359
+ }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
360
+
361
+ useEffect(() => {
362
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
363
+
364
+ widgetStateEventName = getWidgetCacheId(props === null || props === void 0 ? void 0 : (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId);
365
+ const chatWidgetStateChangeEvent = {
366
+ eventName: widgetStateEventName,
367
+ payload: { ...state
368
+ }
369
+ };
370
+ BroadcastService.postMessage(chatWidgetStateChangeEvent);
371
+ }, [state]);
275
372
  const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
276
373
 
277
374
  const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -287,16 +384,7 @@ export const LiveChatWidgetStateful = props => {
287
384
 
288
385
  const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
289
386
 
290
- const confirmationPaneProps = initConfirmationPropsComposer(props); // publish chat widget state
291
-
292
- useEffect(() => {
293
- const chatWidgetStateChangeEvent = {
294
- eventName: BroadcastEvent.ChatWidgetStateChanged,
295
- payload: { ...state
296
- }
297
- };
298
- BroadcastService.postMessage(chatWidgetStateChangeEvent);
299
- }, [state]);
387
+ const confirmationPaneProps = initConfirmationPropsComposer(props);
300
388
  return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
301
389
  styleOptions: webChatStyles,
302
390
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
@@ -304,28 +392,28 @@ export const LiveChatWidgetStateful = props => {
304
392
  id: widgetElementId,
305
393
  styles: generalStyles,
306
394
  className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
307
- }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
395
+ }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.skipChatButtonRendering) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
308
396
  buttonProps: props.chatButtonProps,
309
397
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
310
398
  startChat: prepareStartChatRelay
311
- })), !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
399
+ })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
312
400
  proactiveChatProps: props.proactiveChatPaneProps,
313
401
  startChat: prepareStartChatRelay
314
- })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
402
+ })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
315
403
  headerProps: props.headerProps,
316
404
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
317
405
  endChat: endChatRelay
318
- })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideLoadingPane) && shouldShowLoadingPane(state) && (decodeComponentString((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/React.createElement(LoadingPaneStateful, props.loadingPaneProps)), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideOutOfOfficeHoursPane) && shouldShowOutOfOfficeHoursPane(state) && (decodeComponentString((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/React.createElement(OutOfOfficeHoursPaneStateful, props.outOfOfficeHoursPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
406
+ })), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideLoadingPane) && shouldShowLoadingPane(state) && (decodeComponentString((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/React.createElement(LoadingPaneStateful, props.loadingPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideOutOfOfficeHoursPane) && shouldShowOutOfOfficeHoursPane(state) && (decodeComponentString((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/React.createElement(OutOfOfficeHoursPaneStateful, props.outOfOfficeHoursPaneProps)), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
319
407
  reconnectChatProps: props.reconnectChatPaneProps,
320
408
  initStartChat: initStartChatRelay
321
- })), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
409
+ })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
322
410
  surveyProps: props.preChatSurveyPaneProps,
323
411
  initStartChat: initStartChatRelay
324
- })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
412
+ })), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
325
413
  voiceVideoCallingSdk: voiceVideoCallingSDK
326
- }, props.callingContainerProps)), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, props.webChatContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
414
+ }, props.callingContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, props.webChatContainerProps)), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
327
415
  setPostChatContext: setPostChatContextRelay,
328
416
  prepareEndChat: prepareEndChatRelay
329
- }))), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
417
+ }))), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
330
418
  };
331
419
  export default LiveChatWidgetStateful;
@@ -1,7 +1,7 @@
1
- import { Constants, HtmlAttributeNames, Regex } from "../../common/Constants";
1
+ import { HtmlAttributeNames, Regex } from "../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
3
3
  import React, { useEffect } from "react";
4
- import { extractPreChatSurveyResponseValues, findAllFocusableElement, parseAdaptiveCardPayload } from "../../common/utils";
4
+ import { extractPreChatSurveyResponseValues, findAllFocusableElement, getWidgetCacheId, parseAdaptiveCardPayload } from "../../common/utils";
5
5
  import { ConversationState } from "../../contexts/common/ConversationState";
6
6
  import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
7
7
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
@@ -67,13 +67,14 @@ export const PreChatSurveyPaneStateful = props => {
67
67
  });
68
68
 
69
69
  try {
70
- var _DataStoreManager$cli, _persistedState$domai;
70
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _DataStoreManager$cli, _persistedState$domai;
71
71
 
72
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
72
+ const widgetStateCacheId = getWidgetCacheId(((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$t = _state$domainStates.telemetryInternalData) === null || _state$domainStates$t === void 0 ? void 0 : _state$domainStates$t.orgId) ?? "", ((_state$domainStates$t2 = state.domainStates.telemetryInternalData) === null || _state$domainStates$t2 === void 0 ? void 0 : _state$domainStates$t2.widgetId) ?? "");
73
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateCacheId, "localStorage");
73
74
  const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
74
75
  let optionalParams = {};
75
76
 
76
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
77
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext && !state.appStates.skipChatButtonRendering) {
77
78
  var _persistedState$domai2;
78
79
 
79
80
  optionalParams = {
@@ -83,9 +84,7 @@ export const PreChatSurveyPaneStateful = props => {
83
84
  } else {
84
85
  const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
85
86
  optionalParams = {
86
- initContext: {
87
- preChatResponse: prechatResponseValues
88
- }
87
+ preChatResponse: prechatResponseValues
89
88
  };
90
89
  setPreChatResponseEmail(values);
91
90
  await initStartChat(optionalParams);
@@ -24,6 +24,14 @@ export const ProactiveChatPaneStateful = props => {
24
24
  const handleProactiveChatInviteTimeout = () => {
25
25
  if (!timeoutRemoved) {
26
26
  setTimeoutRemoved(true);
27
+ dispatch({
28
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
29
+ payload: {
30
+ proactiveChatBodyTitle: "",
31
+ proactiveChatEnablePrechat: false,
32
+ proactiveChatInNewWindow: false
33
+ }
34
+ });
27
35
  dispatch({
28
36
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
29
37
  payload: ConversationState.Closed
@@ -81,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
81
89
  Event: TelemetryEvent.ProactiveChatClosed,
82
90
  Description: "Proactive chat closed."
83
91
  });
92
+ dispatch({
93
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
94
+ payload: {
95
+ proactiveChatBodyTitle: "",
96
+ proactiveChatEnablePrechat: false,
97
+ proactiveChatInNewWindow: false
98
+ }
99
+ });
84
100
  dispatch({
85
101
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
86
102
  payload: ConversationState.Closed
87
103
  });
88
104
  },
89
105
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
90
- bodyTitleText: 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)
106
+ 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
91
107
  };
92
108
  useEffect(() => {
93
109
  setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));