@microsoft/omnichannel-chat-widget 0.1.0-main.fb426ed → 0.1.0-main.fdf1fdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/lib/cjs/common/Constants.js +18 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +21 -3
- package/lib/cjs/common/utils.js +75 -2
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -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/authHelper.js +52 -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 +13 -3
- package/lib/cjs/components/livechatwidget/common/endChat.js +68 -22
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +20 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
- 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 +163 -80
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +231 -91
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -7
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +91 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -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/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +3 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/cjs/contexts/createReducer.js +16 -0
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/esm/common/Constants.js +18 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +21 -3
- package/lib/esm/common/utils.js +52 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
- 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/authHelper.js +39 -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 +13 -3
- package/lib/esm/components/livechatwidget/common/endChat.js +65 -22
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +19 -5
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +56 -37
- 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 +157 -82
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +223 -94
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +82 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -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/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +3 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/esm/contexts/createReducer.js +16 -0
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/types/common/Constants.d.ts +9 -1
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +21 -4
- package/lib/types/common/utils.d.ts +7 -1
- 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/authHelper.d.ts +4 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
- 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/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +4 -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 } from "../../../common/utils";
|
|
7
|
+
import { createTimer, getBroadcastChannelName, 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$controlProps14, _props$controlProps15, _props$componentOverr, _props$controlProps16, _props$componentOverr2, _props$controlProps17, _props$componentOverr3, _props$controlProps18, _props$componentOverr4, _props$controlProps19, _props$componentOverr5, _props$controlProps20, _props$componentOverr6, _props$controlProps21, _props$componentOverr7, _props$controlProps22, _props$controlProps23, _props$componentOverr8, _props$controlProps24, _props$componentOverr9, _props$controlProps25, _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)
|
|
@@ -68,9 +69,34 @@ export const LiveChatWidgetStateful = props => {
|
|
|
68
69
|
TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
|
|
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);
|
|
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
|
+
|
|
71
95
|
useEffect(() => {
|
|
72
|
-
var _props$controlProps2, _props$controlProps3, _props$
|
|
96
|
+
var _chatSDK$omnichannelC, _props$controlProps2, _props$controlProps3, _props$controlProps4, _props$controlProps5, _props$controlProps7, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps8, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
|
|
73
97
|
|
|
98
|
+
const broadcastServiceChannelName = getBroadcastChannelName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.widgetId, ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
|
|
99
|
+
BroadcastServiceInitialize(broadcastServiceChannelName);
|
|
74
100
|
registerTelemetryLoggers(props, dispatch);
|
|
75
101
|
createInternetConnectionChangeHandler();
|
|
76
102
|
DataStoreManager.clientDataStore = props.contextDataStore ?? undefined;
|
|
@@ -80,49 +106,79 @@ export const LiveChatWidgetStateful = props => {
|
|
|
80
106
|
});
|
|
81
107
|
dispatch({
|
|
82
108
|
type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
|
|
83
|
-
payload: ((_props$
|
|
109
|
+
payload: ((_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.skipChatButtonRendering) || false
|
|
84
110
|
});
|
|
85
111
|
dispatch({
|
|
86
112
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
87
113
|
payload: false
|
|
88
114
|
});
|
|
115
|
+
|
|
116
|
+
if ((_props$controlProps4 = props.controlProps) !== null && _props$controlProps4 !== void 0 && _props$controlProps4.widgetInstanceId && !isNullOrEmptyString((_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.widgetInstanceId)) {
|
|
117
|
+
var _props$controlProps6;
|
|
118
|
+
|
|
119
|
+
dispatch({
|
|
120
|
+
type: LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
|
|
121
|
+
payload: (_props$controlProps6 = props.controlProps) === null || _props$controlProps6 === void 0 ? void 0 : _props$controlProps6.widgetInstanceId
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
89
125
|
initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
90
126
|
sdkCreated && dispatch({
|
|
91
127
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
92
128
|
payload: true
|
|
93
129
|
});
|
|
130
|
+
}); // Initialize global dir
|
|
131
|
+
|
|
132
|
+
const globalDir = ((_props$controlProps7 = props.controlProps) === null || _props$controlProps7 === void 0 ? void 0 : _props$controlProps7.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);
|
|
133
|
+
dispatch({
|
|
134
|
+
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
135
|
+
payload: globalDir
|
|
94
136
|
});
|
|
95
137
|
|
|
96
|
-
if (!((_props$
|
|
97
|
-
var _props$reconnectChatP2;
|
|
138
|
+
if (!((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
139
|
+
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
140
|
+
|
|
141
|
+
startUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, initStartChat);
|
|
142
|
+
return;
|
|
143
|
+
} // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
145
|
|
|
99
|
-
|
|
100
|
-
|
|
146
|
+
|
|
147
|
+
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;
|
|
148
|
+
|
|
149
|
+
if (isAuthenticationSettingsEnabled === false) {
|
|
150
|
+
var _state$domainStates;
|
|
151
|
+
|
|
152
|
+
if (!isUndefinedOrEmpty((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === ConversationState.Active) {
|
|
153
|
+
var _state$domainStates2;
|
|
154
|
+
|
|
155
|
+
const optionalParams = {
|
|
156
|
+
liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
|
|
157
|
+
};
|
|
158
|
+
initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
} // All other case should show start chat button, skipChatButtonRendering will take care of it own
|
|
101
162
|
|
|
102
163
|
|
|
103
|
-
const globalDir = ((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.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);
|
|
104
164
|
dispatch({
|
|
105
|
-
type: LiveChatWidgetActionType.
|
|
106
|
-
payload:
|
|
165
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
166
|
+
payload: ConversationState.Closed
|
|
107
167
|
});
|
|
168
|
+
}, []); // useEffect for when skip chat button rendering
|
|
108
169
|
|
|
109
|
-
if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
|
|
110
|
-
var _state$domainStates2;
|
|
111
|
-
|
|
112
|
-
const optionalParams = {
|
|
113
|
-
liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
|
|
114
|
-
};
|
|
115
|
-
initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
116
|
-
}
|
|
117
|
-
}, []);
|
|
118
170
|
useEffect(() => {
|
|
119
171
|
if (state.appStates.skipChatButtonRendering) {
|
|
120
|
-
var _props$
|
|
172
|
+
var _props$reconnectChatP4;
|
|
173
|
+
|
|
174
|
+
BroadcastService.postMessage({
|
|
175
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
176
|
+
});
|
|
121
177
|
|
|
122
|
-
if ((_props$
|
|
123
|
-
var _props$
|
|
178
|
+
if ((_props$reconnectChatP4 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP4 !== void 0 && _props$reconnectChatP4.reconnectId && !state.appStates.reconnectId) {
|
|
179
|
+
var _props$reconnectChatP5, _props$reconnectChatP6, _props$reconnectChatP7;
|
|
124
180
|
|
|
125
|
-
handleUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, (_props$
|
|
181
|
+
handleUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.isReconnectEnabled, (_props$reconnectChatP6 = props.reconnectChatPaneProps) === null || _props$reconnectChatP6 === void 0 ? void 0 : _props$reconnectChatP6.reconnectId, initStartChat, (_props$reconnectChatP7 = props.reconnectChatPaneProps) === null || _props$reconnectChatP7 === void 0 ? void 0 : _props$reconnectChatP7.redirectInSameWindow);
|
|
126
182
|
} else {
|
|
127
183
|
getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
|
|
128
184
|
if (authReconnectId && !state.appStates.reconnectId) {
|
|
@@ -139,17 +195,16 @@ export const LiveChatWidgetStateful = props => {
|
|
|
139
195
|
eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
|
|
140
196
|
};
|
|
141
197
|
BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
|
|
142
|
-
dispatch
|
|
143
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
144
|
-
payload: ConversationState.Loading
|
|
145
|
-
});
|
|
146
|
-
initStartChat(chatSDK, dispatch, setAdapter);
|
|
198
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter);
|
|
147
199
|
}
|
|
148
200
|
});
|
|
149
201
|
}
|
|
150
202
|
}
|
|
151
|
-
}, [state.appStates.skipChatButtonRendering]);
|
|
203
|
+
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
204
|
+
|
|
152
205
|
useEffect(() => {
|
|
206
|
+
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$controlProps11;
|
|
207
|
+
|
|
153
208
|
// Add the custom context on receiving the SetCustomContext event
|
|
154
209
|
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
155
210
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -161,13 +216,13 @@ export const LiveChatWidgetStateful = props => {
|
|
|
161
216
|
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
162
217
|
});
|
|
163
218
|
});
|
|
164
|
-
BroadcastService.getMessageByEventName(
|
|
219
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
|
|
165
220
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
166
221
|
Event: TelemetryEvent.StartProactiveChatEventReceived,
|
|
167
222
|
Description: "Start proactive chat event received."
|
|
168
223
|
});
|
|
169
224
|
|
|
170
|
-
if (canStartProactiveChat.current) {
|
|
225
|
+
if (canStartProactiveChat.current === true) {
|
|
171
226
|
var _msg$payload, _msg$payload2, _msg$payload3;
|
|
172
227
|
|
|
173
228
|
startProactiveChat(dispatch, msg === null || msg === void 0 ? void 0 : (_msg$payload = msg.payload) === null || _msg$payload === void 0 ? void 0 : _msg$payload.notificationConfig, msg === null || msg === void 0 ? void 0 : (_msg$payload2 = msg.payload) === null || _msg$payload2 === void 0 ? void 0 : _msg$payload2.enablePreChat, msg === null || msg === void 0 ? void 0 : (_msg$payload3 = msg.payload) === null || _msg$payload3 === void 0 ? void 0 : _msg$payload3.inNewWindow);
|
|
@@ -177,71 +232,127 @@ export const LiveChatWidgetStateful = props => {
|
|
|
177
232
|
Description: "Start proactive chat method called, when chat was already triggered."
|
|
178
233
|
});
|
|
179
234
|
}
|
|
180
|
-
}); //
|
|
235
|
+
}); // Start chat from SDK Event
|
|
236
|
+
|
|
237
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
238
|
+
var _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$controlProps9;
|
|
181
239
|
|
|
182
|
-
BroadcastService.getMessageByEventName("StartChat").subscribe(() => {
|
|
183
240
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
184
241
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
185
242
|
Description: "Start chat event received."
|
|
186
243
|
});
|
|
244
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.widgetInstanceId) ?? ""); // Chat not found in cache
|
|
245
|
+
|
|
246
|
+
if (persistedState === undefined) {
|
|
247
|
+
BroadcastService.postMessage({
|
|
248
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
249
|
+
});
|
|
250
|
+
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
251
|
+
return;
|
|
252
|
+
} // Chat exist in cache
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
if (persistedState) {
|
|
256
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
|
|
257
|
+
|
|
258
|
+
// Only initiate new chat if widget state in cache in one of the followings
|
|
259
|
+
if (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat) {
|
|
260
|
+
BroadcastService.postMessage({
|
|
261
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
262
|
+
});
|
|
263
|
+
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
264
|
+
return;
|
|
265
|
+
} // If minimized, maximize the chat
|
|
266
|
+
|
|
187
267
|
|
|
188
|
-
if (state.appStates.isMinimized) {
|
|
189
268
|
dispatch({
|
|
190
269
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
191
270
|
payload: false
|
|
192
271
|
});
|
|
193
|
-
|
|
194
|
-
|
|
272
|
+
BroadcastService.postMessage({
|
|
273
|
+
eventName: BroadcastEvent.MaximizeChat,
|
|
274
|
+
payload: {
|
|
275
|
+
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,
|
|
276
|
+
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
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}); // End chat
|
|
281
|
+
|
|
282
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
283
|
+
if (state.appStates.skipChatButtonRendering !== true) {
|
|
284
|
+
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$controlProps10;
|
|
285
|
+
|
|
286
|
+
// This is to ensure to get latest state from cache in multitab
|
|
287
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC5 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC5 === void 0 ? void 0 : _chatSDK$omnichannelC5.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
|
|
288
|
+
|
|
289
|
+
if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
|
|
290
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
291
|
+
} else {
|
|
292
|
+
const skipEndChatSDK = true;
|
|
293
|
+
const skipCloseChat = false;
|
|
294
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
295
|
+
}
|
|
195
296
|
}
|
|
196
|
-
}); // end chat from SDK Event
|
|
197
297
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Event: TelemetryEvent.EndChatEventReceived,
|
|
201
|
-
Description: "End chat event received."
|
|
298
|
+
BroadcastService.postMessage({
|
|
299
|
+
eventName: BroadcastEvent.CloseChat
|
|
202
300
|
});
|
|
301
|
+
}); // End chat on browser unload
|
|
203
302
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
disposeTelemetryLoggers();
|
|
214
|
-
});
|
|
303
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
|
|
304
|
+
initiateEndChatOnBrowserUnload();
|
|
305
|
+
}); // Listen to end chat event from other tabs
|
|
306
|
+
|
|
307
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC6 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC6 === void 0 ? void 0 : _chatSDK$omnichannelC6.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC7 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC7 === void 0 ? void 0 : _chatSDK$omnichannelC7.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
|
|
308
|
+
BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
309
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
310
|
+
return;
|
|
311
|
+
}); // When conversation ended by agent
|
|
215
312
|
|
|
216
313
|
if (state.appStates.conversationEndedByAgent) {
|
|
217
314
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
218
|
-
}
|
|
219
|
-
}, []);
|
|
220
|
-
useEffect(() => {
|
|
221
|
-
canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
|
|
222
|
-
canEndChat.current = state.appStates.conversationState === ConversationState.Active;
|
|
223
|
-
|
|
224
|
-
if (state.appStates.conversationState === ConversationState.Active) {
|
|
225
|
-
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
226
|
-
BroadcastService.postMessage({
|
|
227
|
-
eventName: BroadcastEvent.NewMessageNotification
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
} // Track the message count
|
|
315
|
+
} //Listen to WidgetSize, used for minimize to maximize
|
|
231
316
|
|
|
232
317
|
|
|
318
|
+
BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
|
|
319
|
+
dispatch({
|
|
320
|
+
type: LiveChatWidgetActionType.SET_WIDGET_SIZE,
|
|
321
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
return () => {
|
|
325
|
+
disposeTelemetryLoggers();
|
|
326
|
+
};
|
|
327
|
+
}, []);
|
|
328
|
+
useEffect(() => {
|
|
329
|
+
// On new message
|
|
233
330
|
if (state.appStates.conversationState === ConversationState.Active) {
|
|
234
331
|
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
332
|
+
// Track the message count
|
|
235
333
|
currentMessageCountRef.current++;
|
|
236
334
|
dispatch({
|
|
237
335
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
238
336
|
payload: currentMessageCountRef.current + 1
|
|
337
|
+
}); // New message notification
|
|
338
|
+
|
|
339
|
+
BroadcastService.postMessage({
|
|
340
|
+
eventName: BroadcastEvent.NewMessageNotification
|
|
239
341
|
});
|
|
240
342
|
});
|
|
241
343
|
}
|
|
242
|
-
}, [state.appStates.conversationState]);
|
|
344
|
+
}, [state.appStates.conversationState]);
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
|
|
347
|
+
}, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
|
|
243
348
|
|
|
244
349
|
useEffect(() => {
|
|
350
|
+
if (state.appStates.isMinimized) {
|
|
351
|
+
ActivityStreamHandler.cork();
|
|
352
|
+
} else {
|
|
353
|
+
setTimeout(() => ActivityStreamHandler.uncork(), 500);
|
|
354
|
+
}
|
|
355
|
+
|
|
245
356
|
currentMessageCountRef.current = -1;
|
|
246
357
|
dispatch({
|
|
247
358
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
@@ -256,7 +367,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
256
367
|
}, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
|
|
257
368
|
|
|
258
369
|
useEffect(() => {
|
|
259
|
-
if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
|
|
370
|
+
if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
|
|
260
371
|
const customEvent = {
|
|
261
372
|
elementType: ElementType.Custom,
|
|
262
373
|
eventName: BroadcastEvent.UnreadMessageCount,
|
|
@@ -271,13 +382,40 @@ export const LiveChatWidgetStateful = props => {
|
|
|
271
382
|
setWebChatStyles({ ...webChatStyles,
|
|
272
383
|
...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
|
|
273
384
|
});
|
|
274
|
-
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
|
|
385
|
+
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
|
|
386
|
+
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
var _props$controlProps12, _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$controlProps13;
|
|
389
|
+
|
|
390
|
+
// Only activate these windows events when conversation state is active and chat widget is in popout mode
|
|
391
|
+
// Ghost chat scenarios
|
|
392
|
+
if (state.appStates.conversationState === ConversationState.Active && ((_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.skipChatButtonRendering) === true) {
|
|
393
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
394
|
+
window.onbeforeunload = function () {
|
|
395
|
+
const prompt = Constants.BrowserUnloadConfirmationMessage;
|
|
396
|
+
return prompt;
|
|
397
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
window.onunload = function () {
|
|
401
|
+
initiateEndChatOnBrowserUnload();
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
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, (props === null || props === void 0 ? void 0 : (_props$controlProps13 = props.controlProps) === null || _props$controlProps13 === void 0 ? void 0 : _props$controlProps13.widgetInstanceId) ?? "");
|
|
406
|
+
const chatWidgetStateChangeEvent = {
|
|
407
|
+
eventName: widgetStateEventName,
|
|
408
|
+
payload: { ...state
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
412
|
+
}, [state]);
|
|
275
413
|
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
276
414
|
|
|
277
415
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
278
416
|
|
|
279
417
|
|
|
280
|
-
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
418
|
+
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
|
|
281
419
|
|
|
282
420
|
|
|
283
421
|
const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
@@ -285,18 +423,9 @@ export const LiveChatWidgetStateful = props => {
|
|
|
285
423
|
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
286
424
|
|
|
287
425
|
|
|
288
|
-
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
289
|
-
|
|
290
|
-
const confirmationPaneProps = initConfirmationPropsComposer(props); // publish chat widget state
|
|
426
|
+
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
291
427
|
|
|
292
|
-
|
|
293
|
-
const chatWidgetStateChangeEvent = {
|
|
294
|
-
eventName: BroadcastEvent.ChatWidgetStateChanged,
|
|
295
|
-
payload: { ...state
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
299
|
-
}, [state]);
|
|
428
|
+
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
300
429
|
return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
301
430
|
styleOptions: webChatStyles,
|
|
302
431
|
directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
|
|
@@ -304,28 +433,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
304
433
|
id: widgetElementId,
|
|
305
434
|
styles: generalStyles,
|
|
306
435
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
307
|
-
}, !((_props$
|
|
436
|
+
}, !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideChatButton) && !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.skipChatButtonRendering) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
|
|
308
437
|
buttonProps: props.chatButtonProps,
|
|
309
438
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
310
439
|
startChat: prepareStartChatRelay
|
|
311
|
-
})), !((_props$
|
|
440
|
+
})), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
|
|
312
441
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
313
442
|
startChat: prepareStartChatRelay
|
|
314
|
-
})), !((_props$
|
|
443
|
+
})), !((_props$controlProps17 = props.controlProps) !== null && _props$controlProps17 !== void 0 && _props$controlProps17.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
|
|
315
444
|
headerProps: props.headerProps,
|
|
316
445
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
317
446
|
endChat: endChatRelay
|
|
318
|
-
})), !((_props$
|
|
447
|
+
})), !((_props$controlProps18 = props.controlProps) !== null && _props$controlProps18 !== void 0 && _props$controlProps18.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$controlProps19 = props.controlProps) !== null && _props$controlProps19 !== void 0 && _props$controlProps19.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$controlProps20 = props.controlProps) !== null && _props$controlProps20 !== void 0 && _props$controlProps20.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
|
|
319
448
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
320
449
|
initStartChat: initStartChatRelay
|
|
321
|
-
})), !((_props$
|
|
450
|
+
})), !((_props$controlProps21 = props.controlProps) !== null && _props$controlProps21 !== void 0 && _props$controlProps21.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
|
|
322
451
|
surveyProps: props.preChatSurveyPaneProps,
|
|
323
452
|
initStartChat: initStartChatRelay
|
|
324
|
-
})), !((_props$
|
|
453
|
+
})), !((_props$controlProps22 = props.controlProps) !== null && _props$controlProps22 !== void 0 && _props$controlProps22.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
325
454
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
326
|
-
}, props.callingContainerProps)), !((_props$
|
|
455
|
+
}, props.callingContainerProps)), !((_props$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.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$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
|
|
327
456
|
setPostChatContext: setPostChatContextRelay,
|
|
328
457
|
prepareEndChat: prepareEndChatRelay
|
|
329
|
-
}))), !((_props$
|
|
458
|
+
}))), !((_props$controlProps25 = props.controlProps) !== null && _props$controlProps25 !== void 0 && _props$controlProps25.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
|
|
330
459
|
};
|
|
331
460
|
export default LiveChatWidgetStateful;
|
|
@@ -1,9 +1,8 @@
|
|
|
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, 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,13 +66,12 @@ export const PreChatSurveyPaneStateful = props => {
|
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
try {
|
|
70
|
-
var
|
|
69
|
+
var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
|
|
71
70
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
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
|
|
75
73
|
|
|
76
|
-
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) {
|
|
77
75
|
var _persistedState$domai2;
|
|
78
76
|
|
|
79
77
|
optionalParams = {
|
|
@@ -24,6 +24,14 @@ export const ProactiveChatPaneStateful = props => {
|
|
|
24
24
|
const handleProactiveChatInviteTimeout = () => {
|
|
25
25
|
if (!timeoutRemoved) {
|
|
26
26
|
setTimeoutRemoved(true);
|
|
27
|
+
dispatch({
|
|
28
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
29
|
+
payload: {
|
|
30
|
+
proactiveChatBodyTitle: "",
|
|
31
|
+
proactiveChatEnablePrechat: false,
|
|
32
|
+
proactiveChatInNewWindow: false
|
|
33
|
+
}
|
|
34
|
+
});
|
|
27
35
|
dispatch({
|
|
28
36
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
29
37
|
payload: ConversationState.Closed
|
|
@@ -81,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
|
|
|
81
89
|
Event: TelemetryEvent.ProactiveChatClosed,
|
|
82
90
|
Description: "Proactive chat closed."
|
|
83
91
|
});
|
|
92
|
+
dispatch({
|
|
93
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
94
|
+
payload: {
|
|
95
|
+
proactiveChatBodyTitle: "",
|
|
96
|
+
proactiveChatEnablePrechat: false,
|
|
97
|
+
proactiveChatInNewWindow: false
|
|
98
|
+
}
|
|
99
|
+
});
|
|
84
100
|
dispatch({
|
|
85
101
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
86
102
|
payload: ConversationState.Closed
|
|
87
103
|
});
|
|
88
104
|
},
|
|
89
105
|
...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
|
|
90
|
-
bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle
|
|
106
|
+
bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ? state.appStates.proactiveChatStates.proactiveChatBodyTitle : proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText
|
|
91
107
|
};
|
|
92
108
|
useEffect(() => {
|
|
93
109
|
setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));
|