@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.ceb1702
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 +35 -11
- package/lib/cjs/common/Constants.js +46 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +32 -3
- package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
- package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
- package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +30 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -39
- package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/headerstateful/HeaderStateful.js +1 -7
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -15
- package/lib/cjs/components/livechatwidget/common/endChat.js +63 -12
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +15 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +105 -20
- package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
- package/lib/cjs/components/livechatwidget/common/startChat.js +82 -26
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +200 -43
- package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -6
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
- 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 +45 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/cjs/contexts/createReducer.js +16 -10
- package/lib/cjs/controller/componentController.js +1 -1
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +42 -5
- package/lib/esm/common/telemetry/TelemetryConstants.js +32 -3
- package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
- package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
- package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +19 -1
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +18 -7
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -37
- package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/headerstateful/HeaderStateful.js +1 -7
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -16
- package/lib/esm/components/livechatwidget/common/endChat.js +59 -13
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -4
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +94 -20
- package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
- package/lib/esm/components/livechatwidget/common/startChat.js +82 -30
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +188 -46
- package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
- 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 +32 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/esm/contexts/createReducer.js +16 -9
- package/lib/esm/controller/componentController.js +1 -1
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +23 -2
- package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +27 -5
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
- package/lib/types/common/utils.d.ts +3 -0
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
- package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -2
- package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -1
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -0
- 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/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
- package/package.json +6 -7
|
@@ -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,33 +9,53 @@ 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";
|
|
13
|
-
import { getReconnectIdForAuthenticatedChat } from "./reconnectChatHelper";
|
|
12
|
+
import { createTimer, getWidgetCacheId } from "../../../common/utils";
|
|
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) => {
|
|
21
|
+
var _props$reconnectChatP;
|
|
22
|
+
|
|
18
23
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
19
24
|
return;
|
|
20
|
-
} //
|
|
25
|
+
} // Redirecting if unauthenticated reconnect chat expired
|
|
26
|
+
|
|
21
27
|
|
|
28
|
+
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
29
|
+
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
30
|
+
|
|
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);
|
|
32
|
+
} else {
|
|
33
|
+
// Getting reconnectId for authenticated chat
|
|
34
|
+
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
22
35
|
|
|
36
|
+
if (reconnectId) {
|
|
37
|
+
dispatch({
|
|
38
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
39
|
+
payload: reconnectId
|
|
40
|
+
});
|
|
41
|
+
dispatch({
|
|
42
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
43
|
+
payload: ConversationState.ReconnectChat
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
setCustomContextParams(props, state);
|
|
47
|
+
setupChatState(chatSDK, dispatch, setAdapter, state.appStates.conversationState === ConversationState.ProactiveChat, state.appStates.proactiveChatStates.proactiveChatEnablePrechat);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const setupChatState = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
53
|
+
// Getting PreChat Survey Context
|
|
23
54
|
const parseToJson = false;
|
|
24
55
|
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
25
|
-
const showPrechat =
|
|
56
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
26
57
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (reconnectId) {
|
|
30
|
-
dispatch({
|
|
31
|
-
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
32
|
-
payload: reconnectId
|
|
33
|
-
});
|
|
34
|
-
dispatch({
|
|
35
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
36
|
-
payload: ConversationState.ReconnectChat
|
|
37
|
-
});
|
|
38
|
-
} else if (showPrechat) {
|
|
58
|
+
if (showPrechat) {
|
|
39
59
|
dispatch({
|
|
40
60
|
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
41
61
|
payload: preChatSurveyResponse
|
|
@@ -58,12 +78,29 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
58
78
|
try {
|
|
59
79
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
60
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
|
+
|
|
61
96
|
try {
|
|
62
97
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
63
98
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
64
99
|
Event: TelemetryEvent.StartChatSDKCall
|
|
65
100
|
});
|
|
66
|
-
|
|
101
|
+
optionalParams = Object.assign({}, params, optionalParams);
|
|
102
|
+
await chatSDK.startChat(optionalParams);
|
|
103
|
+
isStartChatSuccessful = true;
|
|
67
104
|
} catch (error) {
|
|
68
105
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
69
106
|
Event: TelemetryEvent.StartChatMethodException,
|
|
@@ -71,6 +108,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
71
108
|
exception: `Failed to setup startChat: ${error}`
|
|
72
109
|
}
|
|
73
110
|
});
|
|
111
|
+
isStartChatSuccessful = false;
|
|
74
112
|
}
|
|
75
113
|
|
|
76
114
|
const newAdapter = await createAdapter(chatSDK);
|
|
@@ -98,10 +136,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
98
136
|
await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
99
137
|
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
100
138
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
139
|
+
if (isStartChatSuccessful) {
|
|
140
|
+
dispatch({
|
|
141
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
142
|
+
payload: ConversationState.Active
|
|
143
|
+
});
|
|
144
|
+
}
|
|
105
145
|
} else {
|
|
106
146
|
dispatch({
|
|
107
147
|
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
@@ -139,20 +179,21 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
139
179
|
|
|
140
180
|
|
|
141
181
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
142
|
-
var _DataStoreManager$cli, _persistedState$
|
|
182
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
|
|
143
183
|
|
|
144
|
-
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");
|
|
145
186
|
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
146
187
|
|
|
147
|
-
if (persistedState !== null && persistedState !== void 0 && (_persistedState$
|
|
148
|
-
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;
|
|
149
190
|
|
|
150
191
|
dispatch({
|
|
151
192
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
152
193
|
payload: ConversationState.Loading
|
|
153
194
|
});
|
|
154
195
|
const optionalParams = {
|
|
155
|
-
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
|
|
156
197
|
};
|
|
157
198
|
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
158
199
|
return true;
|
|
@@ -161,4 +202,15 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
161
202
|
}
|
|
162
203
|
};
|
|
163
204
|
|
|
164
|
-
|
|
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";
|
|
8
|
-
import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
|
|
9
|
-
import { initStartChat, prepareStartChat } from "../common/startChat";
|
|
7
|
+
import { createTimer, getLocaleDirection, getWidgetCacheId, getWidgetEndChatEventName } from "../../../common/utils";
|
|
8
|
+
import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
|
|
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";
|
|
@@ -32,7 +32,7 @@ import { createFooter } from "../common/createFooter";
|
|
|
32
32
|
import { createInternetConnectionChangeHandler } from "../common/createInternetConnectionChangeHandler";
|
|
33
33
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
34
34
|
import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
|
|
35
|
-
import { endChat } from "../common/endChat";
|
|
35
|
+
import { endChat, prepareEndChat } from "../common/endChat";
|
|
36
36
|
import { getGeneralStylesForButton } from "../common/getGeneralStylesForButton";
|
|
37
37
|
import { initCallingSdk } from "../common/initCallingSdk";
|
|
38
38
|
import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
|
|
@@ -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,12 +53,14 @@ 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
|
|
60
61
|
} = Components;
|
|
61
|
-
const canStartProactiveChat = useRef(true);
|
|
62
|
+
const canStartProactiveChat = useRef(true);
|
|
63
|
+
const canEndChat = useRef(true); // Process general styles
|
|
62
64
|
|
|
63
65
|
const generalStyles = {
|
|
64
66
|
root: Object.assign({}, getGeneralStylesForButton(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
|
|
@@ -66,6 +68,33 @@ export const LiveChatWidgetStateful = props => {
|
|
|
66
68
|
TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
|
|
67
69
|
const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
|
|
68
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
|
+
|
|
69
98
|
useEffect(() => {
|
|
70
99
|
var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
|
|
71
100
|
|
|
@@ -80,6 +109,10 @@ export const LiveChatWidgetStateful = props => {
|
|
|
80
109
|
type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
|
|
81
110
|
payload: ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.skipChatButtonRendering) || false
|
|
82
111
|
});
|
|
112
|
+
dispatch({
|
|
113
|
+
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
114
|
+
payload: false
|
|
115
|
+
});
|
|
83
116
|
initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
84
117
|
sdkCreated && dispatch({
|
|
85
118
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
@@ -90,7 +123,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
90
123
|
if (!((_props$controlProps3 = props.controlProps) !== null && _props$controlProps3 !== void 0 && _props$controlProps3.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
91
124
|
var _props$reconnectChatP2;
|
|
92
125
|
|
|
93
|
-
|
|
126
|
+
startUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
|
|
94
127
|
} // Initialize global dir
|
|
95
128
|
|
|
96
129
|
|
|
@@ -100,25 +133,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
100
133
|
payload: globalDir
|
|
101
134
|
});
|
|
102
135
|
|
|
103
|
-
if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.
|
|
136
|
+
if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
|
|
104
137
|
var _state$domainStates2;
|
|
105
138
|
|
|
106
139
|
const optionalParams = {
|
|
107
|
-
liveChatContext:
|
|
108
|
-
chatToken: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.chatToken
|
|
109
|
-
}
|
|
140
|
+
liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
|
|
110
141
|
};
|
|
111
142
|
initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
112
143
|
}
|
|
113
|
-
}, []);
|
|
144
|
+
}, []); // useEffect for when skip chat button rendering
|
|
145
|
+
|
|
114
146
|
useEffect(() => {
|
|
115
147
|
if (state.appStates.skipChatButtonRendering) {
|
|
116
148
|
var _props$reconnectChatP3;
|
|
117
149
|
|
|
150
|
+
BroadcastService.postMessage({
|
|
151
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
152
|
+
});
|
|
153
|
+
|
|
118
154
|
if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
|
|
119
|
-
var _props$reconnectChatP4;
|
|
155
|
+
var _props$reconnectChatP4, _props$reconnectChatP5;
|
|
120
156
|
|
|
121
|
-
handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, initStartChat);
|
|
157
|
+
handleUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
|
|
122
158
|
} else {
|
|
123
159
|
getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
|
|
124
160
|
if (authReconnectId && !state.appStates.reconnectId) {
|
|
@@ -131,18 +167,32 @@ export const LiveChatWidgetStateful = props => {
|
|
|
131
167
|
payload: ConversationState.ReconnectChat
|
|
132
168
|
});
|
|
133
169
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
170
|
+
const chatStartedSkippingChatButtonRendering = {
|
|
171
|
+
eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
|
|
172
|
+
};
|
|
173
|
+
BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
|
|
174
|
+
setupChatState(chatSDK, dispatch, setAdapter);
|
|
139
175
|
}
|
|
140
176
|
});
|
|
141
177
|
}
|
|
142
178
|
}
|
|
143
|
-
}, [state.appStates.skipChatButtonRendering]);
|
|
179
|
+
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
180
|
+
|
|
144
181
|
useEffect(() => {
|
|
145
|
-
|
|
182
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
|
|
183
|
+
|
|
184
|
+
// Add the custom context on receiving the SetCustomContext event
|
|
185
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
186
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
187
|
+
Event: TelemetryEvent.CustomContextReceived,
|
|
188
|
+
Description: "CustomContext received."
|
|
189
|
+
});
|
|
190
|
+
dispatch({
|
|
191
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
192
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
|
|
146
196
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
147
197
|
Event: TelemetryEvent.StartProactiveChatEventReceived,
|
|
148
198
|
Description: "Start proactive chat event received."
|
|
@@ -158,17 +208,100 @@ export const LiveChatWidgetStateful = props => {
|
|
|
158
208
|
Description: "Start proactive chat method called, when chat was already triggered."
|
|
159
209
|
});
|
|
160
210
|
}
|
|
211
|
+
}); // Start chat from SDK Event
|
|
212
|
+
|
|
213
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
214
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
215
|
+
Event: TelemetryEvent.StartChatEventRecevied,
|
|
216
|
+
Description: "Start chat event received."
|
|
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;
|
|
234
|
+
|
|
235
|
+
// Minimize to Maximize
|
|
236
|
+
dispatch({
|
|
237
|
+
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
238
|
+
payload: false
|
|
239
|
+
});
|
|
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
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}); // End chat
|
|
249
|
+
|
|
250
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
251
|
+
if (canEndChat.current) {
|
|
252
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
253
|
+
} else {
|
|
254
|
+
const skipEndChatSDK = true;
|
|
255
|
+
const skipCloseChat = false;
|
|
256
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
BroadcastService.postMessage({
|
|
260
|
+
eventName: BroadcastEvent.CloseChat
|
|
261
|
+
});
|
|
161
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
|
+
|
|
162
283
|
window.addEventListener("beforeunload", () => {
|
|
284
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
285
|
+
Event: TelemetryEvent.WindowClosed,
|
|
286
|
+
Description: "Closed window."
|
|
287
|
+
});
|
|
163
288
|
disposeTelemetryLoggers();
|
|
164
289
|
});
|
|
165
290
|
|
|
166
291
|
if (state.appStates.conversationEndedByAgent) {
|
|
167
292
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
168
|
-
}
|
|
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
|
+
});
|
|
169
302
|
}, []);
|
|
170
303
|
useEffect(() => {
|
|
171
|
-
|
|
304
|
+
canEndChat.current = state.appStates.conversationState === ConversationState.Active;
|
|
172
305
|
|
|
173
306
|
if (state.appStates.conversationState === ConversationState.Active) {
|
|
174
307
|
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
@@ -188,7 +321,10 @@ export const LiveChatWidgetStateful = props => {
|
|
|
188
321
|
});
|
|
189
322
|
});
|
|
190
323
|
}
|
|
191
|
-
}, [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.
|
|
192
328
|
|
|
193
329
|
useEffect(() => {
|
|
194
330
|
currentMessageCountRef.current = -1;
|
|
@@ -220,29 +356,35 @@ export const LiveChatWidgetStateful = props => {
|
|
|
220
356
|
setWebChatStyles({ ...webChatStyles,
|
|
221
357
|
...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
|
|
222
358
|
});
|
|
223
|
-
}, [(_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]);
|
|
224
372
|
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
225
373
|
|
|
226
374
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
375
|
|
|
228
376
|
|
|
229
|
-
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
377
|
+
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
230
381
|
|
|
231
382
|
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
383
|
|
|
233
384
|
|
|
234
385
|
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
235
386
|
|
|
236
|
-
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
237
|
-
|
|
238
|
-
useEffect(() => {
|
|
239
|
-
const chatWidgetStateChangeEvent = {
|
|
240
|
-
eventName: BroadcastEvent.ChatWidgetStateChanged,
|
|
241
|
-
payload: { ...state
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
245
|
-
}, [state]);
|
|
387
|
+
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
246
388
|
return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
247
389
|
styleOptions: webChatStyles,
|
|
248
390
|
directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
|
|
@@ -250,28 +392,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
250
392
|
id: widgetElementId,
|
|
251
393
|
styles: generalStyles,
|
|
252
394
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
253
|
-
}, !((_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, {
|
|
254
396
|
buttonProps: props.chatButtonProps,
|
|
255
397
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
256
398
|
startChat: prepareStartChatRelay
|
|
257
|
-
})), !((_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, {
|
|
258
400
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
259
401
|
startChat: prepareStartChatRelay
|
|
260
|
-
})), !((_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, {
|
|
261
403
|
headerProps: props.headerProps,
|
|
262
404
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
263
405
|
endChat: endChatRelay
|
|
264
|
-
})), !((_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, {
|
|
265
407
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
266
408
|
initStartChat: initStartChatRelay
|
|
267
|
-
})), !((_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, {
|
|
268
410
|
surveyProps: props.preChatSurveyPaneProps,
|
|
269
411
|
initStartChat: initStartChatRelay
|
|
270
|
-
}), !((_props$
|
|
412
|
+
})), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
271
413
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
272
|
-
}, 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, {
|
|
273
415
|
setPostChatContext: setPostChatContextRelay,
|
|
274
|
-
|
|
275
|
-
}))), !((_props$
|
|
416
|
+
prepareEndChat: prepareEndChatRelay
|
|
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))));
|
|
276
418
|
};
|
|
277
419
|
export default LiveChatWidgetStateful;
|
|
@@ -3,6 +3,8 @@ import { LoadingPane } from "@microsoft/omnichannel-chat-components";
|
|
|
3
3
|
import { defaultGeneralPostChatLoadingPaneStyleProps } from "./common/defaultgeneralPostChatLoadingPaneStyleProps";
|
|
4
4
|
import { findAllFocusableElement } from "../../common/utils";
|
|
5
5
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
6
|
+
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
7
|
+
import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
6
8
|
export const PostChatLoadingPaneStateful = props => {
|
|
7
9
|
var _props$styleProps;
|
|
8
10
|
|
|
@@ -28,6 +30,10 @@ export const PostChatLoadingPaneStateful = props => {
|
|
|
28
30
|
if (firstElement && firstElement[0]) {
|
|
29
31
|
firstElement[0].focus();
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
35
|
+
Event: TelemetryEvent.PostChatSurveyLoadingPaneLoaded
|
|
36
|
+
});
|
|
31
37
|
}, []);
|
|
32
38
|
return /*#__PURE__*/React.createElement(LoadingPane, {
|
|
33
39
|
componentOverrides: props.componentOverrides,
|
|
@@ -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);
|