@microsoft/omnichannel-chat-widget 1.7.4-main.120159a → 1.7.4-main.1f61ac6
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 +6 -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 +2 -2
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
- 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 +45 -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/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- 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 +6 -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 +2 -2
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -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 +45 -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/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- 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 +7 -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/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/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +1 -0
- 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 +2 -2
|
@@ -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,
|
|
@@ -106,6 +110,9 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
106
110
|
return;
|
|
107
111
|
} else {
|
|
108
112
|
var _state$appStates;
|
|
113
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
114
|
+
Event: _TelemetryConstants.TelemetryEvent.PrechatSurveyExpected
|
|
115
|
+
});
|
|
109
116
|
dispatch({
|
|
110
117
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
111
118
|
payload: preChatSurveyResponse
|
|
@@ -144,18 +151,18 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
144
151
|
const optionalParams = {
|
|
145
152
|
isProactiveChat
|
|
146
153
|
};
|
|
147
|
-
await initStartChat(
|
|
154
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
148
155
|
};
|
|
149
156
|
|
|
150
157
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
158
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
152
|
-
const initStartChat = async (
|
|
159
|
+
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
153
160
|
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
154
161
|
let isStartChatSuccessful = false;
|
|
155
162
|
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
163
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
|
|
157
164
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
158
|
-
(0, _endChat.chatSDKStateCleanUp)(
|
|
165
|
+
(0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
|
|
159
166
|
}
|
|
160
167
|
try {
|
|
161
168
|
var _state$appStates2;
|
|
@@ -173,7 +180,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
173
180
|
});
|
|
174
181
|
|
|
175
182
|
// Auth token retrieval needs to happen during start chat to support pop-out chat
|
|
176
|
-
await setAuthenticationIfApplicable(props,
|
|
183
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
177
184
|
|
|
178
185
|
//Check if chat retrieved from cache
|
|
179
186
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -196,7 +203,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
196
203
|
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
204
|
};
|
|
198
205
|
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
199
|
-
await
|
|
206
|
+
await facadeChatSDK.startChat(startChatOptionalParams);
|
|
200
207
|
isStartChatSuccessful = true;
|
|
201
208
|
} catch (error) {
|
|
202
209
|
(0, _utils.checkContactIdError)(error);
|
|
@@ -215,7 +222,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
215
222
|
isStartChatSuccessful = false;
|
|
216
223
|
throw error;
|
|
217
224
|
}
|
|
218
|
-
await createAdapterAndSubscribe(
|
|
225
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
219
226
|
|
|
220
227
|
// Set app state to Active
|
|
221
228
|
if (isStartChatSuccessful) {
|
|
@@ -237,14 +244,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
237
244
|
});
|
|
238
245
|
(0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
239
246
|
// Set post chat context in state, load in background to do not block the load
|
|
240
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
247
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch, true);
|
|
241
248
|
return;
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
245
252
|
if (!persistentChatEnabled) {
|
|
246
253
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
247
|
-
const liveChatContext = await (
|
|
254
|
+
const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
|
|
248
255
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
256
|
dispatch({
|
|
250
257
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -253,11 +260,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
253
260
|
}
|
|
254
261
|
(0, _startChatErrorHandler.logWidgetLoadComplete)();
|
|
255
262
|
// Set post chat context in state, load in background to do not block the load
|
|
256
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
263
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
|
|
257
264
|
// Updating chat session detail for telemetry
|
|
258
|
-
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(
|
|
265
|
+
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(facadeChatSDK, dispatch);
|
|
259
266
|
} catch (ex) {
|
|
260
|
-
(0, _startChatErrorHandler.handleStartChatError)(dispatch,
|
|
267
|
+
(0, _startChatErrorHandler.handleStartChatError)(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
261
268
|
} finally {
|
|
262
269
|
optionalParams = {};
|
|
263
270
|
widgetInstanceId = "";
|
|
@@ -266,20 +273,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
266
273
|
|
|
267
274
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
275
|
exports.initStartChat = initStartChat;
|
|
269
|
-
const createAdapterAndSubscribe = async (
|
|
270
|
-
var _newAdapter$activity$;
|
|
276
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
271
277
|
// New adapter creation
|
|
272
|
-
const newAdapter = await (0, _createAdapter.createAdapter)(
|
|
278
|
+
const newAdapter = await (0, _createAdapter.createAdapter)(facadeChatSDK, props);
|
|
273
279
|
setAdapter(newAdapter);
|
|
274
|
-
const chatToken = await
|
|
280
|
+
const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
|
|
275
281
|
dispatch({
|
|
276
282
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
277
283
|
payload: chatToken
|
|
278
284
|
});
|
|
279
|
-
|
|
285
|
+
if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
|
|
286
|
+
var _newAdapter$activity$;
|
|
287
|
+
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));
|
|
288
|
+
}
|
|
280
289
|
};
|
|
281
290
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
|
-
const canConnectToExistingChat = async (props,
|
|
291
|
+
const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
283
292
|
var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
|
|
284
293
|
// By pass this function in case of popout chat
|
|
285
294
|
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 +306,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
297
306
|
const optionalParams = {
|
|
298
307
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
299
308
|
};
|
|
300
|
-
await initStartChat(
|
|
309
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
301
310
|
return true;
|
|
302
311
|
}
|
|
303
312
|
return false;
|
|
@@ -362,28 +371,28 @@ const canStartPopoutChat = async props => {
|
|
|
362
371
|
};
|
|
363
372
|
|
|
364
373
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
-
const checkIfConversationStillValid = async (
|
|
374
|
+
const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
|
|
366
375
|
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
367
376
|
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
377
|
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
369
378
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
370
379
|
let conversationDetails = undefined;
|
|
371
380
|
// Preserve current requestId
|
|
372
|
-
const currentRequestId =
|
|
381
|
+
const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
|
|
373
382
|
dispatch({
|
|
374
383
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
375
384
|
payload: currentRequestId
|
|
376
385
|
});
|
|
377
386
|
try {
|
|
378
|
-
|
|
379
|
-
conversationDetails = await (0, _utils.getConversationDetailsCall)(
|
|
387
|
+
facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
|
|
388
|
+
conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK, liveChatContext);
|
|
380
389
|
if (Object.keys(conversationDetails).length === 0 || (0, _utils.isNullOrUndefined)(conversationDetails.state) || conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
381
390
|
dispatch({
|
|
382
391
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
383
392
|
payload: undefined
|
|
384
393
|
});
|
|
385
394
|
if (currentRequestId) {
|
|
386
|
-
|
|
395
|
+
facadeChatSDK.getChatSDK().requestId = currentRequestId;
|
|
387
396
|
}
|
|
388
397
|
return false;
|
|
389
398
|
}
|
|
@@ -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,
|