@microsoft/omnichannel-chat-widget 0.1.0-main.e170704 → 0.1.0-main.f5f497a
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.
- package/README.md +32 -0
- package/lib/cjs/common/Constants.js +14 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +15 -3
- package/lib/cjs/common/telemetry/TelemetryManager.js +7 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +8 -9
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +17 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +15 -3
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -13
- package/lib/cjs/components/livechatwidget/common/endChat.js +28 -13
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +12 -3
- package/lib/cjs/components/livechatwidget/common/startChat.js +78 -31
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +147 -45
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -6
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
- package/lib/cjs/contexts/createReducer.js +9 -0
- package/lib/cjs/controller/componentController.js +1 -1
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +14 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +15 -3
- package/lib/esm/common/telemetry/TelemetryManager.js +6 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +8 -6
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +8 -0
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +17 -6
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -13
- package/lib/esm/components/livechatwidget/common/endChat.js +26 -14
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +11 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +77 -34
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +139 -46
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -1
- package/lib/esm/contexts/createReducer.js +9 -0
- package/lib/esm/controller/componentController.js +1 -1
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +7 -1
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +17 -4
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/utils.d.ts +2 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChatSDKError
|
|
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";
|
|
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
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
payload: ConversationState.Loading
|
|
59
|
-
});
|
|
60
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
46
|
+
setCustomContextParams(props, state);
|
|
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
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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,
|
|
@@ -148,20 +179,21 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
148
179
|
|
|
149
180
|
|
|
150
181
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
151
|
-
var _DataStoreManager$cli, _persistedState$
|
|
182
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
|
|
152
183
|
|
|
153
|
-
const
|
|
184
|
+
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) ?? "");
|
|
185
|
+
const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
154
186
|
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
155
187
|
|
|
156
|
-
if (persistedState !== null && persistedState !== void 0 && (_persistedState$
|
|
157
|
-
var _persistedState$
|
|
188
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
|
|
189
|
+
var _persistedState$domai7;
|
|
158
190
|
|
|
159
191
|
dispatch({
|
|
160
192
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
161
193
|
payload: ConversationState.Loading
|
|
162
194
|
});
|
|
163
195
|
const optionalParams = {
|
|
164
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
196
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
165
197
|
};
|
|
166
198
|
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
167
199
|
return true;
|
|
@@ -170,4 +202,15 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
170
202
|
}
|
|
171
203
|
};
|
|
172
204
|
|
|
173
|
-
|
|
205
|
+
const setCustomContextParams = (props, state) => {
|
|
206
|
+
var _props$chatConfig, _state$domainStates;
|
|
207
|
+
|
|
208
|
+
// Add custom context if any only for unauthenticated chat
|
|
209
|
+
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
|
|
210
|
+
optionalParams = Object.assign({}, optionalParams, {
|
|
211
|
+
customContext: state.domainStates.customContext
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
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$
|
|
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
|
|
|
@@ -53,7 +53,8 @@ export const LiveChatWidgetStateful = props => {
|
|
|
53
53
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
54
54
|
}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
55
|
|
|
56
|
-
const chatSDK = useChatSDKStore();
|
|
56
|
+
const chatSDK = useChatSDKStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
|
|
57
58
|
const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
|
|
58
59
|
const {
|
|
59
60
|
Composer
|
|
@@ -67,6 +68,33 @@ export const LiveChatWidgetStateful = props => {
|
|
|
67
68
|
TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
|
|
68
69
|
const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
|
|
69
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
|
+
|
|
70
98
|
useEffect(() => {
|
|
71
99
|
var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
|
|
72
100
|
|
|
@@ -81,6 +109,10 @@ export const LiveChatWidgetStateful = props => {
|
|
|
81
109
|
type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
|
|
82
110
|
payload: ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.skipChatButtonRendering) || false
|
|
83
111
|
});
|
|
112
|
+
dispatch({
|
|
113
|
+
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
114
|
+
payload: false
|
|
115
|
+
});
|
|
84
116
|
initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
85
117
|
sdkCreated && dispatch({
|
|
86
118
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
@@ -109,11 +141,16 @@ export const LiveChatWidgetStateful = props => {
|
|
|
109
141
|
};
|
|
110
142
|
initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
111
143
|
}
|
|
112
|
-
}, []);
|
|
144
|
+
}, []); // useEffect for when skip chat button rendering
|
|
145
|
+
|
|
113
146
|
useEffect(() => {
|
|
114
147
|
if (state.appStates.skipChatButtonRendering) {
|
|
115
148
|
var _props$reconnectChatP3;
|
|
116
149
|
|
|
150
|
+
BroadcastService.postMessage({
|
|
151
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
152
|
+
});
|
|
153
|
+
|
|
117
154
|
if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
|
|
118
155
|
var _props$reconnectChatP4, _props$reconnectChatP5;
|
|
119
156
|
|
|
@@ -134,17 +171,16 @@ export const LiveChatWidgetStateful = props => {
|
|
|
134
171
|
eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
|
|
135
172
|
};
|
|
136
173
|
BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
|
|
137
|
-
dispatch
|
|
138
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
139
|
-
payload: ConversationState.Loading
|
|
140
|
-
});
|
|
141
|
-
initStartChat(chatSDK, dispatch, setAdapter);
|
|
174
|
+
setupChatState(chatSDK, dispatch, setAdapter);
|
|
142
175
|
}
|
|
143
176
|
});
|
|
144
177
|
}
|
|
145
178
|
}
|
|
146
|
-
}, [state.appStates.skipChatButtonRendering]);
|
|
179
|
+
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
180
|
+
|
|
147
181
|
useEffect(() => {
|
|
182
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
|
|
183
|
+
|
|
148
184
|
// Add the custom context on receiving the SetCustomContext event
|
|
149
185
|
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
150
186
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -156,7 +192,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
156
192
|
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
157
193
|
});
|
|
158
194
|
});
|
|
159
|
-
BroadcastService.getMessageByEventName(
|
|
195
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
|
|
160
196
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
161
197
|
Event: TelemetryEvent.StartProactiveChatEventReceived,
|
|
162
198
|
Description: "Start proactive chat event received."
|
|
@@ -172,30 +208,46 @@ export const LiveChatWidgetStateful = props => {
|
|
|
172
208
|
Description: "Start proactive chat method called, when chat was already triggered."
|
|
173
209
|
});
|
|
174
210
|
}
|
|
175
|
-
}); //
|
|
211
|
+
}); // Start chat from SDK Event
|
|
176
212
|
|
|
177
|
-
BroadcastService.getMessageByEventName(
|
|
213
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
178
214
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
179
215
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
180
216
|
Description: "Start chat event received."
|
|
181
217
|
});
|
|
218
|
+
const persistedState = getStateFromCache();
|
|
219
|
+
|
|
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;
|
|
182
234
|
|
|
183
|
-
|
|
235
|
+
// Minimize to Maximize
|
|
184
236
|
dispatch({
|
|
185
237
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
186
238
|
payload: false
|
|
187
239
|
});
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
});
|
|
190
247
|
}
|
|
191
|
-
}); //
|
|
192
|
-
|
|
193
|
-
BroadcastService.getMessageByEventName("EndChat").subscribe(async () => {
|
|
194
|
-
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
195
|
-
Event: TelemetryEvent.EndChatEventReceived,
|
|
196
|
-
Description: "End chat event received."
|
|
197
|
-
});
|
|
248
|
+
}); // End chat
|
|
198
249
|
|
|
250
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
199
251
|
if (canEndChat.current) {
|
|
200
252
|
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
201
253
|
} else {
|
|
@@ -203,17 +255,52 @@ export const LiveChatWidgetStateful = props => {
|
|
|
203
255
|
const skipCloseChat = false;
|
|
204
256
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
205
257
|
}
|
|
258
|
+
|
|
259
|
+
BroadcastService.postMessage({
|
|
260
|
+
eventName: BroadcastEvent.CloseChat
|
|
261
|
+
});
|
|
206
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
|
+
|
|
207
283
|
window.addEventListener("beforeunload", () => {
|
|
284
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
285
|
+
Event: TelemetryEvent.WindowClosed,
|
|
286
|
+
Description: "Closed window."
|
|
287
|
+
});
|
|
208
288
|
disposeTelemetryLoggers();
|
|
209
289
|
});
|
|
210
290
|
|
|
211
291
|
if (state.appStates.conversationEndedByAgent) {
|
|
212
292
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
213
|
-
}
|
|
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
|
+
});
|
|
214
302
|
}, []);
|
|
215
303
|
useEffect(() => {
|
|
216
|
-
canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
|
|
217
304
|
canEndChat.current = state.appStates.conversationState === ConversationState.Active;
|
|
218
305
|
|
|
219
306
|
if (state.appStates.conversationState === ConversationState.Active) {
|
|
@@ -234,7 +321,10 @@ export const LiveChatWidgetStateful = props => {
|
|
|
234
321
|
});
|
|
235
322
|
});
|
|
236
323
|
}
|
|
237
|
-
}, [state.appStates.conversationState]);
|
|
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.
|
|
238
328
|
|
|
239
329
|
useEffect(() => {
|
|
240
330
|
currentMessageCountRef.current = -1;
|
|
@@ -266,7 +356,19 @@ export const LiveChatWidgetStateful = props => {
|
|
|
266
356
|
setWebChatStyles({ ...webChatStyles,
|
|
267
357
|
...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
|
|
268
358
|
});
|
|
269
|
-
}, [(_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]);
|
|
270
372
|
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
271
373
|
|
|
272
374
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -282,16 +384,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
282
384
|
|
|
283
385
|
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
284
386
|
|
|
285
|
-
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
286
|
-
|
|
287
|
-
useEffect(() => {
|
|
288
|
-
const chatWidgetStateChangeEvent = {
|
|
289
|
-
eventName: BroadcastEvent.ChatWidgetStateChanged,
|
|
290
|
-
payload: { ...state
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
294
|
-
}, [state]);
|
|
387
|
+
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
295
388
|
return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
296
389
|
styleOptions: webChatStyles,
|
|
297
390
|
directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
|
|
@@ -299,28 +392,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
299
392
|
id: widgetElementId,
|
|
300
393
|
styles: generalStyles,
|
|
301
394
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
302
|
-
}, !((_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, {
|
|
303
396
|
buttonProps: props.chatButtonProps,
|
|
304
397
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
305
398
|
startChat: prepareStartChatRelay
|
|
306
|
-
})), !((_props$
|
|
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, {
|
|
307
400
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
308
401
|
startChat: prepareStartChatRelay
|
|
309
|
-
})), !((_props$
|
|
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, {
|
|
310
403
|
headerProps: props.headerProps,
|
|
311
404
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
312
405
|
endChat: endChatRelay
|
|
313
|
-
})), !((_props$
|
|
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, {
|
|
314
407
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
315
408
|
initStartChat: initStartChatRelay
|
|
316
|
-
})), !((_props$
|
|
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, {
|
|
317
410
|
surveyProps: props.preChatSurveyPaneProps,
|
|
318
411
|
initStartChat: initStartChatRelay
|
|
319
|
-
})), !((_props$
|
|
412
|
+
})), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
320
413
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
321
|
-
}, props.callingContainerProps)), !((_props$
|
|
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, {
|
|
322
415
|
setPostChatContext: setPostChatContextRelay,
|
|
323
416
|
prepareEndChat: prepareEndChatRelay
|
|
324
|
-
}))), !((_props$
|
|
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))));
|
|
325
418
|
};
|
|
326
419
|
export default LiveChatWidgetStateful;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
-
|
|
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
|
|
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"));
|