@microsoft/omnichannel-chat-widget 0.1.0-main.52da005 → 0.1.0-main.52fa2fc
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 +7 -34
- package/lib/cjs/common/Constants.js +12 -3
- package/lib/cjs/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/cjs/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/cjs/common/utils.js +23 -2
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +139 -0
- package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +36 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +66 -14
- package/lib/cjs/components/livechatwidget/common/endChat.js +43 -63
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +11 -49
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -7
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +83 -64
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +91 -45
- package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +7 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/cjs/contexts/common/ConversationEndEntity.js +12 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +11 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/cjs/contexts/createReducer.js +36 -2
- package/lib/cjs/hooks/useDebounce.js +28 -0
- package/lib/cjs/hooks/useWindowDimensions.js +30 -0
- package/lib/cjs/plugins/newMessageEventHandler.js +14 -0
- package/lib/esm/common/Constants.js +10 -2
- package/lib/esm/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/esm/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/esm/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/esm/common/utils.js +20 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +134 -0
- package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +30 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +66 -14
- package/lib/esm/components/livechatwidget/common/endChat.js +45 -65
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -51
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +12 -7
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +83 -64
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +92 -46
- package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +5 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/esm/contexts/common/ConversationEndEntity.js +5 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +11 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/esm/contexts/createReducer.js +36 -2
- package/lib/esm/hooks/useDebounce.js +22 -0
- package/lib/esm/hooks/useWindowDimensions.js +23 -0
- package/lib/esm/plugins/newMessageEventHandler.js +14 -0
- package/lib/types/common/Constants.d.ts +9 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +1 -1
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +31 -6
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +1 -0
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +4 -0
- package/lib/types/common/utils.d.ts +1 -0
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +0 -7
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +6 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -3
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.d.ts +1 -1
- package/lib/types/contexts/common/ConversationEndEntity.d.ts +4 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +6 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -7
- package/lib/types/hooks/useDebounce.d.ts +3 -0
- package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
- package/package.json +3 -3
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
|
|
2
1
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
|
|
3
|
+
import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
|
|
4
|
+
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
5
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
6
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
3
7
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
8
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
9
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
@@ -8,13 +12,9 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
|
8
12
|
import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
9
13
|
import { createAdapter } from "./createAdapter";
|
|
10
14
|
import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
|
|
11
|
-
import {
|
|
15
|
+
import { handleChatReconnect } from "./reconnectChatHelper";
|
|
12
16
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
13
17
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
14
|
-
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
15
|
-
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
16
|
-
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
17
|
-
import { handleChatReconnect } from "./reconnectChatHelper";
|
|
18
18
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
let optionalParams = {};
|
|
@@ -27,10 +27,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
27
27
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
28
28
|
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
30
|
+
// reconnect > chat from cache
|
|
34
31
|
await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
35
32
|
|
|
36
33
|
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
@@ -38,6 +35,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
40
37
|
|
|
38
|
+
// Can connect to existing chat session
|
|
39
|
+
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
41
43
|
// Setting Proactive chat settings
|
|
42
44
|
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
43
45
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
|
|
@@ -78,11 +80,19 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
78
80
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
79
81
|
payload: ConversationState.Loading
|
|
80
82
|
});
|
|
81
|
-
|
|
83
|
+
const optionalParams = {
|
|
84
|
+
isProactiveChat
|
|
85
|
+
};
|
|
86
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
82
87
|
};
|
|
83
88
|
|
|
84
89
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
const initStartChat = async (chatSDK,
|
|
90
|
+
const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
|
|
91
|
+
var _props$controlProps2;
|
|
92
|
+
let isStartChatSuccessful = false;
|
|
93
|
+
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
94
|
+
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
95
|
+
const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
|
|
86
96
|
try {
|
|
87
97
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
88
98
|
//Start widget load timer
|
|
@@ -96,10 +106,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
96
106
|
// set auth token to chat sdk before start chat
|
|
97
107
|
const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
98
108
|
if (!authSuccess) {
|
|
109
|
+
dispatch({
|
|
110
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
111
|
+
payload: ConversationState.Closed
|
|
112
|
+
});
|
|
99
113
|
return;
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
|
-
let isStartChatSuccessful = false;
|
|
103
116
|
|
|
104
117
|
//Check if chat retrieved from cache
|
|
105
118
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -113,10 +126,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
113
126
|
});
|
|
114
127
|
}
|
|
115
128
|
try {
|
|
129
|
+
var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
|
|
116
130
|
// Set custom context params
|
|
117
131
|
setCustomContextParams(chatSDK);
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
const defaultOptionalParams = {
|
|
133
|
+
sendDefaultInitContext: true,
|
|
134
|
+
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
135
|
+
portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
|
|
136
|
+
};
|
|
137
|
+
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
138
|
+
await chatSDK.startChat(startChatOptionalParams);
|
|
120
139
|
isStartChatSuccessful = true;
|
|
121
140
|
} catch (error) {
|
|
122
141
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -126,12 +145,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
126
145
|
}
|
|
127
146
|
});
|
|
128
147
|
isStartChatSuccessful = false;
|
|
129
|
-
// Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
130
|
-
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
131
|
-
dispatch({
|
|
132
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
133
|
-
payload: ConversationState.Closed
|
|
134
|
-
});
|
|
135
148
|
return;
|
|
136
149
|
}
|
|
137
150
|
|
|
@@ -160,12 +173,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
160
173
|
payload: liveChatContext
|
|
161
174
|
});
|
|
162
175
|
|
|
163
|
-
// Set post chat context in state, no survey load
|
|
164
|
-
setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
165
|
-
|
|
166
|
-
// Updating chat session detail for telemetry
|
|
167
|
-
await updateSessionDataForTelemetry(chatSDK, dispatch);
|
|
168
|
-
|
|
169
176
|
// Set app state to Active
|
|
170
177
|
if (isStartChatSuccessful) {
|
|
171
178
|
ActivityStreamHandler.uncork();
|
|
@@ -184,6 +191,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
184
191
|
Description: "Widget load complete",
|
|
185
192
|
ElapsedTimeInMilliseconds: TelemetryTimers === null || TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
|
|
186
193
|
});
|
|
194
|
+
|
|
195
|
+
// Set post chat context in state, no survey load
|
|
196
|
+
setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
197
|
+
|
|
198
|
+
// Updating chat session detail for telemetry
|
|
199
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch);
|
|
187
200
|
} catch (ex) {
|
|
188
201
|
TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
|
|
189
202
|
Event: TelemetryEvent.WidgetLoadFailed,
|
|
@@ -204,33 +217,56 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
204
217
|
});
|
|
205
218
|
return;
|
|
206
219
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
if (!hideErrorUIPane) {
|
|
221
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
222
|
+
dispatch({
|
|
223
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
224
|
+
payload: true
|
|
225
|
+
});
|
|
226
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
227
|
+
Event: TelemetryEvent.ErrorUIPaneLoaded,
|
|
228
|
+
Description: "Error UI Pane Loaded"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
212
231
|
// Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
|
|
213
232
|
dispatch({
|
|
214
233
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
215
234
|
payload: ConversationState.Loading
|
|
216
235
|
});
|
|
236
|
+
|
|
237
|
+
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
238
|
+
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
239
|
+
if (isStartChatSuccessful === true) {
|
|
240
|
+
await forceEndChat(chatSDK);
|
|
241
|
+
}
|
|
217
242
|
} finally {
|
|
218
243
|
optionalParams = {};
|
|
219
244
|
widgetInstanceId = "";
|
|
220
245
|
}
|
|
221
246
|
};
|
|
222
247
|
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
+
const forceEndChat = async chatSDK => {
|
|
250
|
+
TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
|
|
251
|
+
Event: TelemetryEvent.WidgetLoadFailed,
|
|
252
|
+
ExceptionDetails: {
|
|
253
|
+
Exception: "SessionInit was successful, but widget load failed."
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
|
|
257
|
+
};
|
|
258
|
+
|
|
223
259
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
260
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
225
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$
|
|
261
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
|
|
226
262
|
// By pass this function in case of popout chat
|
|
227
263
|
if (state.appStates.hideStartChatButton === true) {
|
|
228
264
|
return false;
|
|
229
265
|
}
|
|
230
|
-
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$
|
|
266
|
+
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$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
|
|
231
267
|
|
|
232
268
|
//Connect to only active chat session
|
|
233
|
-
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext)
|
|
269
|
+
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext)) {
|
|
234
270
|
var _persistedState$domai7;
|
|
235
271
|
dispatch({
|
|
236
272
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
@@ -239,7 +275,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
239
275
|
const optionalParams = {
|
|
240
276
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
241
277
|
};
|
|
242
|
-
await initStartChat(chatSDK,
|
|
278
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
243
279
|
return true;
|
|
244
280
|
} else {
|
|
245
281
|
return false;
|
|
@@ -270,39 +306,18 @@ const setCustomContextParams = chatSDK => {
|
|
|
270
306
|
};
|
|
271
307
|
|
|
272
308
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const authClientFunction = getAuthClientFunction(props.chatConfig);
|
|
277
|
-
if (authClientFunction) {
|
|
278
|
-
// set auth token to chat sdk before start chat
|
|
279
|
-
const authSuccess = await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
|
|
280
|
-
if (!authSuccess) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return true;
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
|
-
const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
|
|
309
|
+
const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
|
|
310
|
+
var _state$domainStates, _state$domainStates$l;
|
|
311
|
+
const requestId = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
|
|
291
312
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
313
|
let conversationDetails = undefined;
|
|
293
314
|
|
|
294
|
-
//
|
|
315
|
+
//Preserve old requestId
|
|
316
|
+
const oldRequestId = chatSDK.requestId ?? "";
|
|
295
317
|
dispatch({
|
|
296
|
-
type: LiveChatWidgetActionType.
|
|
297
|
-
payload:
|
|
318
|
+
type: LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
319
|
+
payload: oldRequestId
|
|
298
320
|
});
|
|
299
|
-
const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
|
|
300
|
-
if (!authSucceed) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
//Preserve old requestId
|
|
305
|
-
const oldRequestId = chatSDK.requestId;
|
|
306
321
|
try {
|
|
307
322
|
chatSDK.requestId = requestId;
|
|
308
323
|
conversationDetails = await chatSDK.getConversationDetails();
|
|
@@ -311,6 +326,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
|
|
|
311
326
|
return false;
|
|
312
327
|
}
|
|
313
328
|
if (conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
329
|
+
dispatch({
|
|
330
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
331
|
+
payload: undefined
|
|
332
|
+
});
|
|
314
333
|
chatSDK.requestId = oldRequestId;
|
|
315
334
|
return false;
|
|
316
335
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
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
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
-
import { BroadcastService,
|
|
3
|
+
import { BroadcastService, BroadcastServiceInitialize, decodeComponentString } from "@microsoft/omnichannel-chat-components";
|
|
4
4
|
import { Stack } from "@fluentui/react";
|
|
5
5
|
import React, { useEffect, useRef, useState } from "react";
|
|
6
|
-
import { createTimer, getBroadcastChannelName, getLocaleDirection, getStateFromCache, getWidgetCacheId, getWidgetEndChatEventName, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
7
6
|
import { checkIfConversationStillValid, initStartChat, prepareStartChat, setPreChatAndInitiateChat } from "../common/startChat";
|
|
7
|
+
import { createTimer, getBroadcastChannelName, getLocaleDirection, getStateFromCache, getWidgetCacheId, getWidgetEndChatEventName, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
8
|
+
import { endChat, prepareEndChat } from "../common/endChat";
|
|
8
9
|
import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
|
|
10
|
+
import { ActivityStreamHandler } from "../common/ActivityStreamHandler";
|
|
9
11
|
import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
|
|
10
12
|
import ChatButtonStateful from "../../chatbuttonstateful/ChatButtonStateful";
|
|
11
13
|
import { Components } from "botframework-webchat";
|
|
12
14
|
import ConfirmationPaneStateful from "../../confirmationpanestateful/ConfirmationPaneStateful";
|
|
13
15
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
14
16
|
import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
|
|
17
|
+
import { Constants, E2VVOptions } from "../../../common/Constants";
|
|
15
18
|
import { ElementType } from "@microsoft/omnichannel-chat-components";
|
|
16
19
|
import EmailTranscriptPaneStateful from "../../emailtranscriptpanestateful/EmailTranscriptPaneStateful";
|
|
17
20
|
import HeaderStateful from "../../headerstateful/HeaderStateful";
|
|
@@ -28,26 +31,26 @@ import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
|
28
31
|
import WebChatContainerStateful from "../../webchatcontainerstateful/WebChatContainerStateful";
|
|
29
32
|
import { createFooter } from "../common/createFooter";
|
|
30
33
|
import { createInternetConnectionChangeHandler } from "../common/createInternetConnectionChangeHandler";
|
|
34
|
+
import { defaultClientDataStoreProvider } from "../../../common/storage/default/defaultClientDataStoreProvider";
|
|
35
|
+
import { defaultScrollBarProps } from "../common/defaultProps/defaultScrollBarProps";
|
|
31
36
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
32
37
|
import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
|
|
33
|
-
import { endChat, prepareEndChat } from "../common/endChat";
|
|
34
38
|
import { getGeneralStylesForButton } from "../common/getGeneralStylesForButton";
|
|
35
39
|
import { initCallingSdk } from "../common/initCallingSdk";
|
|
36
40
|
import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
|
|
37
41
|
import { initWebChatComposer } from "../common/initWebChatComposer";
|
|
42
|
+
import { registerBroadcastServiceForLocalStorage } from "../../../common/storage/default/defaultCacheManager";
|
|
38
43
|
import { registerTelemetryLoggers } from "../common/registerTelemetryLoggers";
|
|
39
44
|
import { setPostChatContextAndLoadSurvey } from "../common/setPostChatContextAndLoadSurvey";
|
|
40
45
|
import { startProactiveChat } from "../common/startProactiveChat";
|
|
41
46
|
import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
42
47
|
import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
43
48
|
import useChatSDKStore from "../../../hooks/useChatSDKStore";
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import { defaultScrollBarProps } from "../common/defaultProps/defaultScrollBarProps";
|
|
48
|
-
import { E2VVOptions } from "../../../common/Constants";
|
|
49
|
+
import { ConversationEndEntity } from "../../../contexts/common/ConversationEndEntity";
|
|
50
|
+
import { handleAgentEndConversation } from "../common/agentEndConversationHelper";
|
|
51
|
+
import { handleChatReconnect, isReconnectEnabled } from "../common/reconnectChatHelper";
|
|
49
52
|
export const LiveChatWidgetStateful = props => {
|
|
50
|
-
var _props$webChatContain, _props$styleProps, _chatSDK$omnichannelC, _props$controlProps, _props$controlProps2, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$
|
|
53
|
+
var _props$webChatContain, _props$styleProps, _chatSDK$omnichannelC, _props$controlProps, _props$controlProps2, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps15, _props$controlProps16, _props$componentOverr, _props$controlProps17, _props$componentOverr2, _props$controlProps18, _props$componentOverr3, _props$controlProps19, _props$componentOverr4, _props$controlProps20, _props$componentOverr5, _props$controlProps21, _props$componentOverr6, _props$controlProps22, _props$componentOverr7, _props$controlProps23, _props$controlProps24, _props$componentOverr8, _props$controlProps25, _props$componentOverr9, _props$controlProps26, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
|
|
51
54
|
const [state, dispatch] = useChatContextStore();
|
|
52
55
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
56
|
const [adapter, setAdapter] = useChatAdapterStore();
|
|
@@ -95,7 +98,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
95
98
|
};
|
|
96
99
|
} else {
|
|
97
100
|
activeCachedChatExist = false;
|
|
98
|
-
optionalParams =
|
|
101
|
+
optionalParams = {};
|
|
99
102
|
}
|
|
100
103
|
};
|
|
101
104
|
|
|
@@ -105,7 +108,6 @@ export const LiveChatWidgetStateful = props => {
|
|
|
105
108
|
|
|
106
109
|
//Start a chat from cache/reconnectid
|
|
107
110
|
if (activeCachedChatExist === true) {
|
|
108
|
-
var _state$domainStates3, _state$domainStates3$;
|
|
109
111
|
dispatch({
|
|
110
112
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
111
113
|
payload: ConversationState.Loading
|
|
@@ -115,9 +117,17 @@ export const LiveChatWidgetStateful = props => {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
//Check if conversation state is not in wrapup or closed state
|
|
118
|
-
isChatValid = await checkIfConversationStillValid(chatSDK,
|
|
120
|
+
isChatValid = await checkIfConversationStillValid(chatSDK, dispatch, state);
|
|
119
121
|
if (isChatValid === true) {
|
|
120
|
-
|
|
122
|
+
//Check if reconnect enabled
|
|
123
|
+
if (isReconnectEnabled(props.chatConfig) === true) {
|
|
124
|
+
await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
125
|
+
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
126
|
+
if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
121
131
|
return;
|
|
122
132
|
}
|
|
123
133
|
}
|
|
@@ -133,16 +143,22 @@ export const LiveChatWidgetStateful = props => {
|
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
145
|
};
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
|
+
const setupClientDataStore = () => {
|
|
138
149
|
// Add default localStorage support for widget
|
|
139
150
|
if (props.contextDataStore === undefined) {
|
|
140
|
-
var _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$
|
|
141
|
-
|
|
142
|
-
DataStoreManager.clientDataStore = defaultClientDataStoreProvider();
|
|
151
|
+
var _props$controlProps3, _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$controlProps4;
|
|
152
|
+
const cacheTtlInMins = (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.cacheTtlInMins) ?? Constants.CacheTtlInMinutes;
|
|
153
|
+
DataStoreManager.clientDataStore = defaultClientDataStoreProvider(cacheTtlInMins);
|
|
154
|
+
registerBroadcastServiceForLocalStorage(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$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.widgetInstanceId) ?? "", cacheTtlInMins);
|
|
143
155
|
} else {
|
|
144
156
|
DataStoreManager.clientDataStore = props.contextDataStore;
|
|
145
157
|
}
|
|
158
|
+
};
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
var _props$controlProps5, _props$controlProps6, _props$controlProps7, _props$chatConfig, _props$chatConfig$Liv, _props$controlProps9, _props$chatConfig2, _props$chatConfig2$Ch;
|
|
161
|
+
setupClientDataStore();
|
|
146
162
|
registerTelemetryLoggers(props, dispatch);
|
|
147
163
|
createInternetConnectionChangeHandler();
|
|
148
164
|
dispatch({
|
|
@@ -151,17 +167,17 @@ export const LiveChatWidgetStateful = props => {
|
|
|
151
167
|
});
|
|
152
168
|
dispatch({
|
|
153
169
|
type: LiveChatWidgetActionType.SET_START_CHAT_BUTTON_DISPLAY,
|
|
154
|
-
payload: ((_props$
|
|
170
|
+
payload: ((_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.hideStartChatButton) || false
|
|
155
171
|
});
|
|
156
172
|
dispatch({
|
|
157
173
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
158
174
|
payload: false
|
|
159
175
|
});
|
|
160
|
-
if ((_props$
|
|
161
|
-
var _props$
|
|
176
|
+
if ((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.widgetInstanceId && !isNullOrEmptyString((_props$controlProps7 = props.controlProps) === null || _props$controlProps7 === void 0 ? void 0 : _props$controlProps7.widgetInstanceId)) {
|
|
177
|
+
var _props$controlProps8;
|
|
162
178
|
dispatch({
|
|
163
179
|
type: LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
|
|
164
|
-
payload: (_props$
|
|
180
|
+
payload: (_props$controlProps8 = props.controlProps) === null || _props$controlProps8 === void 0 ? void 0 : _props$controlProps8.widgetInstanceId
|
|
165
181
|
});
|
|
166
182
|
}
|
|
167
183
|
if (((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_callingoptions) !== E2VVOptions.NoCalling) {
|
|
@@ -174,7 +190,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
174
190
|
}
|
|
175
191
|
|
|
176
192
|
// Initialize global dir
|
|
177
|
-
const globalDir = ((_props$
|
|
193
|
+
const globalDir = ((_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.dir) ?? getLocaleDirection((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Ch = _props$chatConfig2.ChatWidgetLanguage) === null || _props$chatConfig2$Ch === void 0 ? void 0 : _props$chatConfig2$Ch.msdyn_localeid);
|
|
178
194
|
dispatch({
|
|
179
195
|
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
180
196
|
payload: globalDir
|
|
@@ -200,7 +216,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
200
216
|
|
|
201
217
|
// useEffect for custom context
|
|
202
218
|
useEffect(() => {
|
|
203
|
-
var _chatSDK$omnichannelC8, _chatSDK$omnichannelC9, _props$
|
|
219
|
+
var _chatSDK$omnichannelC8, _chatSDK$omnichannelC9, _props$controlProps13;
|
|
204
220
|
// Add the custom context on receiving the SetCustomContext event
|
|
205
221
|
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
206
222
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -228,14 +244,33 @@ export const LiveChatWidgetStateful = props => {
|
|
|
228
244
|
}
|
|
229
245
|
});
|
|
230
246
|
|
|
247
|
+
// Toggle chat visibility
|
|
248
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.HideChatVisibilityChangeEvent).subscribe(event => {
|
|
249
|
+
var _event$payload;
|
|
250
|
+
if ((event === null || event === void 0 ? void 0 : (_event$payload = event.payload) === null || _event$payload === void 0 ? void 0 : _event$payload.isChatHidden) !== undefined) {
|
|
251
|
+
var _event$payload2, _props$controlProps10;
|
|
252
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
253
|
+
Event: TelemetryEvent.ChatVisibilityChanged,
|
|
254
|
+
Description: "Chat visibility changed to " + (event === null || event === void 0 ? void 0 : (_event$payload2 = event.payload) === null || _event$payload2 === void 0 ? void 0 : _event$payload2.isChatHidden)
|
|
255
|
+
});
|
|
256
|
+
if ((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideStartChatButton) {
|
|
257
|
+
var _event$payload3;
|
|
258
|
+
dispatch({
|
|
259
|
+
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
260
|
+
payload: event === null || event === void 0 ? void 0 : (_event$payload3 = event.payload) === null || _event$payload3 === void 0 ? void 0 : _event$payload3.isChatHidden
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
231
266
|
// Start chat from SDK Event
|
|
232
267
|
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
233
|
-
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$
|
|
268
|
+
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$controlProps11;
|
|
234
269
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
235
270
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
236
271
|
Description: "Start chat event received."
|
|
237
272
|
});
|
|
238
|
-
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$
|
|
273
|
+
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$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
|
|
239
274
|
|
|
240
275
|
// Chat not found in cache
|
|
241
276
|
if (persistedState === undefined) {
|
|
@@ -276,9 +311,9 @@ export const LiveChatWidgetStateful = props => {
|
|
|
276
311
|
// End chat
|
|
277
312
|
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
278
313
|
if (state.appStates.hideStartChatButton === false) {
|
|
279
|
-
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$
|
|
314
|
+
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$controlProps12;
|
|
280
315
|
// This is to ensure to get latest state from cache in multitab
|
|
281
|
-
const persistedState = getStateFromCache(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 === null || props === void 0 ? void 0 : (_props$
|
|
316
|
+
const persistedState = getStateFromCache(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 === null || props === void 0 ? void 0 : (_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.widgetInstanceId) ?? "");
|
|
282
317
|
if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
|
|
283
318
|
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
284
319
|
} else {
|
|
@@ -298,14 +333,14 @@ export const LiveChatWidgetStateful = props => {
|
|
|
298
333
|
});
|
|
299
334
|
|
|
300
335
|
// Listen to end chat event from other tabs
|
|
301
|
-
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC8 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC8 === void 0 ? void 0 : _chatSDK$omnichannelC8.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC9 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC9 === void 0 ? void 0 : _chatSDK$omnichannelC9.widgetId, ((_props$
|
|
336
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC8 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC8 === void 0 ? void 0 : _chatSDK$omnichannelC8.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC9 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC9 === void 0 ? void 0 : _chatSDK$omnichannelC9.widgetId, ((_props$controlProps13 = props.controlProps) === null || _props$controlProps13 === void 0 ? void 0 : _props$controlProps13.widgetInstanceId) ?? "");
|
|
302
337
|
BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
303
338
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
304
339
|
return;
|
|
305
340
|
});
|
|
306
341
|
|
|
307
342
|
// When conversation ended by agent
|
|
308
|
-
if (state.appStates.
|
|
343
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
|
|
309
344
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
310
345
|
}
|
|
311
346
|
|
|
@@ -403,7 +438,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
403
438
|
|
|
404
439
|
// Publish chat widget state
|
|
405
440
|
useEffect(() => {
|
|
406
|
-
var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$
|
|
441
|
+
var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$controlProps14;
|
|
407
442
|
// Only activate these windows events when conversation state is active and chat widget is in popout mode
|
|
408
443
|
// Ghost chat scenarios
|
|
409
444
|
/* COMMENTING THIS CODE FOR PARITY WITH OLD LCW
|
|
@@ -421,7 +456,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
421
456
|
};
|
|
422
457
|
}*/
|
|
423
458
|
|
|
424
|
-
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$
|
|
459
|
+
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$controlProps14 = props.controlProps) === null || _props$controlProps14 === void 0 ? void 0 : _props$controlProps14.widgetInstanceId) ?? "");
|
|
425
460
|
const chatWidgetStateChangeEvent = {
|
|
426
461
|
eventName: widgetStateEventName,
|
|
427
462
|
payload: {
|
|
@@ -430,6 +465,20 @@ export const LiveChatWidgetStateful = props => {
|
|
|
430
465
|
};
|
|
431
466
|
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
432
467
|
}, [state]);
|
|
468
|
+
|
|
469
|
+
// Initiate End chat from a single point
|
|
470
|
+
useEffect(() => {
|
|
471
|
+
if (state.appStates.conversationEndedBy !== undefined) {
|
|
472
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
473
|
+
}
|
|
474
|
+
}, [state.appStates.conversationEndedBy]);
|
|
475
|
+
|
|
476
|
+
// Handle Agent end conversation cases
|
|
477
|
+
useEffect(() => {
|
|
478
|
+
if (state.appStates.conversationEndedByAgentEventReceived) {
|
|
479
|
+
handleAgentEndConversation(props, state, dispatch);
|
|
480
|
+
}
|
|
481
|
+
}, [state.appStates.conversationEndedByAgentEventReceived]);
|
|
433
482
|
const initiateEndChatOnBrowserUnload = () => {
|
|
434
483
|
var _DataStoreManager$cli;
|
|
435
484
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -449,15 +498,13 @@ export const LiveChatWidgetStateful = props => {
|
|
|
449
498
|
eventName: BroadcastEvent.ClosePopoutWindow
|
|
450
499
|
});
|
|
451
500
|
};
|
|
452
|
-
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
501
|
+
const webChatProps = initWebChatComposer(props, chatSDK, setAdapter, state, dispatch, adapter, setWebChatStyles);
|
|
453
502
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
454
503
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
455
504
|
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
|
|
456
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
457
|
-
const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
458
505
|
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
459
506
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
460
|
-
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK,
|
|
507
|
+
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
461
508
|
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
462
509
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
|
|
463
510
|
::-webkit-scrollbar {
|
|
@@ -483,28 +530,27 @@ export const LiveChatWidgetStateful = props => {
|
|
|
483
530
|
id: widgetElementId,
|
|
484
531
|
styles: generalStyles,
|
|
485
532
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
486
|
-
}, !((_props$
|
|
533
|
+
}, !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideChatButton) && !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hideStartChatButton) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
|
|
487
534
|
buttonProps: props.chatButtonProps,
|
|
488
535
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
489
536
|
startChat: prepareStartChatRelay
|
|
490
|
-
})), !((_props$
|
|
537
|
+
})), !((_props$controlProps17 = props.controlProps) !== null && _props$controlProps17 !== void 0 && _props$controlProps17.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
|
|
491
538
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
492
539
|
startChat: prepareStartChatRelay
|
|
493
|
-
})), !((_props$
|
|
540
|
+
})), !((_props$controlProps18 = props.controlProps) !== null && _props$controlProps18 !== void 0 && _props$controlProps18.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
|
|
494
541
|
headerProps: props.headerProps,
|
|
495
542
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
496
543
|
endChat: endChatRelay
|
|
497
|
-
})), !((_props$
|
|
544
|
+
})), !((_props$controlProps19 = props.controlProps) !== null && _props$controlProps19 !== void 0 && _props$controlProps19.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$controlProps20 = props.controlProps) !== null && _props$controlProps20 !== void 0 && _props$controlProps20.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$controlProps21 = props.controlProps) !== null && _props$controlProps21 !== void 0 && _props$controlProps21.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
|
|
498
545
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
499
546
|
initStartChat: initStartChatRelay
|
|
500
|
-
})), !((_props$
|
|
547
|
+
})), !((_props$controlProps22 = props.controlProps) !== null && _props$controlProps22 !== void 0 && _props$controlProps22.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
|
|
501
548
|
surveyProps: props.preChatSurveyPaneProps,
|
|
502
549
|
initStartChat: initStartChatRelay
|
|
503
|
-
})), !((_props$
|
|
550
|
+
})), !((_props$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
504
551
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
505
|
-
}, props.callingContainerProps)), !((_props$
|
|
506
|
-
setPostChatContext: setPostChatContextRelay
|
|
507
|
-
|
|
508
|
-
}))), !((_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)))));
|
|
552
|
+
}, props.callingContainerProps)), !((_props$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.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$controlProps25 = props.controlProps) !== null && _props$controlProps25 !== void 0 && _props$controlProps25.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
|
|
553
|
+
setPostChatContext: setPostChatContextRelay
|
|
554
|
+
}))), !((_props$controlProps26 = props.controlProps) !== null && _props$controlProps26 !== void 0 && _props$controlProps26.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)))));
|
|
509
555
|
};
|
|
510
556
|
export default LiveChatWidgetStateful;
|