@microsoft/omnichannel-chat-widget 1.7.4-main.f0f5d34 → 1.7.5-main.290ba08
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 +15 -11
- 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/attachmentMiddleware.js +2 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/index.js +115 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +3 -4
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +3 -4
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/toastMiddleware.js +2 -3
- 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 +34 -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 +12 -8
- 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/attachmentMiddleware.js +2 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/index.js +10 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +2 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +2 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/toastMiddleware.js +2 -3
- 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 +6 -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/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.d.ts +1 -2
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/index.d.ts +10 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.d.ts +1 -2
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +1 -2
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/toastMiddleware.d.ts +1 -2
- package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
- package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
- package/lib/types/index.d.ts +5 -3
- package/lib/types/plugins/createChatTranscript.d.ts +2 -1
- package/package.json +4 -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);
|
|
@@ -206,10 +213,16 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
206
213
|
exception: `Failed to setup startChat: ${error}`
|
|
207
214
|
}
|
|
208
215
|
});
|
|
216
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
217
|
+
eventName: _TelemetryConstants.BroadcastEvent.OnWidgetError,
|
|
218
|
+
payload: {
|
|
219
|
+
errorMessage: error
|
|
220
|
+
}
|
|
221
|
+
});
|
|
209
222
|
isStartChatSuccessful = false;
|
|
210
223
|
throw error;
|
|
211
224
|
}
|
|
212
|
-
await createAdapterAndSubscribe(
|
|
225
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
213
226
|
|
|
214
227
|
// Set app state to Active
|
|
215
228
|
if (isStartChatSuccessful) {
|
|
@@ -231,14 +244,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
231
244
|
});
|
|
232
245
|
(0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
233
246
|
// Set post chat context in state, load in background to do not block the load
|
|
234
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
247
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch, true);
|
|
235
248
|
return;
|
|
236
249
|
}
|
|
237
250
|
|
|
238
251
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
239
252
|
if (!persistentChatEnabled) {
|
|
240
253
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
241
|
-
const liveChatContext = await (
|
|
254
|
+
const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
|
|
242
255
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
256
|
dispatch({
|
|
244
257
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -247,11 +260,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
247
260
|
}
|
|
248
261
|
(0, _startChatErrorHandler.logWidgetLoadComplete)();
|
|
249
262
|
// Set post chat context in state, load in background to do not block the load
|
|
250
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(
|
|
263
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(facadeChatSDK, dispatch);
|
|
251
264
|
// Updating chat session detail for telemetry
|
|
252
|
-
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(
|
|
265
|
+
await (0, _updateSessionDataForTelemetry.updateTelemetryData)(facadeChatSDK, dispatch);
|
|
253
266
|
} catch (ex) {
|
|
254
|
-
(0, _startChatErrorHandler.handleStartChatError)(dispatch,
|
|
267
|
+
(0, _startChatErrorHandler.handleStartChatError)(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
255
268
|
} finally {
|
|
256
269
|
optionalParams = {};
|
|
257
270
|
widgetInstanceId = "";
|
|
@@ -260,20 +273,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
260
273
|
|
|
261
274
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
262
275
|
exports.initStartChat = initStartChat;
|
|
263
|
-
const createAdapterAndSubscribe = async (
|
|
264
|
-
var _newAdapter$activity$;
|
|
276
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
265
277
|
// New adapter creation
|
|
266
|
-
const newAdapter = await (0, _createAdapter.createAdapter)(
|
|
278
|
+
const newAdapter = await (0, _createAdapter.createAdapter)(facadeChatSDK, props);
|
|
267
279
|
setAdapter(newAdapter);
|
|
268
|
-
const chatToken = await
|
|
280
|
+
const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
|
|
269
281
|
dispatch({
|
|
270
282
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
271
283
|
payload: chatToken
|
|
272
284
|
});
|
|
273
|
-
|
|
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
|
+
}
|
|
274
289
|
};
|
|
275
290
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
-
const canConnectToExistingChat = async (props,
|
|
291
|
+
const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
277
292
|
var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
|
|
278
293
|
// By pass this function in case of popout chat
|
|
279
294
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.hideStartChatButton) === true) {
|
|
@@ -291,7 +306,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
291
306
|
const optionalParams = {
|
|
292
307
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
293
308
|
};
|
|
294
|
-
await initStartChat(
|
|
309
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
295
310
|
return true;
|
|
296
311
|
}
|
|
297
312
|
return false;
|
|
@@ -356,29 +371,29 @@ const canStartPopoutChat = async props => {
|
|
|
356
371
|
};
|
|
357
372
|
|
|
358
373
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
|
-
const checkIfConversationStillValid = async (
|
|
374
|
+
const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
|
|
360
375
|
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
361
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;
|
|
362
377
|
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
363
378
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
364
379
|
let conversationDetails = undefined;
|
|
365
380
|
// Preserve current requestId
|
|
366
|
-
const currentRequestId =
|
|
381
|
+
const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
|
|
367
382
|
dispatch({
|
|
368
383
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
369
384
|
payload: currentRequestId
|
|
370
385
|
});
|
|
371
386
|
try {
|
|
372
|
-
|
|
373
|
-
conversationDetails = await (0, _utils.getConversationDetailsCall)(
|
|
374
|
-
if (Object.keys(conversationDetails).length === 0) {
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
387
|
+
facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
|
|
388
|
+
conversationDetails = await (0, _utils.getConversationDetailsCall)(facadeChatSDK, liveChatContext);
|
|
389
|
+
if (Object.keys(conversationDetails).length === 0 || (0, _utils.isNullOrUndefined)(conversationDetails.state) || conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
378
390
|
dispatch({
|
|
379
391
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
380
392
|
payload: undefined
|
|
381
393
|
});
|
|
394
|
+
if (currentRequestId) {
|
|
395
|
+
facadeChatSDK.getChatSDK().requestId = currentRequestId;
|
|
396
|
+
}
|
|
382
397
|
return false;
|
|
383
398
|
}
|
|
384
399
|
return true;
|
|
@@ -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,
|