@microsoft/omnichannel-chat-widget 1.7.4-main.f0f5d34 → 1.7.4
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 +7 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +12 -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 +15 -13
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -0
- 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 +40 -30
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +10 -6
- 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 +54 -39
- 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 +63 -40
- 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/WebChatContainerStateful.js +11 -6
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +8 -0
- 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 +7 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +12 -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 +15 -13
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/esm/components/headerstateful/HeaderStateful.js +4 -0
- 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 +40 -30
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +10 -6
- 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 +55 -40
- 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 +63 -40
- 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/WebChatContainerStateful.js +11 -6
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/notification/NotificationHandler.js +8 -0
- 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 +9 -2
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +7 -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/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +1 -0
- 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 +4 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import { Constants, LiveWorkItemState, WidgetLoadCustomErrorString, WidgetLoadTelemetryMessage } from "../../../common/Constants";
|
|
3
|
-
import { checkContactIdError, createTimer, getConversationDetailsCall, getStateFromCache, getWidgetCacheIdfromProps, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
3
|
+
import { checkContactIdError, createTimer, getConversationDetailsCall, getStateFromCache, getWidgetCacheIdfromProps, isNullOrEmptyString, isNullOrUndefined, isUndefinedOrEmpty } from "../../../common/utils";
|
|
4
4
|
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
5
5
|
import { handleChatReconnect, isPersistentEnabled, isReconnectEnabled } from "./reconnectChatHelper";
|
|
6
6
|
import { handleStartChatError, logWidgetLoadComplete } from "./startChatErrorHandler";
|
|
@@ -26,27 +26,27 @@ let widgetInstanceId;
|
|
|
26
26
|
let popoutWidgetInstanceId;
|
|
27
27
|
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
const setAuthenticationIfApplicable = async (props,
|
|
29
|
+
const setAuthenticationIfApplicable = async (props, facadeChatSDK) => {
|
|
30
30
|
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
31
31
|
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
32
32
|
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
33
33
|
if (getAuthToken && authClientFunction) {
|
|
34
34
|
// set auth token to chat sdk before start chat
|
|
35
|
-
const authSuccess = await handleAuthentication(
|
|
36
|
-
if (!authSuccess) {
|
|
35
|
+
const authSuccess = await handleAuthentication(facadeChatSDK.getChatSDK(), chatConfig, getAuthToken);
|
|
36
|
+
if (!authSuccess.result) {
|
|
37
37
|
throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
const prepareStartChat = async (props,
|
|
43
|
+
const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
44
44
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
45
45
|
widgetInstanceId = getWidgetCacheIdfromProps(props);
|
|
46
46
|
|
|
47
47
|
// reconnect > chat from cache
|
|
48
48
|
if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
|
|
49
|
-
const shouldStartChatNormally = await handleChatReconnect(
|
|
49
|
+
const shouldStartChatNormally = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
50
50
|
if (!shouldStartChatNormally) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
@@ -58,7 +58,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Can connect to existing chat session
|
|
61
|
-
if (await canConnectToExistingChat(props,
|
|
61
|
+
if (await canConnectToExistingChat(props, facadeChatSDK, state, dispatch, setAdapter)) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -68,26 +68,30 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
68
68
|
|
|
69
69
|
// Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
|
|
70
70
|
if (isPersistentEnabled(props.chatConfig)) {
|
|
71
|
-
await setAuthenticationIfApplicable(props,
|
|
71
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
//Setting PreChat and intiate chat
|
|
75
|
-
await setPreChatAndInitiateChat(
|
|
75
|
+
await setPreChatAndInitiateChat(facadeChatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
const setPreChatAndInitiateChat = async (
|
|
79
|
+
const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
80
80
|
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
|
|
81
|
-
//
|
|
81
|
+
// This reset needs to be done before to load prechat, because the conversation state changes from close to prechat
|
|
82
|
+
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
|
|
83
|
+
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
84
|
+
chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
|
|
85
|
+
}
|
|
82
86
|
|
|
83
87
|
// Getting prechat Survey Context
|
|
84
88
|
const parseToJson = false;
|
|
85
|
-
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
|
|
89
|
+
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));
|
|
86
90
|
let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
|
|
87
|
-
showPrechat = await shouldSetPreChatIfPersistentChat(
|
|
91
|
+
showPrechat = await 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);
|
|
88
92
|
if (showPrechat) {
|
|
89
93
|
var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
|
|
90
|
-
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";
|
|
94
|
+
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";
|
|
91
95
|
if (isOutOfOperatingHours) {
|
|
92
96
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
93
97
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -100,6 +104,9 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
100
104
|
return;
|
|
101
105
|
} else {
|
|
102
106
|
var _state$appStates;
|
|
107
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
108
|
+
Event: TelemetryEvent.PrechatSurveyExpected
|
|
109
|
+
});
|
|
103
110
|
dispatch({
|
|
104
111
|
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
105
112
|
payload: preChatSurveyResponse
|
|
@@ -138,17 +145,17 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
138
145
|
const optionalParams = {
|
|
139
146
|
isProactiveChat
|
|
140
147
|
};
|
|
141
|
-
await initStartChat(
|
|
148
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
142
149
|
};
|
|
143
150
|
|
|
144
151
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
-
const initStartChat = async (
|
|
152
|
+
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
146
153
|
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
147
154
|
let isStartChatSuccessful = false;
|
|
148
155
|
const persistentChatEnabled = await 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);
|
|
149
156
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
|
|
150
157
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
151
|
-
chatSDKStateCleanUp(
|
|
158
|
+
chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
|
|
152
159
|
}
|
|
153
160
|
try {
|
|
154
161
|
var _state$appStates2;
|
|
@@ -166,7 +173,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
166
173
|
});
|
|
167
174
|
|
|
168
175
|
// Auth token retrieval needs to happen during start chat to support pop-out chat
|
|
169
|
-
await setAuthenticationIfApplicable(props,
|
|
176
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
170
177
|
|
|
171
178
|
//Check if chat retrieved from cache
|
|
172
179
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -189,7 +196,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
189
196
|
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
|
|
190
197
|
};
|
|
191
198
|
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
192
|
-
await
|
|
199
|
+
await facadeChatSDK.startChat(startChatOptionalParams);
|
|
193
200
|
isStartChatSuccessful = true;
|
|
194
201
|
} catch (error) {
|
|
195
202
|
checkContactIdError(error);
|
|
@@ -199,10 +206,16 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
199
206
|
exception: `Failed to setup startChat: ${error}`
|
|
200
207
|
}
|
|
201
208
|
});
|
|
209
|
+
BroadcastService.postMessage({
|
|
210
|
+
eventName: BroadcastEvent.OnWidgetError,
|
|
211
|
+
payload: {
|
|
212
|
+
errorMessage: error
|
|
213
|
+
}
|
|
214
|
+
});
|
|
202
215
|
isStartChatSuccessful = false;
|
|
203
216
|
throw error;
|
|
204
217
|
}
|
|
205
|
-
await createAdapterAndSubscribe(
|
|
218
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
206
219
|
|
|
207
220
|
// Set app state to Active
|
|
208
221
|
if (isStartChatSuccessful) {
|
|
@@ -224,14 +237,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
224
237
|
});
|
|
225
238
|
logWidgetLoadComplete(WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
226
239
|
// Set post chat context in state, load in background to do not block the load
|
|
227
|
-
setPostChatContextAndLoadSurvey(
|
|
240
|
+
setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch, true);
|
|
228
241
|
return;
|
|
229
242
|
}
|
|
230
243
|
|
|
231
244
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
232
245
|
if (!persistentChatEnabled) {
|
|
233
246
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
|
-
const liveChatContext = await (
|
|
247
|
+
const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
|
|
235
248
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
236
249
|
dispatch({
|
|
237
250
|
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -240,11 +253,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
240
253
|
}
|
|
241
254
|
logWidgetLoadComplete();
|
|
242
255
|
// Set post chat context in state, load in background to do not block the load
|
|
243
|
-
setPostChatContextAndLoadSurvey(
|
|
256
|
+
setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch);
|
|
244
257
|
// Updating chat session detail for telemetry
|
|
245
|
-
await updateTelemetryData(
|
|
258
|
+
await updateTelemetryData(facadeChatSDK, dispatch);
|
|
246
259
|
} catch (ex) {
|
|
247
|
-
handleStartChatError(dispatch,
|
|
260
|
+
handleStartChatError(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
248
261
|
} finally {
|
|
249
262
|
optionalParams = {};
|
|
250
263
|
widgetInstanceId = "";
|
|
@@ -252,20 +265,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
252
265
|
};
|
|
253
266
|
|
|
254
267
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
|
-
const createAdapterAndSubscribe = async (
|
|
256
|
-
var _newAdapter$activity$;
|
|
268
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
257
269
|
// New adapter creation
|
|
258
|
-
const newAdapter = await createAdapter(
|
|
270
|
+
const newAdapter = await createAdapter(facadeChatSDK, props);
|
|
259
271
|
setAdapter(newAdapter);
|
|
260
|
-
const chatToken = await
|
|
272
|
+
const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
|
|
261
273
|
dispatch({
|
|
262
274
|
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
263
275
|
payload: chatToken
|
|
264
276
|
});
|
|
265
|
-
|
|
277
|
+
if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
|
|
278
|
+
var _newAdapter$activity$;
|
|
279
|
+
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken.chatId, chatToken.visitorId));
|
|
280
|
+
}
|
|
266
281
|
};
|
|
267
282
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
|
-
const canConnectToExistingChat = async (props,
|
|
283
|
+
const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
269
284
|
var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
|
|
270
285
|
// By pass this function in case of popout chat
|
|
271
286
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.hideStartChatButton) === true) {
|
|
@@ -283,7 +298,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
283
298
|
const optionalParams = {
|
|
284
299
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
285
300
|
};
|
|
286
|
-
await initStartChat(
|
|
301
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
287
302
|
return true;
|
|
288
303
|
}
|
|
289
304
|
return false;
|
|
@@ -348,29 +363,29 @@ const canStartPopoutChat = async props => {
|
|
|
348
363
|
};
|
|
349
364
|
|
|
350
365
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
351
|
-
const checkIfConversationStillValid = async (
|
|
366
|
+
const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
|
|
352
367
|
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
353
368
|
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;
|
|
354
369
|
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
355
370
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
356
371
|
let conversationDetails = undefined;
|
|
357
372
|
// Preserve current requestId
|
|
358
|
-
const currentRequestId =
|
|
373
|
+
const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
|
|
359
374
|
dispatch({
|
|
360
375
|
type: LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
361
376
|
payload: currentRequestId
|
|
362
377
|
});
|
|
363
378
|
try {
|
|
364
|
-
|
|
365
|
-
conversationDetails = await getConversationDetailsCall(
|
|
366
|
-
if (Object.keys(conversationDetails).length === 0) {
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
if (conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
379
|
+
facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
|
|
380
|
+
conversationDetails = await getConversationDetailsCall(facadeChatSDK, liveChatContext);
|
|
381
|
+
if (Object.keys(conversationDetails).length === 0 || isNullOrUndefined(conversationDetails.state) || conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
370
382
|
dispatch({
|
|
371
383
|
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
372
384
|
payload: undefined
|
|
373
385
|
});
|
|
386
|
+
if (currentRequestId) {
|
|
387
|
+
facadeChatSDK.getChatSDK().requestId = currentRequestId;
|
|
388
|
+
}
|
|
374
389
|
return false;
|
|
375
390
|
}
|
|
376
391
|
return true;
|
|
@@ -11,7 +11,7 @@ import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
|
11
11
|
import { getWidgetCacheIdfromProps } from "../../../common/utils";
|
|
12
12
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
export const handleStartChatError = (dispatch,
|
|
14
|
+
export const handleStartChatError = (dispatch, facadeChatSDK, props, ex, isStartChatSuccessful) => {
|
|
15
15
|
var _props$controlProps;
|
|
16
16
|
if (!ex) {
|
|
17
17
|
logWidgetLoadFailed();
|
|
@@ -59,7 +59,7 @@ export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSu
|
|
|
59
59
|
break;
|
|
60
60
|
case ChatSDKErrorName.InvalidConversation:
|
|
61
61
|
case ChatSDKErrorName.ClosedConversation:
|
|
62
|
-
handleInvalidOrClosedConversation(dispatch,
|
|
62
|
+
handleInvalidOrClosedConversation(dispatch, facadeChatSDK, props, ex);
|
|
63
63
|
return;
|
|
64
64
|
default:
|
|
65
65
|
logWidgetLoadFailed(ex);
|
|
@@ -94,7 +94,7 @@ export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSu
|
|
|
94
94
|
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
95
95
|
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
96
96
|
if (isStartChatSuccessful === true) {
|
|
97
|
-
forceEndChat(
|
|
97
|
+
forceEndChat(facadeChatSDK);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
const logWidgetLoadFailed = ex => {
|
|
@@ -142,7 +142,7 @@ const logWidgetLoadCompleteWithError = ex => {
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
-
const forceEndChat =
|
|
145
|
+
const forceEndChat = facadeChatSDK => {
|
|
146
146
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
147
147
|
Event: TelemetryEvent.PrepareEndChat,
|
|
148
148
|
Description: PrepareEndChatDescriptionConstants.WidgetLoadFailedAfterSessionInit
|
|
@@ -150,7 +150,7 @@ const forceEndChat = chatSDK => {
|
|
|
150
150
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
151
151
|
Event: TelemetryEvent.EndChatSDKCall
|
|
152
152
|
});
|
|
153
|
-
|
|
153
|
+
facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatSDK().endChat();
|
|
154
154
|
};
|
|
155
155
|
const handleWidgetUseOutsideOperatingHour = dispatch => {
|
|
156
156
|
dispatch({
|
|
@@ -203,7 +203,7 @@ const handleUninitializedChatSDK = ex => {
|
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
-
const handleInvalidOrClosedConversation = (dispatch,
|
|
206
|
+
const handleInvalidOrClosedConversation = (dispatch, facadeChatSDK, props, ex) => {
|
|
207
207
|
var _DataStoreManager$cli;
|
|
208
208
|
logWidgetLoadCompleteWithError(ex);
|
|
209
209
|
|
|
@@ -211,7 +211,7 @@ const handleInvalidOrClosedConversation = (dispatch, chatSDK, props, ex) => {
|
|
|
211
211
|
callingStateCleanUp(dispatch);
|
|
212
212
|
endChatStateCleanUp(dispatch);
|
|
213
213
|
closeChatStateCleanUp(dispatch);
|
|
214
|
-
chatSDKStateCleanUp(
|
|
214
|
+
chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
|
|
215
215
|
(_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(getWidgetCacheIdfromProps(props));
|
|
216
216
|
|
|
217
217
|
// Starts new chat
|
|
@@ -6,16 +6,16 @@ import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
|
|
|
6
6
|
import { getConversationDetailsCall } from "../../../common/utils";
|
|
7
7
|
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
export const updateTelemetryData = async (
|
|
9
|
+
export const updateTelemetryData = async (facadeChatSDK, dispatch) => {
|
|
10
10
|
// load it concurrently, this will reduce the load time
|
|
11
|
-
await Promise.all([updateSessionDataForTelemetry(
|
|
11
|
+
await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch), updateConversationDataForTelemetry(facadeChatSDK, dispatch)]);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
const updateSessionDataForTelemetry = async (
|
|
16
|
-
if (
|
|
15
|
+
const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
16
|
+
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
const chatSession = await
|
|
18
|
+
const chatSession = await facadeChatSDK.getCurrentLiveChatContext();
|
|
19
19
|
const telemetryData = TelemetryHelper.addSessionDataToTelemetry(chatSession, TelemetryManager.InternalTelemetryData);
|
|
20
20
|
dispatch({
|
|
21
21
|
type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|
|
@@ -31,10 +31,10 @@ const updateSessionDataForTelemetry = async (chatSDK, dispatch) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
const updateConversationDataForTelemetry = async (
|
|
35
|
-
if (
|
|
34
|
+
const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch) => {
|
|
35
|
+
if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
const liveWorkItem = await getConversationDetailsCall(
|
|
37
|
+
const liveWorkItem = await getConversationDetailsCall(facadeChatSDK);
|
|
38
38
|
const telemetryData = TelemetryHelper.addConversationDataToTelemetry(liveWorkItem, TelemetryManager.InternalTelemetryData);
|
|
39
39
|
dispatch({
|
|
40
40
|
type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|