@microsoft/omnichannel-chat-widget 0.1.0-main.0c0fd47 → 0.1.0-main.0d1c6e4
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 +14 -10
- 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 +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +70 -59
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +81 -43
- 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/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 +10 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
- package/lib/cjs/contexts/createReducer.js +28 -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 +14 -10
- 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 +6 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +70 -59
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +82 -44
- 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/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 +10 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
- package/lib/esm/contexts/createReducer.js +28 -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/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 +5 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -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 = {};
|
|
@@ -78,11 +78,19 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
78
78
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
79
79
|
payload: ConversationState.Loading
|
|
80
80
|
});
|
|
81
|
-
|
|
81
|
+
const optionalParams = {
|
|
82
|
+
isProactiveChat
|
|
83
|
+
};
|
|
84
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
82
85
|
};
|
|
83
86
|
|
|
84
87
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
const initStartChat = async (chatSDK,
|
|
88
|
+
const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
|
|
89
|
+
var _props$controlProps2;
|
|
90
|
+
let isStartChatSuccessful = false;
|
|
91
|
+
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
92
|
+
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
93
|
+
const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
|
|
86
94
|
try {
|
|
87
95
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
88
96
|
//Start widget load timer
|
|
@@ -96,10 +104,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
96
104
|
// set auth token to chat sdk before start chat
|
|
97
105
|
const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
98
106
|
if (!authSuccess) {
|
|
107
|
+
dispatch({
|
|
108
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
109
|
+
payload: ConversationState.Closed
|
|
110
|
+
});
|
|
99
111
|
return;
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
|
-
let isStartChatSuccessful = false;
|
|
103
114
|
|
|
104
115
|
//Check if chat retrieved from cache
|
|
105
116
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -113,10 +124,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
113
124
|
});
|
|
114
125
|
}
|
|
115
126
|
try {
|
|
127
|
+
var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
|
|
116
128
|
// Set custom context params
|
|
117
129
|
setCustomContextParams(chatSDK);
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
const defaultOptionalParams = {
|
|
131
|
+
sendDefaultInitContext: true,
|
|
132
|
+
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
133
|
+
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
|
|
134
|
+
};
|
|
135
|
+
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
136
|
+
await chatSDK.startChat(startChatOptionalParams);
|
|
120
137
|
isStartChatSuccessful = true;
|
|
121
138
|
} catch (error) {
|
|
122
139
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -126,12 +143,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
126
143
|
}
|
|
127
144
|
});
|
|
128
145
|
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
146
|
return;
|
|
136
147
|
}
|
|
137
148
|
|
|
@@ -160,12 +171,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
160
171
|
payload: liveChatContext
|
|
161
172
|
});
|
|
162
173
|
|
|
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
174
|
// Set app state to Active
|
|
170
175
|
if (isStartChatSuccessful) {
|
|
171
176
|
ActivityStreamHandler.uncork();
|
|
@@ -184,6 +189,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
184
189
|
Description: "Widget load complete",
|
|
185
190
|
ElapsedTimeInMilliseconds: TelemetryTimers === null || TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
|
|
186
191
|
});
|
|
192
|
+
|
|
193
|
+
// Set post chat context in state, no survey load
|
|
194
|
+
setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
195
|
+
|
|
196
|
+
// Updating chat session detail for telemetry
|
|
197
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch);
|
|
187
198
|
} catch (ex) {
|
|
188
199
|
TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
|
|
189
200
|
Event: TelemetryEvent.WidgetLoadFailed,
|
|
@@ -204,33 +215,56 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
204
215
|
});
|
|
205
216
|
return;
|
|
206
217
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
218
|
+
if (!hideErrorUIPane) {
|
|
219
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
220
|
+
dispatch({
|
|
221
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
222
|
+
payload: true
|
|
223
|
+
});
|
|
224
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
225
|
+
Event: TelemetryEvent.ErrorUIPaneLoaded,
|
|
226
|
+
Description: "Error UI Pane Loaded"
|
|
227
|
+
});
|
|
228
|
+
}
|
|
212
229
|
// Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
|
|
213
230
|
dispatch({
|
|
214
231
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
215
232
|
payload: ConversationState.Loading
|
|
216
233
|
});
|
|
234
|
+
|
|
235
|
+
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
236
|
+
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
237
|
+
if (isStartChatSuccessful === true) {
|
|
238
|
+
await forceEndChat(chatSDK);
|
|
239
|
+
}
|
|
217
240
|
} finally {
|
|
218
241
|
optionalParams = {};
|
|
219
242
|
widgetInstanceId = "";
|
|
220
243
|
}
|
|
221
244
|
};
|
|
222
245
|
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
247
|
+
const forceEndChat = async chatSDK => {
|
|
248
|
+
TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
|
|
249
|
+
Event: TelemetryEvent.WidgetLoadFailed,
|
|
250
|
+
ExceptionDetails: {
|
|
251
|
+
Exception: "SessionInit was successful, but widget load failed."
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
|
|
255
|
+
};
|
|
256
|
+
|
|
223
257
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
258
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
225
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$
|
|
259
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
|
|
226
260
|
// By pass this function in case of popout chat
|
|
227
261
|
if (state.appStates.hideStartChatButton === true) {
|
|
228
262
|
return false;
|
|
229
263
|
}
|
|
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$
|
|
264
|
+
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
265
|
|
|
232
266
|
//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)
|
|
267
|
+
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
268
|
var _persistedState$domai7;
|
|
235
269
|
dispatch({
|
|
236
270
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
@@ -239,7 +273,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
239
273
|
const optionalParams = {
|
|
240
274
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
241
275
|
};
|
|
242
|
-
await initStartChat(chatSDK,
|
|
276
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
243
277
|
return true;
|
|
244
278
|
} else {
|
|
245
279
|
return false;
|
|
@@ -269,38 +303,11 @@ const setCustomContextParams = chatSDK => {
|
|
|
269
303
|
}
|
|
270
304
|
};
|
|
271
305
|
|
|
272
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
273
|
-
const handleAuthenticationIfEnabled = async (chatSDK, props) => {
|
|
274
|
-
//For auth chat
|
|
275
|
-
if (props.getAuthToken) {
|
|
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
306
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
307
|
const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
|
|
291
308
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
309
|
let conversationDetails = undefined;
|
|
293
310
|
|
|
294
|
-
// Show Loading screen during auth check and start chat calls
|
|
295
|
-
dispatch({
|
|
296
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
297
|
-
payload: ConversationState.Loading
|
|
298
|
-
});
|
|
299
|
-
const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
|
|
300
|
-
if (!authSucceed) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
311
|
//Preserve old requestId
|
|
305
312
|
const oldRequestId = chatSDK.requestId;
|
|
306
313
|
try {
|
|
@@ -311,6 +318,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
|
|
|
311
318
|
return false;
|
|
312
319
|
}
|
|
313
320
|
if (conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
321
|
+
dispatch({
|
|
322
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
323
|
+
payload: undefined
|
|
324
|
+
});
|
|
314
325
|
chatSDK.requestId = oldRequestId;
|
|
315
326
|
return false;
|
|
316
327
|
}
|
|
@@ -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,25 @@ 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 { defaultClientDataStoreProvider } from "../../../common/storage/default/defaultClientDataStoreProvider";
|
|
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";
|
|
49
51
|
export const LiveChatWidgetStateful = props => {
|
|
50
|
-
var _props$webChatContain, _props$styleProps, _chatSDK$omnichannelC, _props$controlProps, _props$controlProps2, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$
|
|
52
|
+
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
53
|
const [state, dispatch] = useChatContextStore();
|
|
52
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
55
|
const [adapter, setAdapter] = useChatAdapterStore();
|
|
@@ -95,7 +97,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
95
97
|
};
|
|
96
98
|
} else {
|
|
97
99
|
activeCachedChatExist = false;
|
|
98
|
-
optionalParams =
|
|
100
|
+
optionalParams = {};
|
|
99
101
|
}
|
|
100
102
|
};
|
|
101
103
|
|
|
@@ -117,7 +119,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
117
119
|
//Check if conversation state is not in wrapup or closed state
|
|
118
120
|
isChatValid = await checkIfConversationStillValid(chatSDK, props, (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.liveChatContext) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.requestId, dispatch);
|
|
119
121
|
if (isChatValid === true) {
|
|
120
|
-
await initStartChat(chatSDK,
|
|
122
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
@@ -133,16 +135,22 @@ export const LiveChatWidgetStateful = props => {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
const setupClientDataStore = () => {
|
|
138
141
|
// Add default localStorage support for widget
|
|
139
142
|
if (props.contextDataStore === undefined) {
|
|
140
|
-
var _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$
|
|
141
|
-
|
|
142
|
-
DataStoreManager.clientDataStore = defaultClientDataStoreProvider();
|
|
143
|
+
var _props$controlProps3, _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$controlProps4;
|
|
144
|
+
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;
|
|
145
|
+
DataStoreManager.clientDataStore = defaultClientDataStoreProvider(cacheTtlInMins);
|
|
146
|
+
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
147
|
} else {
|
|
144
148
|
DataStoreManager.clientDataStore = props.contextDataStore;
|
|
145
149
|
}
|
|
150
|
+
};
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
var _props$controlProps5, _props$controlProps6, _props$controlProps7, _props$chatConfig, _props$chatConfig$Liv, _props$controlProps9, _props$chatConfig2, _props$chatConfig2$Ch;
|
|
153
|
+
setupClientDataStore();
|
|
146
154
|
registerTelemetryLoggers(props, dispatch);
|
|
147
155
|
createInternetConnectionChangeHandler();
|
|
148
156
|
dispatch({
|
|
@@ -151,17 +159,17 @@ export const LiveChatWidgetStateful = props => {
|
|
|
151
159
|
});
|
|
152
160
|
dispatch({
|
|
153
161
|
type: LiveChatWidgetActionType.SET_START_CHAT_BUTTON_DISPLAY,
|
|
154
|
-
payload: ((_props$
|
|
162
|
+
payload: ((_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.hideStartChatButton) || false
|
|
155
163
|
});
|
|
156
164
|
dispatch({
|
|
157
165
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
158
166
|
payload: false
|
|
159
167
|
});
|
|
160
|
-
if ((_props$
|
|
161
|
-
var _props$
|
|
168
|
+
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)) {
|
|
169
|
+
var _props$controlProps8;
|
|
162
170
|
dispatch({
|
|
163
171
|
type: LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
|
|
164
|
-
payload: (_props$
|
|
172
|
+
payload: (_props$controlProps8 = props.controlProps) === null || _props$controlProps8 === void 0 ? void 0 : _props$controlProps8.widgetInstanceId
|
|
165
173
|
});
|
|
166
174
|
}
|
|
167
175
|
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 +182,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
174
182
|
}
|
|
175
183
|
|
|
176
184
|
// Initialize global dir
|
|
177
|
-
const globalDir = ((_props$
|
|
185
|
+
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
186
|
dispatch({
|
|
179
187
|
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
180
188
|
payload: globalDir
|
|
@@ -200,7 +208,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
200
208
|
|
|
201
209
|
// useEffect for custom context
|
|
202
210
|
useEffect(() => {
|
|
203
|
-
var _chatSDK$omnichannelC8, _chatSDK$omnichannelC9, _props$
|
|
211
|
+
var _chatSDK$omnichannelC8, _chatSDK$omnichannelC9, _props$controlProps13;
|
|
204
212
|
// Add the custom context on receiving the SetCustomContext event
|
|
205
213
|
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
206
214
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -228,14 +236,33 @@ export const LiveChatWidgetStateful = props => {
|
|
|
228
236
|
}
|
|
229
237
|
});
|
|
230
238
|
|
|
239
|
+
// Toggle chat visibility
|
|
240
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.HideChatVisibilityChangeEvent).subscribe(event => {
|
|
241
|
+
var _event$payload;
|
|
242
|
+
if ((event === null || event === void 0 ? void 0 : (_event$payload = event.payload) === null || _event$payload === void 0 ? void 0 : _event$payload.isChatHidden) !== undefined) {
|
|
243
|
+
var _event$payload2, _props$controlProps10;
|
|
244
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
245
|
+
Event: TelemetryEvent.ChatVisibilityChanged,
|
|
246
|
+
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)
|
|
247
|
+
});
|
|
248
|
+
if ((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideStartChatButton) {
|
|
249
|
+
var _event$payload3;
|
|
250
|
+
dispatch({
|
|
251
|
+
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
252
|
+
payload: event === null || event === void 0 ? void 0 : (_event$payload3 = event.payload) === null || _event$payload3 === void 0 ? void 0 : _event$payload3.isChatHidden
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
231
258
|
// Start chat from SDK Event
|
|
232
259
|
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
233
|
-
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$
|
|
260
|
+
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$controlProps11;
|
|
234
261
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
235
262
|
Event: TelemetryEvent.StartChatEventRecevied,
|
|
236
263
|
Description: "Start chat event received."
|
|
237
264
|
});
|
|
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$
|
|
265
|
+
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
266
|
|
|
240
267
|
// Chat not found in cache
|
|
241
268
|
if (persistedState === undefined) {
|
|
@@ -276,9 +303,9 @@ export const LiveChatWidgetStateful = props => {
|
|
|
276
303
|
// End chat
|
|
277
304
|
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
278
305
|
if (state.appStates.hideStartChatButton === false) {
|
|
279
|
-
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$
|
|
306
|
+
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$controlProps12;
|
|
280
307
|
// 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$
|
|
308
|
+
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
309
|
if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
|
|
283
310
|
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
284
311
|
} else {
|
|
@@ -298,14 +325,14 @@ export const LiveChatWidgetStateful = props => {
|
|
|
298
325
|
});
|
|
299
326
|
|
|
300
327
|
// 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$
|
|
328
|
+
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
329
|
BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
303
330
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
304
331
|
return;
|
|
305
332
|
});
|
|
306
333
|
|
|
307
334
|
// When conversation ended by agent
|
|
308
|
-
if (state.appStates.
|
|
335
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
|
|
309
336
|
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
310
337
|
}
|
|
311
338
|
|
|
@@ -403,7 +430,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
403
430
|
|
|
404
431
|
// Publish chat widget state
|
|
405
432
|
useEffect(() => {
|
|
406
|
-
var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$
|
|
433
|
+
var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$controlProps14;
|
|
407
434
|
// Only activate these windows events when conversation state is active and chat widget is in popout mode
|
|
408
435
|
// Ghost chat scenarios
|
|
409
436
|
/* COMMENTING THIS CODE FOR PARITY WITH OLD LCW
|
|
@@ -421,7 +448,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
421
448
|
};
|
|
422
449
|
}*/
|
|
423
450
|
|
|
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$
|
|
451
|
+
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
452
|
const chatWidgetStateChangeEvent = {
|
|
426
453
|
eventName: widgetStateEventName,
|
|
427
454
|
payload: {
|
|
@@ -430,6 +457,20 @@ export const LiveChatWidgetStateful = props => {
|
|
|
430
457
|
};
|
|
431
458
|
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
432
459
|
}, [state]);
|
|
460
|
+
|
|
461
|
+
// Initiate End chat from a single point
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
if (state.appStates.conversationEndedBy !== undefined) {
|
|
464
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
465
|
+
}
|
|
466
|
+
}, [state.appStates.conversationEndedBy]);
|
|
467
|
+
|
|
468
|
+
// Handle Agent end conversation cases
|
|
469
|
+
useEffect(() => {
|
|
470
|
+
if (state.appStates.conversationEndedByAgentEventReceived) {
|
|
471
|
+
handleAgentEndConversation(props, state, dispatch);
|
|
472
|
+
}
|
|
473
|
+
}, [state.appStates.conversationEndedByAgentEventReceived]);
|
|
433
474
|
const initiateEndChatOnBrowserUnload = () => {
|
|
434
475
|
var _DataStoreManager$cli;
|
|
435
476
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
@@ -449,15 +490,13 @@ export const LiveChatWidgetStateful = props => {
|
|
|
449
490
|
eventName: BroadcastEvent.ClosePopoutWindow
|
|
450
491
|
});
|
|
451
492
|
};
|
|
452
|
-
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
493
|
+
const webChatProps = initWebChatComposer(props, chatSDK, setAdapter, state, dispatch, adapter, setWebChatStyles);
|
|
453
494
|
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
454
495
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
455
496
|
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
497
|
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
459
498
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
460
|
-
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK,
|
|
499
|
+
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
461
500
|
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
462
501
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
|
|
463
502
|
::-webkit-scrollbar {
|
|
@@ -483,28 +522,27 @@ export const LiveChatWidgetStateful = props => {
|
|
|
483
522
|
id: widgetElementId,
|
|
484
523
|
styles: generalStyles,
|
|
485
524
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
486
|
-
}, !((_props$
|
|
525
|
+
}, !((_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
526
|
buttonProps: props.chatButtonProps,
|
|
488
527
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
489
528
|
startChat: prepareStartChatRelay
|
|
490
|
-
})), !((_props$
|
|
529
|
+
})), !((_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
530
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
492
531
|
startChat: prepareStartChatRelay
|
|
493
|
-
})), !((_props$
|
|
532
|
+
})), !((_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
533
|
headerProps: props.headerProps,
|
|
495
534
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
496
535
|
endChat: endChatRelay
|
|
497
|
-
})), !((_props$
|
|
536
|
+
})), !((_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
537
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
499
538
|
initStartChat: initStartChatRelay
|
|
500
|
-
})), !((_props$
|
|
539
|
+
})), !((_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
540
|
surveyProps: props.preChatSurveyPaneProps,
|
|
502
541
|
initStartChat: initStartChatRelay
|
|
503
|
-
})), !((_props$
|
|
542
|
+
})), !((_props$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
504
543
|
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)))));
|
|
544
|
+
}, 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, {
|
|
545
|
+
setPostChatContext: setPostChatContextRelay
|
|
546
|
+
}))), !((_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
547
|
};
|
|
510
548
|
export default LiveChatWidgetStateful;
|
|
@@ -5,6 +5,7 @@ import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
|
5
5
|
import { defaultGeneralLoadingPaneStyleProps } from "./common/defaultStyleProps/defaultgeneralLoadingPaneStyleProps";
|
|
6
6
|
import { findAllFocusableElement } from "../../common/utils";
|
|
7
7
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
8
|
+
import useWindowDimensions from "../../hooks/useWindowDimensions";
|
|
8
9
|
import { errorUILoadingPaneStyleProps } from "./common/errorUIStyleProps/errorUILoadingPaneStyleProps";
|
|
9
10
|
export const LoadingPaneStateful = props => {
|
|
10
11
|
var _props$styleProps;
|
|
@@ -31,6 +32,10 @@ export const LoadingPaneStateful = props => {
|
|
|
31
32
|
hideSpinnerText: true,
|
|
32
33
|
...props.controlProps
|
|
33
34
|
};
|
|
35
|
+
const {
|
|
36
|
+
height,
|
|
37
|
+
width
|
|
38
|
+
} = useWindowDimensions();
|
|
34
39
|
|
|
35
40
|
// Move focus to the first button
|
|
36
41
|
useEffect(() => {
|
|
@@ -46,7 +51,9 @@ export const LoadingPaneStateful = props => {
|
|
|
46
51
|
return /*#__PURE__*/React.createElement(LoadingPane, {
|
|
47
52
|
componentOverrides: props.componentOverrides,
|
|
48
53
|
controlProps: state.appStates.isStartChatFailing ? errorUIControlProps : controlProps,
|
|
49
|
-
styleProps: state.appStates.isStartChatFailing ? errorUIStyleProps : styleProps
|
|
54
|
+
styleProps: state.appStates.isStartChatFailing ? errorUIStyleProps : styleProps,
|
|
55
|
+
windowWidth: width,
|
|
56
|
+
windowHeight: height
|
|
50
57
|
});
|
|
51
58
|
};
|
|
52
59
|
export default LoadingPaneStateful;
|
|
@@ -15,7 +15,9 @@ export const PostChatSurveyPaneStateful = props => {
|
|
|
15
15
|
display: state.appStates.isMinimized ? "none" : ""
|
|
16
16
|
});
|
|
17
17
|
let surveyInviteLink = "";
|
|
18
|
-
if (state.domainStates.postChatContext.
|
|
18
|
+
if (state.appStates.shouldUseBotSurvey && state.domainStates.postChatContext.botSurveyInviteLink) {
|
|
19
|
+
surveyInviteLink = state.domainStates.postChatContext.botSurveyInviteLink + "&embed=" + (postChatSurveyMode === PostChatSurveyMode.Embed).toString() + "&compact=" + (props.isCustomerVoiceSurveyCompact ?? true).toString() + "&lang=" + (state.domainStates.postChatContext.formsProLocale ?? "en") + "&showmultilingual=false";
|
|
20
|
+
} else {
|
|
19
21
|
surveyInviteLink = state.domainStates.postChatContext.surveyInviteLink + "&embed=" + (postChatSurveyMode === PostChatSurveyMode.Embed).toString() + "&compact=" + (props.isCustomerVoiceSurveyCompact ?? true).toString() + "&lang=" + (state.domainStates.postChatContext.formsProLocale ?? "en") + "&showmultilingual=false";
|
|
20
22
|
}
|
|
21
23
|
const styleProps = {
|
|
@@ -112,7 +112,7 @@ export const PreChatSurveyPaneStateful = props => {
|
|
|
112
112
|
}
|
|
113
113
|
if (current && current.tagName.toLowerCase() == HtmlAttributeNames.div && current.childElementCount > 0) {
|
|
114
114
|
const input = current.children[0].children;
|
|
115
|
-
if (input
|
|
115
|
+
if ((input === null || input === void 0 ? void 0 : input.length) > 0 && input[0].className != HtmlAttributeNames.adaptiveCardToggleInputClassName && input[0].className != HtmlAttributeNames.adaptiveCardActionSetClassName) {
|
|
116
116
|
input[0].setAttribute(HtmlAttributeNames.ariaLabel, value);
|
|
117
117
|
}
|
|
118
118
|
}
|