@microsoft/omnichannel-chat-widget 1.7.4-main.562254b → 1.7.4-main.8d43b20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/common/facades/FacadeChatSDK.js +298 -0
- package/lib/cjs/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/cjs/common/utils.js +2 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/cjs/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/cjs/components/livechatwidget/common/endChat.js +21 -22
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +3 -3
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
- package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +4 -4
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +42 -36
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/cjs/contexts/FacadeChatSDKStore.js +10 -0
- package/lib/cjs/hooks/useFacadeChatSDKStore.js +17 -0
- package/lib/cjs/index.js +9 -2
- package/lib/cjs/plugins/createChatTranscript.js +2 -2
- package/lib/esm/common/facades/FacadeChatSDK.js +291 -0
- package/lib/esm/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +5 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/esm/common/utils.js +2 -2
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/esm/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/esm/components/livechatwidget/common/endChat.js +21 -22
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +3 -3
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -4
- package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +4 -4
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +42 -36
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/esm/contexts/FacadeChatSDKStore.js +4 -0
- package/lib/esm/hooks/useFacadeChatSDKStore.js +10 -0
- package/lib/esm/index.js +5 -4
- package/lib/esm/plugins/createChatTranscript.js +2 -2
- package/lib/types/common/facades/FacadeChatSDK.d.ts +71 -0
- package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +13 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
- package/lib/types/common/utils.d.ts +2 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +14 -1
- package/lib/types/components/livechatwidget/common/createAdapter.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/initCallingSdk.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/updateSessionDataForTelemetry.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -1
- package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
- package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
- package/lib/types/index.d.ts +4 -3
- package/lib/types/plugins/createChatTranscript.d.ts +2 -1
- package/package.json +1 -1
|
@@ -31,27 +31,27 @@ let widgetInstanceId;
|
|
|
31
31
|
let popoutWidgetInstanceId;
|
|
32
32
|
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
const setAuthenticationIfApplicable = async (props,
|
|
34
|
+
const setAuthenticationIfApplicable = async (props, facadeChatSDK) => {
|
|
35
35
|
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
36
36
|
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
37
37
|
const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
|
|
38
38
|
if (getAuthToken && authClientFunction) {
|
|
39
39
|
// set auth token to chat sdk before start chat
|
|
40
|
-
const authSuccess = await (0, _authHelper.handleAuthentication)(
|
|
41
|
-
if (!authSuccess) {
|
|
40
|
+
const authSuccess = await (0, _authHelper.handleAuthentication)(facadeChatSDK.getChatSDK(), chatConfig, getAuthToken);
|
|
41
|
+
if (!authSuccess.result) {
|
|
42
42
|
throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
const prepareStartChat = async (props,
|
|
48
|
+
const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
49
49
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
50
50
|
widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
|
|
51
51
|
|
|
52
52
|
// reconnect > chat from cache
|
|
53
53
|
if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
|
|
54
|
-
const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(
|
|
54
|
+
const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
55
55
|
if (!shouldStartChatNormally) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -63,7 +63,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// Can connect to existing chat session
|
|
66
|
-
if (await canConnectToExistingChat(props,
|
|
66
|
+
if (await canConnectToExistingChat(props, facadeChatSDK, state, dispatch, setAdapter)) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -73,27 +73,31 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
73
73
|
|
|
74
74
|
// Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
|
|
75
75
|
if ((0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
|
|
76
|
-
await setAuthenticationIfApplicable(props,
|
|
76
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
//Setting PreChat and intiate chat
|
|
80
|
-
await setPreChatAndInitiateChat(
|
|
80
|
+
await setPreChatAndInitiateChat(facadeChatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
84
|
exports.prepareStartChat = prepareStartChat;
|
|
85
|
-
const setPreChatAndInitiateChat = async (
|
|
85
|
+
const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
86
86
|
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
|
|
87
|
-
//
|
|
87
|
+
// This reset needs to be done before to load prechat, because the conversation state changes from close to prechat
|
|
88
|
+
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
|
|
89
|
+
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
90
|
+
(0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
|
|
91
|
+
}
|
|
88
92
|
|
|
89
93
|
// Getting prechat Survey Context
|
|
90
94
|
const parseToJson = false;
|
|
91
|
-
const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await
|
|
95
|
+
const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await facadeChatSDK.getPreChatSurvey(parseToJson));
|
|
92
96
|
let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
|
|
93
|
-
showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(
|
|
97
|
+
showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(facadeChatSDK.getChatSDK(), state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_conversationmode, showPrechat);
|
|
94
98
|
if (showPrechat) {
|
|
95
99
|
var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
|
|
96
|
-
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toLowerCase()) === "true";
|
|
100
|
+
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toString().toLowerCase()) === "true";
|
|
97
101
|
if (isOutOfOperatingHours) {
|
|
98
102
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
99
103
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -144,18 +148,18 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
144
148
|
const optionalParams = {
|
|
145
149
|
isProactiveChat
|
|
146
150
|
};
|
|
147
|
-
await initStartChat(
|
|
151
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
148
152
|
};
|
|
149
153
|
|
|
150
154
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
155
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
152
|
-
const initStartChat = async (
|
|
156
|
+
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
153
157
|
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
154
158
|
let isStartChatSuccessful = false;
|
|
155
159
|
const persistentChatEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
|
|
156
160
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
|
|
157
161
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
158
|
-
(0, _endChat.chatSDKStateCleanUp)(
|
|
162
|
+
(0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
|
|
159
163
|
}
|
|
160
164
|
try {
|
|
161
165
|
var _state$appStates2;
|
|
@@ -173,7 +177,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
173
177
|
});
|
|
174
178
|
|
|
175
179
|
// Auth token retrieval needs to happen during start chat to support pop-out chat
|
|
176
|
-
await setAuthenticationIfApplicable(props,
|
|
180
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
177
181
|
|
|
178
182
|
//Check if chat retrieved from cache
|
|
179
183
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -196,7 +200,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
196
200
|
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
|
|
197
201
|
};
|
|
198
202
|
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
199
|
-
await
|
|
203
|
+
await facadeChatSDK.startChat(startChatOptionalParams);
|
|
200
204
|
isStartChatSuccessful = true;
|
|
201
205
|
} catch (error) {
|
|
202
206
|
(0, _utils.checkContactIdError)(error);
|
|
@@ -215,7 +219,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
215
219
|
isStartChatSuccessful = false;
|
|
216
220
|
throw error;
|
|
217
221
|
}
|
|
218
|
-
await createAdapterAndSubscribe(
|
|
222
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
219
223
|
|
|
220
224
|
// Set app state to Active
|
|
221
225
|
if (isStartChatSuccessful) {
|
|
@@ -237,14 +241,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
237
241
|
});
|
|
238
242
|
(0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
239
243
|
// Set post chat context in state, load in background to do not block the load
|
|
240
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
244
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch, true);
|
|
241
245
|
return;
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
245
249
|
if (!persistentChatEnabled) {
|
|
246
250
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
247
|
-
const liveChatContext = await (
|
|
251
|
+
const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
|
|
248
252
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
253
|
dispatch({
|
|
250
254
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -253,11 +257,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
253
257
|
}
|
|
254
258
|
(0, _startChatErrorHandler.logWidgetLoadComplete)();
|
|
255
259
|
// Set post chat context in state, load in background to do not block the load
|
|
256
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
260
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
|
|
257
261
|
// Updating chat session detail for telemetry
|
|
258
|
-
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(
|
|
262
|
+
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(facadeChatSDK, dispatch);
|
|
259
263
|
} catch (ex) {
|
|
260
|
-
(0, _startChatErrorHandler.handleStartChatError)(dispatch,
|
|
264
|
+
(0, _startChatErrorHandler.handleStartChatError)(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
261
265
|
} finally {
|
|
262
266
|
optionalParams = {};
|
|
263
267
|
widgetInstanceId = "";
|
|
@@ -266,20 +270,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
266
270
|
|
|
267
271
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
272
|
exports.initStartChat = initStartChat;
|
|
269
|
-
const createAdapterAndSubscribe = async (
|
|
270
|
-
var _newAdapter$activity$;
|
|
273
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
271
274
|
// New adapter creation
|
|
272
|
-
const newAdapter = await (0, _createAdapter.createAdapter)(
|
|
275
|
+
const newAdapter = await (0, _createAdapter.createAdapter)(facadeChatSDK, props);
|
|
273
276
|
setAdapter(newAdapter);
|
|
274
|
-
const chatToken = await
|
|
277
|
+
const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
|
|
275
278
|
dispatch({
|
|
276
279
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
277
280
|
payload: chatToken
|
|
278
281
|
});
|
|
279
|
-
|
|
282
|
+
if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
|
|
283
|
+
var _newAdapter$activity$;
|
|
284
|
+
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken.chatId, chatToken.visitorId));
|
|
285
|
+
}
|
|
280
286
|
};
|
|
281
287
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
|
-
const canConnectToExistingChat = async (props,
|
|
288
|
+
const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
283
289
|
var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
|
|
284
290
|
// By pass this function in case of popout chat
|
|
285
291
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.hideStartChatButton) === true) {
|
|
@@ -297,7 +303,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
297
303
|
const optionalParams = {
|
|
298
304
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
299
305
|
};
|
|
300
|
-
await initStartChat(
|
|
306
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
301
307
|
return true;
|
|
302
308
|
}
|
|
303
309
|
return false;
|
|
@@ -362,28 +368,28 @@ const canStartPopoutChat = async props => {
|
|
|
362
368
|
};
|
|
363
369
|
|
|
364
370
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
-
const checkIfConversationStillValid = async (
|
|
371
|
+
const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
|
|
366
372
|
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
367
373
|
const requestIdFromCache = (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : (_state$domainStates8$ = _state$domainStates8.liveChatContext) === null || _state$domainStates8$ === void 0 ? void 0 : _state$domainStates8$.requestId;
|
|
368
374
|
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
369
375
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
370
376
|
let conversationDetails = undefined;
|
|
371
377
|
// Preserve current requestId
|
|
372
|
-
const currentRequestId =
|
|
378
|
+
const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
|
|
373
379
|
dispatch({
|
|
374
380
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
375
381
|
payload: currentRequestId
|
|
376
382
|
});
|
|
377
383
|
try {
|
|
378
|
-
|
|
379
|
-
conversationDetails = await (0, _utils.getConversationDetailsCall)(
|
|
384
|
+
facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
|
|
385
|
+
conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK, liveChatContext);
|
|
380
386
|
if (Object.keys(conversationDetails).length === 0 || (0, _utils.isNullOrUndefined)(conversationDetails.state) || conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
381
387
|
dispatch({
|
|
382
388
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
383
389
|
payload: undefined
|
|
384
390
|
});
|
|
385
391
|
if (currentRequestId) {
|
|
386
|
-
|
|
392
|
+
facadeChatSDK.getChatSDK().requestId = currentRequestId;
|
|
387
393
|
}
|
|
388
394
|
return false;
|
|
389
395
|
}
|
|
@@ -16,7 +16,7 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
|
16
16
|
var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
|
|
17
17
|
var _utils = require("../../../common/utils");
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
const handleStartChatError = (dispatch,
|
|
19
|
+
const handleStartChatError = (dispatch, facadeChatSDK, props, ex, isStartChatSuccessful) => {
|
|
20
20
|
var _props$controlProps;
|
|
21
21
|
if (!ex) {
|
|
22
22
|
logWidgetLoadFailed();
|
|
@@ -64,7 +64,7 @@ const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSuccessfu
|
|
|
64
64
|
break;
|
|
65
65
|
case _omnichannelChatSdk.ChatSDKErrorName.InvalidConversation:
|
|
66
66
|
case _omnichannelChatSdk.ChatSDKErrorName.ClosedConversation:
|
|
67
|
-
handleInvalidOrClosedConversation(dispatch,
|
|
67
|
+
handleInvalidOrClosedConversation(dispatch, facadeChatSDK, props, ex);
|
|
68
68
|
return;
|
|
69
69
|
default:
|
|
70
70
|
logWidgetLoadFailed(ex);
|
|
@@ -99,7 +99,7 @@ const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSuccessfu
|
|
|
99
99
|
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
100
100
|
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
101
101
|
if (isStartChatSuccessful === true) {
|
|
102
|
-
forceEndChat(
|
|
102
|
+
forceEndChat(facadeChatSDK);
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
exports.handleStartChatError = handleStartChatError;
|
|
@@ -149,7 +149,7 @@ const logWidgetLoadCompleteWithError = ex => {
|
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
152
|
-
const forceEndChat =
|
|
152
|
+
const forceEndChat = facadeChatSDK => {
|
|
153
153
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
154
154
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
155
155
|
Description: _Constants.PrepareEndChatDescriptionConstants.WidgetLoadFailedAfterSessionInit
|
|
@@ -157,7 +157,7 @@ const forceEndChat = chatSDK => {
|
|
|
157
157
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
158
158
|
Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCall
|
|
159
159
|
});
|
|
160
|
-
|
|
160
|
+
facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatSDK().endChat();
|
|
161
161
|
};
|
|
162
162
|
const handleWidgetUseOutsideOperatingHour = dispatch => {
|
|
163
163
|
dispatch({
|
|
@@ -210,7 +210,7 @@ const handleUninitializedChatSDK = ex => {
|
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
|
-
const handleInvalidOrClosedConversation = (dispatch,
|
|
213
|
+
const handleInvalidOrClosedConversation = (dispatch, facadeChatSDK, props, ex) => {
|
|
214
214
|
var _DataStoreManager$cli;
|
|
215
215
|
logWidgetLoadCompleteWithError(ex);
|
|
216
216
|
|
|
@@ -218,7 +218,7 @@ const handleInvalidOrClosedConversation = (dispatch, chatSDK, props, ex) => {
|
|
|
218
218
|
(0, _endChat.callingStateCleanUp)(dispatch);
|
|
219
219
|
(0, _endChat.endChatStateCleanUp)(dispatch);
|
|
220
220
|
(0, _endChat.closeChatStateCleanUp)(dispatch);
|
|
221
|
-
(0, _endChat.chatSDKStateCleanUp)(
|
|
221
|
+
(0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
|
|
222
222
|
(_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData((0, _utils.getWidgetCacheIdfromProps)(props));
|
|
223
223
|
|
|
224
224
|
// Starts new chat
|
|
@@ -11,17 +11,17 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
|
11
11
|
var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
|
|
12
12
|
var _utils = require("../../../common/utils");
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const updateTelemetryData = async (
|
|
14
|
+
const updateTelemetryData = async (facadeChatSDK, dispatch) => {
|
|
15
15
|
// load it concurrently, this will reduce the load time
|
|
16
|
-
await Promise.all([updateSessionDataForTelemetry(
|
|
16
|
+
await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch), updateConversationDataForTelemetry(facadeChatSDK, dispatch)]);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
exports.updateTelemetryData = updateTelemetryData;
|
|
21
|
-
const updateSessionDataForTelemetry = async (
|
|
22
|
-
if (
|
|
21
|
+
const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
22
|
+
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
const chatSession = await
|
|
24
|
+
const chatSession = await facadeChatSDK.getCurrentLiveChatContext();
|
|
25
25
|
const telemetryData = _TelemetryHelper.TelemetryHelper.addSessionDataToTelemetry(chatSession, _TelemetryManager.TelemetryManager.InternalTelemetryData);
|
|
26
26
|
dispatch({
|
|
27
27
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|
|
@@ -37,10 +37,10 @@ const updateSessionDataForTelemetry = async (chatSDK, dispatch) => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
const updateConversationDataForTelemetry = async (
|
|
41
|
-
if (
|
|
40
|
+
const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
41
|
+
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
const liveWorkItem = await (0, _utils.getConversationDetailsCall)(
|
|
43
|
+
const liveWorkItem = await (0, _utils.getConversationDetailsCall)(facadeChatSDK);
|
|
44
44
|
const telemetryData = _TelemetryHelper.TelemetryHelper.addConversationDataToTelemetry(liveWorkItem, _TelemetryManager.TelemetryManager.InternalTelemetryData);
|
|
45
45
|
dispatch({
|
|
46
46
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|
|
@@ -57,7 +57,7 @@ var _setPostChatContextAndLoadSurvey = require("../common/setPostChatContextAndL
|
|
|
57
57
|
var _startProactiveChat = require("../common/startProactiveChat");
|
|
58
58
|
var _useChatAdapterStore = _interopRequireDefault(require("../../../hooks/useChatAdapterStore"));
|
|
59
59
|
var _useChatContextStore = _interopRequireDefault(require("../../../hooks/useChatContextStore"));
|
|
60
|
-
var
|
|
60
|
+
var _useFacadeChatSDKStore = _interopRequireDefault(require("../../../hooks/useFacadeChatSDKStore"));
|
|
61
61
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
62
62
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
63
63
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -72,7 +72,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
72
72
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
73
73
|
});
|
|
74
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
-
const
|
|
75
|
+
const [facadeChatSDK] = (0, _useFacadeChatSDKStore.default)();
|
|
76
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
77
|
const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = (0, _react2.useState)(undefined);
|
|
78
78
|
const {
|
|
@@ -90,8 +90,8 @@ const LiveChatWidgetStateful = props => {
|
|
|
90
90
|
|
|
91
91
|
// In case the broadcast channel is already initialized elsewhere; One tab can only hold 1 instance
|
|
92
92
|
if ((props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.skipBroadcastChannelInit) !== true) {
|
|
93
|
-
var
|
|
94
|
-
const broadcastServiceChannelName = (0, _utils.getBroadcastChannelName)(
|
|
93
|
+
var _facadeChatSDK$getCha, _facadeChatSDK$getCha2, _props$controlProps2;
|
|
94
|
+
const broadcastServiceChannelName = (0, _utils.getBroadcastChannelName)((_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : (_facadeChatSDK$getCha2 = _facadeChatSDK$getCha.omnichannelConfig) === null || _facadeChatSDK$getCha2 === void 0 ? void 0 : _facadeChatSDK$getCha2.widgetId, ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
|
|
95
95
|
(0, _omnichannelChatComponents.BroadcastServiceInitialize)(broadcastServiceChannelName);
|
|
96
96
|
}
|
|
97
97
|
_TelemetryManager.TelemetryTimers.LcwLoadToChatButtonTimer = (0, _utils.createTimer)();
|
|
@@ -126,7 +126,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
126
126
|
const startChat = async (props, localState) => {
|
|
127
127
|
const isReconnectTriggered = async () => {
|
|
128
128
|
if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
|
|
129
|
-
const noValidReconnectId = await (0, _reconnectChatHelper.handleChatReconnect)(
|
|
129
|
+
const noValidReconnectId = await (0, _reconnectChatHelper.handleChatReconnect)(facadeChatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
|
|
130
130
|
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
131
131
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
132
132
|
payload: null
|
|
@@ -147,11 +147,11 @@ const LiveChatWidgetStateful = props => {
|
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
//Check if conversation state is not in wrapup or closed state
|
|
150
|
-
isChatValid = await (0, _startChat.checkIfConversationStillValid)(
|
|
150
|
+
isChatValid = await (0, _startChat.checkIfConversationStillValid)(facadeChatSDK, dispatch, state);
|
|
151
151
|
if (isChatValid === true) {
|
|
152
152
|
const reconnectTriggered = await isReconnectTriggered();
|
|
153
153
|
if (!reconnectTriggered) {
|
|
154
|
-
await (0, _startChat.initStartChat)(
|
|
154
|
+
await (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
155
155
|
}
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
@@ -171,7 +171,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
171
171
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
172
172
|
payload: null
|
|
173
173
|
});
|
|
174
|
-
await (0, _startChat.setPreChatAndInitiateChat)(
|
|
174
|
+
await (0, _startChat.setPreChatAndInitiateChat)(facadeChatSDK, dispatch, setAdapter, undefined, undefined, inMemoryState, props);
|
|
175
175
|
}
|
|
176
176
|
return;
|
|
177
177
|
} else {
|
|
@@ -241,7 +241,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
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) !== _Constants.E2VVOptions.NoCalling) {
|
|
244
|
-
(0, _initCallingSdk.initCallingSdk)(
|
|
244
|
+
(0, _initCallingSdk.initCallingSdk)(facadeChatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
245
245
|
sdkCreated && dispatch({
|
|
246
246
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
247
247
|
payload: true
|
|
@@ -273,9 +273,9 @@ const LiveChatWidgetStateful = props => {
|
|
|
273
273
|
(0, _react2.useEffect)(() => {
|
|
274
274
|
var _state$appStates6;
|
|
275
275
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates6 = state.appStates) === null || _state$appStates6 === void 0 ? void 0 : _state$appStates6.hideStartChatButton) === true) {
|
|
276
|
-
var _props$chatConfig3, _props$chatConfig3$Li;
|
|
276
|
+
var _props$chatConfig3, _props$chatConfig3$Li, _props$chatConfig4, _props$chatConfig4$Li;
|
|
277
277
|
//handle OOH pane
|
|
278
|
-
if ((props === null || props === void 0 ? void 0 : (_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.OutOfOperatingHours.toLowerCase()) === "true") {
|
|
278
|
+
if (typeof (props === null || props === void 0 ? void 0 : (_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.OutOfOperatingHours) === "string" && (props === null || props === void 0 ? void 0 : (_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.OutOfOperatingHours.toLowerCase()) === "true") {
|
|
279
279
|
dispatch({
|
|
280
280
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
281
281
|
payload: _ConversationState.ConversationState.OutOfOffice
|
|
@@ -298,7 +298,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
298
298
|
|
|
299
299
|
// useEffect for custom context
|
|
300
300
|
(0, _react2.useEffect)(() => {
|
|
301
|
-
var
|
|
301
|
+
var _facadeChatSDK$getCha3, _facadeChatSDK$getCha4, _facadeChatSDK$getCha5, _facadeChatSDK$getCha6, _props$controlProps11;
|
|
302
302
|
// Add the custom context on receiving the SetCustomContext event
|
|
303
303
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
304
304
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
@@ -351,7 +351,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
351
351
|
if (callInProgress.current === false && dateNow - lastLWICheckTimeRef.current > _Constants.Constants.LWICheckOnVisibilityTimeout) {
|
|
352
352
|
lastLWICheckTimeRef.current = dateNow;
|
|
353
353
|
callInProgress.current = true;
|
|
354
|
-
const conversationDetails = await (0, _utils.getConversationDetailsCall)(
|
|
354
|
+
const conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK);
|
|
355
355
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === _Constants.LiveWorkItemState.WrapUp || (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === _Constants.LiveWorkItemState.Closed) {
|
|
356
356
|
dispatch({
|
|
357
357
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
|
|
@@ -367,11 +367,15 @@ const LiveChatWidgetStateful = props => {
|
|
|
367
367
|
}
|
|
368
368
|
});
|
|
369
369
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.NetworkReconnected).subscribe(async () => {
|
|
370
|
-
var _window2, _window2$location;
|
|
371
|
-
|
|
370
|
+
var _window2, _window2$location, _inMemoryState$appSta;
|
|
371
|
+
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
372
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
373
|
+
payload: null
|
|
374
|
+
});
|
|
375
|
+
if ((0, _utils.isThisSessionPopout)((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$location = _window2.location) === null || _window2$location === void 0 ? void 0 : _window2$location.href) || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta = inMemoryState.appStates) === null || _inMemoryState$appSta === void 0 ? void 0 : _inMemoryState$appSta.conversationState) !== _ConversationState.ConversationState.Active) {
|
|
372
376
|
return;
|
|
373
377
|
}
|
|
374
|
-
const conversationDetails = await (0, _utils.getConversationDetailsCall)(
|
|
378
|
+
const conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK);
|
|
375
379
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === _Constants.LiveWorkItemState.WrapUp || (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === _Constants.LiveWorkItemState.Closed) {
|
|
376
380
|
dispatch({
|
|
377
381
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
|
|
@@ -405,9 +409,9 @@ const LiveChatWidgetStateful = props => {
|
|
|
405
409
|
|
|
406
410
|
// Start chat from SDK Event
|
|
407
411
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(msg => {
|
|
408
|
-
var _props$
|
|
412
|
+
var _props$chatConfig5, _props$chatConfig5$Li, _props$chatConfig6, _props$chatConfig6$Li, _msg$payload5, _msg$payload6, _msg$payload7, _msg$payload9, _inMemoryState$appSta2, _inMemoryState$appSta3, _inMemoryState$appSta4, _inMemoryState$appSta5;
|
|
409
413
|
// If chat is out of operating hours chat widget sets the conversation state to OutOfOffice.
|
|
410
|
-
if ((props === null || props === void 0 ? void 0 : (_props$
|
|
414
|
+
if (typeof (props === null || props === void 0 ? void 0 : (_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.OutOfOperatingHours) === "string" && (props === null || props === void 0 ? void 0 : (_props$chatConfig6 = props.chatConfig) === null || _props$chatConfig6 === void 0 ? void 0 : (_props$chatConfig6$Li = _props$chatConfig6.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig6$Li === void 0 ? void 0 : _props$chatConfig6$Li.OutOfOperatingHours.toLowerCase()) === "true") {
|
|
411
415
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
412
416
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
413
417
|
payload: false
|
|
@@ -444,16 +448,16 @@ const LiveChatWidgetStateful = props => {
|
|
|
444
448
|
inMemoryState.domainStates.customContext = msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.customContext;
|
|
445
449
|
|
|
446
450
|
// Only initiate new chat if widget runtime state is one of the followings
|
|
447
|
-
if (((_inMemoryState$
|
|
451
|
+
if (((_inMemoryState$appSta2 = inMemoryState.appStates) === null || _inMemoryState$appSta2 === void 0 ? void 0 : _inMemoryState$appSta2.conversationState) === _ConversationState.ConversationState.Closed || ((_inMemoryState$appSta3 = inMemoryState.appStates) === null || _inMemoryState$appSta3 === void 0 ? void 0 : _inMemoryState$appSta3.conversationState) === _ConversationState.ConversationState.InActive || ((_inMemoryState$appSta4 = inMemoryState.appStates) === null || _inMemoryState$appSta4 === void 0 ? void 0 : _inMemoryState$appSta4.conversationState) === _ConversationState.ConversationState.Postchat) {
|
|
448
452
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
449
453
|
eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
|
|
450
454
|
});
|
|
451
|
-
(0, _startChat.prepareStartChat)(props,
|
|
455
|
+
(0, _startChat.prepareStartChat)(props, facadeChatSDK, inMemoryState, dispatch, setAdapter);
|
|
452
456
|
return;
|
|
453
457
|
}
|
|
454
458
|
|
|
455
459
|
// If minimized, maximize the chat
|
|
456
|
-
if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$
|
|
460
|
+
if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta5 = inMemoryState.appStates) === null || _inMemoryState$appSta5 === void 0 ? void 0 : _inMemoryState$appSta5.isMinimized) === true) {
|
|
457
461
|
var _inMemoryState$domain, _inMemoryState$domain2, _inMemoryState$domain3, _inMemoryState$domain4;
|
|
458
462
|
dispatch({
|
|
459
463
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -500,7 +504,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
500
504
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
501
505
|
Description: _Constants.PrepareEndChatDescriptionConstants.InitiateEndChatReceived
|
|
502
506
|
});
|
|
503
|
-
(0, _endChat.endChat)(props,
|
|
507
|
+
(0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
|
|
504
508
|
}
|
|
505
509
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
506
510
|
eventName: _TelemetryConstants.BroadcastEvent.CloseChat
|
|
@@ -513,7 +517,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
513
517
|
});
|
|
514
518
|
|
|
515
519
|
// Listen to end chat event from other tabs
|
|
516
|
-
const endChatEventName = (0, _utils.getWidgetEndChatEventName)(
|
|
520
|
+
const endChatEventName = (0, _utils.getWidgetEndChatEventName)((_facadeChatSDK$getCha3 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha3 === void 0 ? void 0 : (_facadeChatSDK$getCha4 = _facadeChatSDK$getCha3.omnichannelConfig) === null || _facadeChatSDK$getCha4 === void 0 ? void 0 : _facadeChatSDK$getCha4.orgId, (_facadeChatSDK$getCha5 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha5 === void 0 ? void 0 : (_facadeChatSDK$getCha6 = _facadeChatSDK$getCha5.omnichannelConfig) === null || _facadeChatSDK$getCha6 === void 0 ? void 0 : _facadeChatSDK$getCha6.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
|
|
517
521
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
|
|
518
522
|
var _msg$payload10;
|
|
519
523
|
if ((msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
|
|
@@ -521,9 +525,9 @@ const LiveChatWidgetStateful = props => {
|
|
|
521
525
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
522
526
|
Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
|
|
523
527
|
});
|
|
524
|
-
(0, _endChat.endChat)(props,
|
|
528
|
+
(0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
|
|
525
529
|
(0, _endChat.endChatStateCleanUp)(dispatch);
|
|
526
|
-
(0, _endChat.chatSDKStateCleanUp)(
|
|
530
|
+
(0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
|
|
527
531
|
return;
|
|
528
532
|
}
|
|
529
533
|
});
|
|
@@ -565,7 +569,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
565
569
|
(0, _react2.useEffect)(() => {
|
|
566
570
|
// On new message
|
|
567
571
|
if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
|
|
568
|
-
|
|
572
|
+
facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.onNewMessage(() => {
|
|
569
573
|
// Track the message count
|
|
570
574
|
currentMessageCountRef.current++;
|
|
571
575
|
dispatch({
|
|
@@ -653,7 +657,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
653
657
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
654
658
|
Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
|
|
655
659
|
});
|
|
656
|
-
(0, _endChat.endChat)(props,
|
|
660
|
+
(0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
|
|
657
661
|
return;
|
|
658
662
|
}
|
|
659
663
|
|
|
@@ -663,7 +667,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
663
667
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
664
668
|
Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
|
|
665
669
|
});
|
|
666
|
-
(0, _endChat.endChat)(props,
|
|
670
|
+
(0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
|
|
667
671
|
return;
|
|
668
672
|
}
|
|
669
673
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot) {
|
|
@@ -674,7 +678,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
674
678
|
}
|
|
675
679
|
|
|
676
680
|
// All other cases
|
|
677
|
-
(0, _endChat.prepareEndChat)(props,
|
|
681
|
+
(0, _endChat.prepareEndChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
|
|
678
682
|
}, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
|
|
679
683
|
|
|
680
684
|
// Publish chat widget state
|
|
@@ -707,13 +711,13 @@ const LiveChatWidgetStateful = props => {
|
|
|
707
711
|
|
|
708
712
|
// Handle Chat disconnect cases
|
|
709
713
|
(0, _react2.useEffect)(() => {
|
|
710
|
-
var _inMemoryState$
|
|
714
|
+
var _inMemoryState$appSta6;
|
|
711
715
|
const inMemoryState = (0, _createReducer.executeReducer)(state, {
|
|
712
716
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
713
717
|
payload: null
|
|
714
718
|
});
|
|
715
719
|
(0, _chatDisconnectHelper.handleChatDisconnect)(props, inMemoryState, setWebChatStyles);
|
|
716
|
-
const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$
|
|
720
|
+
const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta6 = inMemoryState.appStates) === null || _inMemoryState$appSta6 === void 0 ? void 0 : _inMemoryState$appSta6.chatDisconnectEventReceived;
|
|
717
721
|
if (chatDisconnectState && adapter) {
|
|
718
722
|
try {
|
|
719
723
|
adapter.end();
|
|
@@ -745,7 +749,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
745
749
|
Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
|
|
746
750
|
Description: _Constants.PrepareEndChatDescriptionConstants.BrowserUnload
|
|
747
751
|
});
|
|
748
|
-
(0, _endChat.endChat)(props,
|
|
752
|
+
(0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, false);
|
|
749
753
|
// Clean local storage
|
|
750
754
|
(_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventId);
|
|
751
755
|
|
|
@@ -758,16 +762,16 @@ const LiveChatWidgetStateful = props => {
|
|
|
758
762
|
eventName: _TelemetryConstants.BroadcastEvent.ClosePopoutWindow
|
|
759
763
|
});
|
|
760
764
|
};
|
|
761
|
-
const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
765
|
+
const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
|
|
762
766
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
763
|
-
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props,
|
|
764
|
-
const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props,
|
|
767
|
+
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
|
|
768
|
+
const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, facadeChatSDK, state, dispatch, setAdapter);
|
|
765
769
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
766
|
-
const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(
|
|
770
|
+
const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
767
771
|
const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
|
|
768
772
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
769
|
-
const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props,
|
|
770
|
-
const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, state, dispatch,
|
|
773
|
+
const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
|
|
774
|
+
const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, state, dispatch, facadeChatSDK, endChatRelay);
|
|
771
775
|
const downloadTranscriptProps = (0, _createDownloadTranscriptProps.default)(props.downloadTranscriptProps, {
|
|
772
776
|
...(_defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps === null || _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps === void 0 ? void 0 : _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.webChatStyles),
|
|
773
777
|
...((_props$webChatContain8 = props.webChatContainerProps) === null || _props$webChatContain8 === void 0 ? void 0 : _props$webChatContain8.webChatStyles)
|
|
@@ -793,7 +797,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
793
797
|
};
|
|
794
798
|
|
|
795
799
|
// Add 'omnichannel-chat-widget' OC User Agent if not already set
|
|
796
|
-
(0, _utils.setOcUserAgent)(
|
|
800
|
+
(0, _utils.setOcUserAgent)(facadeChatSDK.getChatSDK());
|
|
797
801
|
const directLine = ((_livechatProps$webCha = livechatProps.webChatContainerProps) === null || _livechatProps$webCha === void 0 ? void 0 : _livechatProps$webCha.directLine) ?? adapter ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.directLine;
|
|
798
802
|
const userID = directLine.getState ? directLine === null || directLine === void 0 ? void 0 : directLine.getState("acs.userId") : "teamsvisitor";
|
|
799
803
|
|