@microsoft/omnichannel-chat-widget 0.1.0-main.c2417f9 → 0.1.0-main.ce08f21
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/lib/cjs/common/Constants.js +4 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -0
- package/lib/cjs/common/utils.js +58 -5
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
- package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -0
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +152 -81
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +167 -112
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/cjs/contexts/createReducer.js +8 -0
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/esm/common/Constants.js +4 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +7 -0
- package/lib/esm/common/utils.js +45 -3
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
- package/lib/esm/components/livechatwidget/common/endChat.js +53 -21
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +9 -2
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +147 -80
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -112
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/esm/contexts/createReducer.js +8 -0
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/types/common/Constants.d.ts +2 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
- package/lib/types/common/utils.d.ts +6 -3
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
- package/package.json +4 -3
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
4
|
-
import { BroadcastService, decodeComponentString } from "@microsoft/omnichannel-chat-components";
|
|
4
|
+
import { BroadcastService, decodeComponentString, BroadcastServiceInitialize } 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, getWidgetCacheId, getWidgetEndChatEventName } from "../../../common/utils";
|
|
7
|
+
import { createTimer, getLocaleDirection, getStateFromCache, getWidgetCacheId, getWidgetEndChatEventName, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
8
8
|
import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
|
|
9
|
-
import { initStartChat, prepareStartChat } from "../common/startChat";
|
|
9
|
+
import { initStartChat, prepareStartChat, setPreChatAndInitiateChat } 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";
|
|
@@ -43,8 +43,10 @@ import { startProactiveChat } from "../common/startProactiveChat";
|
|
|
43
43
|
import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
44
44
|
import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
45
45
|
import useChatSDKStore from "../../../hooks/useChatSDKStore";
|
|
46
|
+
import { ActivityStreamHandler } from "../common/ActivityStreamHandler";
|
|
47
|
+
import { Constants } from "../../../common/Constants";
|
|
46
48
|
export const LiveChatWidgetStateful = props => {
|
|
47
|
-
var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$
|
|
49
|
+
var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps13, _props$controlProps14, _props$componentOverr, _props$controlProps15, _props$componentOverr2, _props$controlProps16, _props$componentOverr3, _props$controlProps17, _props$componentOverr4, _props$controlProps18, _props$componentOverr5, _props$controlProps19, _props$componentOverr6, _props$controlProps20, _props$componentOverr7, _props$controlProps21, _props$controlProps22, _props$componentOverr8, _props$controlProps23, _props$componentOverr9, _props$controlProps24, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
|
|
48
50
|
|
|
49
51
|
const [state, dispatch] = useChatContextStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
52
|
|
|
@@ -59,8 +61,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
59
61
|
const {
|
|
60
62
|
Composer
|
|
61
63
|
} = Components;
|
|
62
|
-
const canStartProactiveChat = useRef(true);
|
|
63
|
-
const canEndChat = useRef(true); // Process general styles
|
|
64
|
+
const canStartProactiveChat = useRef(true); // Process general styles
|
|
64
65
|
|
|
65
66
|
const generalStyles = {
|
|
66
67
|
root: Object.assign({}, getGeneralStylesForButton(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
|
|
@@ -69,9 +70,32 @@ export const LiveChatWidgetStateful = props => {
|
|
|
69
70
|
const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
|
|
70
71
|
const currentMessageCountRef = useRef(0);
|
|
71
72
|
let widgetStateEventName = "";
|
|
73
|
+
|
|
74
|
+
const initiateEndChatOnBrowserUnload = () => {
|
|
75
|
+
var _DataStoreManager$cli;
|
|
76
|
+
|
|
77
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
78
|
+
Event: TelemetryEvent.BrowserUnloadEventStarted,
|
|
79
|
+
Description: "Browser unload event received."
|
|
80
|
+
});
|
|
81
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false); // Clean local storage
|
|
82
|
+
|
|
83
|
+
(_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
|
|
84
|
+
|
|
85
|
+
if (voiceVideoCallingSDK) {
|
|
86
|
+
voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
|
|
87
|
+
} //Message for clearing window[popouTab]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
BroadcastService.postMessage({
|
|
91
|
+
eventName: BroadcastEvent.ClosePopoutWindow
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
72
95
|
useEffect(() => {
|
|
73
|
-
var _props$controlProps2, _props$controlProps3, _props$
|
|
96
|
+
var _props$chatSDK, _props$chatSDK$omnich, _props$controlProps2, _props$controlProps3, _props$controlProps4, _props$controlProps6, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps7, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
|
|
74
97
|
|
|
98
|
+
BroadcastServiceInitialize((_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.widgetId);
|
|
75
99
|
registerTelemetryLoggers(props, dispatch);
|
|
76
100
|
createInternetConnectionChangeHandler();
|
|
77
101
|
DataStoreManager.clientDataStore = props.contextDataStore ?? undefined;
|
|
@@ -87,44 +111,73 @@ export const LiveChatWidgetStateful = props => {
|
|
|
87
111
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
88
112
|
payload: false
|
|
89
113
|
});
|
|
114
|
+
|
|
115
|
+
if ((_props$controlProps3 = props.controlProps) !== null && _props$controlProps3 !== void 0 && _props$controlProps3.widgetInstanceId && !isNullOrEmptyString((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.widgetInstanceId)) {
|
|
116
|
+
var _props$controlProps5;
|
|
117
|
+
|
|
118
|
+
dispatch({
|
|
119
|
+
type: LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
|
|
120
|
+
payload: (_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.widgetInstanceId
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
90
124
|
initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
91
125
|
sdkCreated && dispatch({
|
|
92
126
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
93
127
|
payload: true
|
|
94
128
|
});
|
|
129
|
+
}); // Initialize global dir
|
|
130
|
+
|
|
131
|
+
const globalDir = ((_props$controlProps6 = props.controlProps) === null || _props$controlProps6 === void 0 ? void 0 : _props$controlProps6.dir) ?? getLocaleDirection((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Cha = _props$chatConfig.ChatWidgetLanguage) === null || _props$chatConfig$Cha === void 0 ? void 0 : _props$chatConfig$Cha.msdyn_localeid);
|
|
132
|
+
dispatch({
|
|
133
|
+
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
134
|
+
payload: globalDir
|
|
95
135
|
});
|
|
96
136
|
|
|
97
|
-
if (!((_props$
|
|
137
|
+
if (!((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
98
138
|
var _props$reconnectChatP2;
|
|
99
139
|
|
|
100
|
-
startUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
|
|
101
|
-
|
|
140
|
+
startUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
|
|
141
|
+
return;
|
|
142
|
+
} // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
144
|
|
|
103
145
|
|
|
104
|
-
const
|
|
105
|
-
dispatch({
|
|
106
|
-
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
107
|
-
payload: globalDir
|
|
108
|
-
});
|
|
146
|
+
const isAuthenticationSettingsEnabled = (_props$chatConfig2 = props.chatConfig) !== null && _props$chatConfig2 !== void 0 && (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) !== null && _props$chatConfig2$Li !== void 0 && _props$chatConfig2$Li.msdyn_javascriptclientfunction ? true : false;
|
|
109
147
|
|
|
110
|
-
if (
|
|
111
|
-
var _state$
|
|
148
|
+
if (isAuthenticationSettingsEnabled === false) {
|
|
149
|
+
var _state$domainStates;
|
|
112
150
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
151
|
+
if (!isUndefinedOrEmpty((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === ConversationState.Active) {
|
|
152
|
+
var _state$domainStates2;
|
|
153
|
+
|
|
154
|
+
const optionalParams = {
|
|
155
|
+
liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
|
|
156
|
+
};
|
|
157
|
+
initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
} // All other case should show start chat button, skipChatButtonRendering will take care of it own
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
dispatch({
|
|
164
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
165
|
+
payload: ConversationState.Closed
|
|
166
|
+
});
|
|
118
167
|
}, []); // useEffect for when skip chat button rendering
|
|
119
168
|
|
|
120
169
|
useEffect(() => {
|
|
121
170
|
if (state.appStates.skipChatButtonRendering) {
|
|
122
171
|
var _props$reconnectChatP3;
|
|
123
172
|
|
|
173
|
+
BroadcastService.postMessage({
|
|
174
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
175
|
+
});
|
|
176
|
+
|
|
124
177
|
if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
|
|
125
178
|
var _props$reconnectChatP4, _props$reconnectChatP5;
|
|
126
179
|
|
|
127
|
-
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);
|
|
180
|
+
handleUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, 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);
|
|
128
181
|
} else {
|
|
129
182
|
getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
|
|
130
183
|
if (authReconnectId && !state.appStates.reconnectId) {
|
|
@@ -141,11 +194,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
141
194
|
eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
|
|
142
195
|
};
|
|
143
196
|
BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
|
|
144
|
-
dispatch
|
|
145
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
146
|
-
payload: ConversationState.Loading
|
|
147
|
-
});
|
|
148
|
-
initStartChat(chatSDK, dispatch, setAdapter);
|
|
197
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter);
|
|
149
198
|
}
|
|
150
199
|
});
|
|
151
200
|
}
|
|
@@ -153,7 +202,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
153
202
|
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
154
203
|
|
|
155
204
|
useEffect(() => {
|
|
156
|
-
var _chatSDK$
|
|
205
|
+
var _chatSDK$omnichannelC5, _chatSDK$omnichannelC6, _props$controlProps10;
|
|
157
206
|
|
|
158
207
|
// Add the custom context on receiving the SetCustomContext event
|
|
159
208
|
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
@@ -185,25 +234,36 @@ export const LiveChatWidgetStateful = props => {
|
|
|
185
234
|
}); // Start chat from SDK Event
|
|
186
235
|
|
|
187
236
|
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
188
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2,
|
|
237
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps8;
|
|
189
238
|
|
|
190
239
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
191
240
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
192
241
|
Description: "Start chat event received."
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
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) ?? "");
|
|
196
|
-
const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
197
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
242
|
+
});
|
|
243
|
+
const persistedState = getStateFromCache(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, (props === null || props === void 0 ? void 0 : (_props$controlProps8 = props.controlProps) === null || _props$controlProps8 === void 0 ? void 0 : _props$controlProps8.widgetInstanceId) ?? ""); // Chat not found in cache
|
|
198
244
|
|
|
199
|
-
if (persistedState
|
|
245
|
+
if (persistedState === undefined) {
|
|
200
246
|
BroadcastService.postMessage({
|
|
201
247
|
eventName: BroadcastEvent.ChatInitiated
|
|
202
248
|
});
|
|
203
249
|
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
204
|
-
|
|
250
|
+
return;
|
|
251
|
+
} // Chat exist in cache
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
if (persistedState) {
|
|
205
255
|
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
|
|
206
256
|
|
|
257
|
+
// Only initiate new chat if widget state in cache in one of the followings
|
|
258
|
+
if (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat) {
|
|
259
|
+
BroadcastService.postMessage({
|
|
260
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
261
|
+
});
|
|
262
|
+
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
263
|
+
return;
|
|
264
|
+
} // If minimized, maximize the chat
|
|
265
|
+
|
|
266
|
+
|
|
207
267
|
dispatch({
|
|
208
268
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
209
269
|
payload: false
|
|
@@ -218,67 +278,40 @@ export const LiveChatWidgetStateful = props => {
|
|
|
218
278
|
}
|
|
219
279
|
}); // End chat
|
|
220
280
|
|
|
221
|
-
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const isChatUnloading = ((_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.chatUnloading) ?? false;
|
|
225
|
-
const isSdkCall = ((_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.isSdkCall) ?? false;
|
|
226
|
-
const eventDescription = isChatUnloading ? "End chat event received from unload." : "End chat event received.";
|
|
227
|
-
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
228
|
-
Event: TelemetryEvent.EndChatEventReceived,
|
|
229
|
-
Description: eventDescription
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
if (isChatUnloading) {
|
|
233
|
-
var _DataStoreManager$cli2;
|
|
281
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
282
|
+
if (state.appStates.skipChatButtonRendering !== true) {
|
|
283
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$controlProps9;
|
|
234
284
|
|
|
235
|
-
//
|
|
236
|
-
|
|
285
|
+
// This is to ensure to get latest state from cache in multitab
|
|
286
|
+
const persistedState = getStateFromCache(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, (props === null || props === void 0 ? void 0 : (_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.widgetInstanceId) ?? "");
|
|
237
287
|
|
|
238
|
-
(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
} // Raise chatClose for SDK events
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (isSdkCall) {
|
|
249
|
-
BroadcastService.postMessage({
|
|
250
|
-
eventName: BroadcastEvent.CloseChat
|
|
251
|
-
});
|
|
288
|
+
if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
|
|
289
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
290
|
+
} else {
|
|
291
|
+
const skipEndChatSDK = true;
|
|
292
|
+
const skipCloseChat = false;
|
|
293
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
294
|
+
}
|
|
252
295
|
}
|
|
253
|
-
}); // reset proactive chat params
|
|
254
296
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
258
|
-
payload: {
|
|
259
|
-
proactiveChatBodyTitle: "",
|
|
260
|
-
proactiveChatEnablePrechat: false,
|
|
261
|
-
proactiveChatInNewWindow: false
|
|
262
|
-
}
|
|
297
|
+
BroadcastService.postMessage({
|
|
298
|
+
eventName: BroadcastEvent.CloseChat
|
|
263
299
|
});
|
|
300
|
+
}); // End chat on browser unload
|
|
301
|
+
|
|
302
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
|
|
303
|
+
initiateEndChatOnBrowserUnload();
|
|
264
304
|
}); // Listen to end chat event from other tabs
|
|
265
305
|
|
|
266
|
-
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$
|
|
306
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC5 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC5 === void 0 ? void 0 : _chatSDK$omnichannelC5.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC6 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC6 === void 0 ? void 0 : _chatSDK$omnichannelC6.widgetId, ((_props$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
|
|
267
307
|
BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
268
308
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
window.addEventListener("beforeunload", () => {
|
|
272
|
-
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
273
|
-
Event: TelemetryEvent.WindowClosed,
|
|
274
|
-
Description: "Closed window."
|
|
275
|
-
});
|
|
276
|
-
disposeTelemetryLoggers();
|
|
277
|
-
});
|
|
309
|
+
return;
|
|
310
|
+
}); // When conversation ended by agent
|
|
278
311
|
|
|
279
312
|
if (state.appStates.conversationEndedByAgent) {
|
|
280
313
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
281
|
-
} //Listen to WidgetSize
|
|
314
|
+
} //Listen to WidgetSize, used for minimize to maximize
|
|
282
315
|
|
|
283
316
|
|
|
284
317
|
BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
|
|
@@ -287,25 +320,23 @@ export const LiveChatWidgetStateful = props => {
|
|
|
287
320
|
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
288
321
|
});
|
|
289
322
|
});
|
|
323
|
+
return () => {
|
|
324
|
+
disposeTelemetryLoggers();
|
|
325
|
+
};
|
|
290
326
|
}, []);
|
|
291
327
|
useEffect(() => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (state.appStates.conversationState === ConversationState.Active) {
|
|
295
|
-
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
296
|
-
BroadcastService.postMessage({
|
|
297
|
-
eventName: BroadcastEvent.NewMessageNotification
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
} // Track the message count
|
|
301
|
-
|
|
302
|
-
|
|
328
|
+
// On new message
|
|
303
329
|
if (state.appStates.conversationState === ConversationState.Active) {
|
|
304
330
|
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
331
|
+
// Track the message count
|
|
305
332
|
currentMessageCountRef.current++;
|
|
306
333
|
dispatch({
|
|
307
334
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
308
335
|
payload: currentMessageCountRef.current + 1
|
|
336
|
+
}); // New message notification
|
|
337
|
+
|
|
338
|
+
BroadcastService.postMessage({
|
|
339
|
+
eventName: BroadcastEvent.NewMessageNotification
|
|
309
340
|
});
|
|
310
341
|
});
|
|
311
342
|
}
|
|
@@ -315,6 +346,12 @@ export const LiveChatWidgetStateful = props => {
|
|
|
315
346
|
}, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
|
|
316
347
|
|
|
317
348
|
useEffect(() => {
|
|
349
|
+
if (state.appStates.isMinimized) {
|
|
350
|
+
ActivityStreamHandler.cork();
|
|
351
|
+
} else {
|
|
352
|
+
setTimeout(() => ActivityStreamHandler.uncork(), 500);
|
|
353
|
+
}
|
|
354
|
+
|
|
318
355
|
currentMessageCountRef.current = -1;
|
|
319
356
|
dispatch({
|
|
320
357
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
@@ -329,7 +366,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
329
366
|
}, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
|
|
330
367
|
|
|
331
368
|
useEffect(() => {
|
|
332
|
-
if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
|
|
369
|
+
if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
|
|
333
370
|
const customEvent = {
|
|
334
371
|
elementType: ElementType.Custom,
|
|
335
372
|
eventName: BroadcastEvent.UnreadMessageCount,
|
|
@@ -347,22 +384,37 @@ export const LiveChatWidgetStateful = props => {
|
|
|
347
384
|
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
|
|
348
385
|
|
|
349
386
|
useEffect(() => {
|
|
350
|
-
var _props$
|
|
387
|
+
var _props$controlProps11, _props$chatSDK2, _props$chatSDK2$omnic, _props$chatSDK3, _props$chatSDK3$omnic, _props$controlProps12;
|
|
388
|
+
|
|
389
|
+
// Only activate these windows events when conversation state is active and chat widget is in popout mode
|
|
390
|
+
// Ghost chat scenarios
|
|
391
|
+
if (state.appStates.conversationState === ConversationState.Active && ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.skipChatButtonRendering) === true) {
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
393
|
+
window.onbeforeunload = function () {
|
|
394
|
+
const prompt = Constants.BrowserUnloadConfirmationMessage;
|
|
395
|
+
return prompt;
|
|
396
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
351
397
|
|
|
352
|
-
|
|
398
|
+
|
|
399
|
+
window.onunload = function () {
|
|
400
|
+
initiateEndChatOnBrowserUnload();
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
widgetStateEventName = getWidgetCacheId(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.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK3 = props.chatSDK) === null || _props$chatSDK3 === void 0 ? void 0 : (_props$chatSDK3$omnic = _props$chatSDK3.omnichannelConfig) === null || _props$chatSDK3$omnic === void 0 ? void 0 : _props$chatSDK3$omnic.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.widgetInstanceId) ?? "");
|
|
353
405
|
const chatWidgetStateChangeEvent = {
|
|
354
406
|
eventName: widgetStateEventName,
|
|
355
407
|
payload: { ...state
|
|
356
408
|
}
|
|
357
409
|
};
|
|
358
410
|
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
359
|
-
}, [state]);
|
|
411
|
+
}, [state.appStates.conversationState]);
|
|
360
412
|
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
361
413
|
|
|
362
414
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
415
|
|
|
364
416
|
|
|
365
|
-
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
417
|
+
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
366
418
|
|
|
367
419
|
|
|
368
420
|
const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
@@ -370,7 +422,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
370
422
|
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
423
|
|
|
372
424
|
|
|
373
|
-
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
425
|
+
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
374
426
|
|
|
375
427
|
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
376
428
|
return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
@@ -380,28 +432,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
380
432
|
id: widgetElementId,
|
|
381
433
|
styles: generalStyles,
|
|
382
434
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
383
|
-
}, !((_props$
|
|
435
|
+
}, !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideChatButton) && !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.skipChatButtonRendering) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
|
|
384
436
|
buttonProps: props.chatButtonProps,
|
|
385
437
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
386
438
|
startChat: prepareStartChatRelay
|
|
387
|
-
})), !((_props$
|
|
439
|
+
})), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
|
|
388
440
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
389
441
|
startChat: prepareStartChatRelay
|
|
390
|
-
})), !((_props$
|
|
442
|
+
})), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
|
|
391
443
|
headerProps: props.headerProps,
|
|
392
444
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
393
445
|
endChat: endChatRelay
|
|
394
|
-
})), !((_props$
|
|
446
|
+
})), !((_props$controlProps17 = props.controlProps) !== null && _props$controlProps17 !== void 0 && _props$controlProps17.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$controlProps18 = props.controlProps) !== null && _props$controlProps18 !== void 0 && _props$controlProps18.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$controlProps19 = props.controlProps) !== null && _props$controlProps19 !== void 0 && _props$controlProps19.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
|
|
395
447
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
396
448
|
initStartChat: initStartChatRelay
|
|
397
|
-
})), !((_props$
|
|
449
|
+
})), !((_props$controlProps20 = props.controlProps) !== null && _props$controlProps20 !== void 0 && _props$controlProps20.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
|
|
398
450
|
surveyProps: props.preChatSurveyPaneProps,
|
|
399
451
|
initStartChat: initStartChatRelay
|
|
400
|
-
})), !((_props$
|
|
452
|
+
})), !((_props$controlProps21 = props.controlProps) !== null && _props$controlProps21 !== void 0 && _props$controlProps21.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
401
453
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
402
|
-
}, props.callingContainerProps)), !((_props$
|
|
454
|
+
}, props.callingContainerProps)), !((_props$controlProps22 = props.controlProps) !== null && _props$controlProps22 !== void 0 && _props$controlProps22.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$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
|
|
403
455
|
setPostChatContext: setPostChatContextRelay,
|
|
404
456
|
prepareEndChat: prepareEndChatRelay
|
|
405
|
-
}))), !((_props$
|
|
457
|
+
}))), !((_props$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.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))));
|
|
406
458
|
};
|
|
407
459
|
export default LiveChatWidgetStateful;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
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,
|
|
4
|
+
import { extractPreChatSurveyResponseValues, findAllFocusableElement, getStateFromCache, isUndefinedOrEmpty, parseAdaptiveCardPayload } from "../../common/utils";
|
|
5
5
|
import { ConversationState } from "../../contexts/common/ConversationState";
|
|
6
|
-
import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
|
|
7
6
|
import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
|
|
8
7
|
import { PreChatSurveyPane } from "@microsoft/omnichannel-chat-components";
|
|
9
8
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
@@ -67,14 +66,12 @@ export const PreChatSurveyPaneStateful = props => {
|
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
try {
|
|
70
|
-
var _state$domainStates, _state$domainStates$t, _state$domainStates$t2,
|
|
69
|
+
var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
|
|
71
70
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
75
|
-
let optionalParams = {};
|
|
71
|
+
const persistedState = getStateFromCache(((_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) ?? "", state.domainStates.widgetInstanceId ?? "");
|
|
72
|
+
let optionalParams = {}; //Connect to Active chats and chat is not popout
|
|
76
73
|
|
|
77
|
-
if (persistedState
|
|
74
|
+
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : _persistedState$domai.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active && !state.appStates.skipChatButtonRendering) {
|
|
78
75
|
var _persistedState$domai2;
|
|
79
76
|
|
|
80
77
|
optionalParams = {
|
|
@@ -103,7 +103,7 @@ export const ProactiveChatPaneStateful = props => {
|
|
|
103
103
|
});
|
|
104
104
|
},
|
|
105
105
|
...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
|
|
106
|
-
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
|
|
107
107
|
};
|
|
108
108
|
useEffect(() => {
|
|
109
109
|
setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));
|
|
@@ -8,6 +8,7 @@ export let ConversationState;
|
|
|
8
8
|
ConversationState[ConversationState["ProactiveChat"] = 4] = "ProactiveChat";
|
|
9
9
|
ConversationState[ConversationState["Active"] = 5] = "Active";
|
|
10
10
|
ConversationState[ConversationState["InActive"] = 6] = "InActive";
|
|
11
|
-
ConversationState[ConversationState["
|
|
12
|
-
ConversationState[ConversationState["
|
|
11
|
+
ConversationState[ConversationState["PostchatLoading"] = 7] = "PostchatLoading";
|
|
12
|
+
ConversationState[ConversationState["Postchat"] = 8] = "Postchat";
|
|
13
|
+
ConversationState[ConversationState["Closed"] = 9] = "Closed";
|
|
13
14
|
})(ConversationState || (ConversationState = {}));
|
|
@@ -34,4 +34,5 @@ export let LiveChatWidgetActionType;
|
|
|
34
34
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
|
|
35
35
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
|
|
36
36
|
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_SIZE"] = 32] = "SET_WIDGET_SIZE";
|
|
37
|
+
LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_INSTANCE_ID"] = 33] = "SET_WIDGET_INSTANCE_ID";
|
|
37
38
|
})(LiveChatWidgetActionType || (LiveChatWidgetActionType = {}));
|
|
@@ -20,14 +20,14 @@ export const getLiveChatWidgetContextInitialState = props => {
|
|
|
20
20
|
globalDir: "ltr",
|
|
21
21
|
liveChatContext: undefined,
|
|
22
22
|
customContext: undefined,
|
|
23
|
-
widgetSize: undefined
|
|
23
|
+
widgetSize: undefined,
|
|
24
|
+
widgetInstanceId: ""
|
|
24
25
|
},
|
|
25
26
|
appStates: {
|
|
26
27
|
conversationState: ConversationState.Closed,
|
|
27
28
|
isMinimized: false,
|
|
28
29
|
previousElementOnFocusBeforeModalOpen: null,
|
|
29
30
|
outsideOperatingHours: false,
|
|
30
|
-
shouldShowPostChat: false,
|
|
31
31
|
preChatResponseEmail: "",
|
|
32
32
|
isAudioMuted: null,
|
|
33
33
|
newMessage: false,
|
|
@@ -235,6 +235,14 @@ export const createReducer = () => {
|
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
+
case LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID:
|
|
239
|
+
return { ...state,
|
|
240
|
+
domainStates: { ...state.domainStates,
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
|
+
widgetInstanceId: action.payload
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
238
246
|
default:
|
|
239
247
|
return state;
|
|
240
248
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConversationState } from "../contexts/common/ConversationState";
|
|
2
2
|
export const shouldShowChatButton = state => {
|
|
3
|
-
return state.appStates.isMinimized || state.appStates.conversationState === ConversationState.Closed;
|
|
3
|
+
return (state.appStates.isMinimized || state.appStates.conversationState === ConversationState.Closed) && state.appStates.skipChatButtonRendering == false; // Do not show chat button in case of popout
|
|
4
4
|
};
|
|
5
5
|
export const shouldShowProactiveChatPane = state => {
|
|
6
6
|
return !state.appStates.isMinimized && state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
@@ -18,13 +18,13 @@ export const shouldShowWebChatContainer = state => {
|
|
|
18
18
|
return state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.InActive;
|
|
19
19
|
};
|
|
20
20
|
export const shouldShowLoadingPane = state => {
|
|
21
|
-
return !state.appStates.isMinimized &&
|
|
21
|
+
return !state.appStates.isMinimized && state.appStates.conversationState === ConversationState.Loading;
|
|
22
22
|
};
|
|
23
23
|
export const shouldShowReconnectChatPane = state => {
|
|
24
24
|
return !state.appStates.isMinimized && state.appStates.conversationState === ConversationState.ReconnectChat;
|
|
25
25
|
};
|
|
26
26
|
export const shouldShowPostChatLoadingPane = state => {
|
|
27
|
-
return !state.appStates.isMinimized && state.appStates.
|
|
27
|
+
return !state.appStates.isMinimized && state.appStates.conversationState === ConversationState.PostchatLoading;
|
|
28
28
|
};
|
|
29
29
|
export const shouldShowOutOfOfficeHoursPane = state => {
|
|
30
30
|
return !state.appStates.isMinimized && state.appStates.conversationState === ConversationState.OutOfOffice;
|