@microsoft/omnichannel-chat-widget 1.7.2 → 1.7.3-main.7a38853
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/components/livechatwidget/common/liveChatConfigUtils.js +11 -2
- package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +28 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +27 -18
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +5 -1
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +9 -0
- package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +22 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +27 -18
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +5 -1
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -0
- package/package.json +1 -1
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isPostChatSurveyEnabled = void 0;
|
|
6
|
+
exports.isPostChatSurveyEnabled = exports.isPersistentChatEnabled = void 0;
|
|
7
|
+
var _Constants = require("../../../common/Constants");
|
|
8
|
+
var _utils = require("../../../common/utils");
|
|
7
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
10
|
const isPostChatSurveyEnabled = async chatSDK => {
|
|
9
11
|
var _chatConfig$LiveWSAnd;
|
|
@@ -11,4 +13,11 @@ const isPostChatSurveyEnabled = async chatSDK => {
|
|
|
11
13
|
const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
|
|
12
14
|
return postChatEnabled === "true";
|
|
13
15
|
};
|
|
14
|
-
exports.isPostChatSurveyEnabled = isPostChatSurveyEnabled;
|
|
16
|
+
exports.isPostChatSurveyEnabled = isPostChatSurveyEnabled;
|
|
17
|
+
const isPersistentChatEnabled = async conversationMode => {
|
|
18
|
+
if ((0, _utils.isNullOrUndefined)(conversationMode)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString().toLowerCase()) === _Constants.ConversationMode.Persistent;
|
|
22
|
+
};
|
|
23
|
+
exports.isPersistentChatEnabled = isPersistentChatEnabled;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shouldSetPreChatIfPersistentChat = void 0;
|
|
7
|
+
var _liveChatConfigUtils = require("./liveChatConfigUtils");
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
const shouldSetPreChatIfPersistentChat = async (chatSDK, conversationMode, showPreChat) => {
|
|
10
|
+
const persistentEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(conversationMode);
|
|
11
|
+
let skipPreChat = false;
|
|
12
|
+
if (persistentEnabled) {
|
|
13
|
+
const reconnectableChatsParams = {
|
|
14
|
+
authenticatedUserToken: chatSDK.authenticatedUserToken
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const reconnectableChatsResponse = await chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams);
|
|
18
|
+
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
|
19
|
+
// Skip rendering prechat on existing persistent chat session
|
|
20
|
+
skipPreChat = true;
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// eslint-disable-line no-empty
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return showPreChat && !skipPreChat;
|
|
27
|
+
};
|
|
28
|
+
exports.shouldSetPreChatIfPersistentChat = shouldSetPreChatIfPersistentChat;
|
|
@@ -21,6 +21,8 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
|
|
|
21
21
|
var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
|
|
22
22
|
var _startChatErrorHandler = require("./startChatErrorHandler");
|
|
23
23
|
var _endChat = require("./endChat");
|
|
24
|
+
var _liveChatConfigUtils = require("./liveChatConfigUtils");
|
|
25
|
+
var _persistentChatHelper = require("./persistentChatHelper");
|
|
24
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
27
|
let optionalParams = {};
|
|
26
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -61,16 +63,17 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
61
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
64
|
exports.prepareStartChat = prepareStartChat;
|
|
63
65
|
const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
64
|
-
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps;
|
|
66
|
+
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
|
|
65
67
|
//Handle reconnect scenario
|
|
66
68
|
|
|
67
69
|
// Getting prechat Survey Context
|
|
68
70
|
const parseToJson = false;
|
|
69
71
|
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 chatSDK.getPreChatSurvey(parseToJson));
|
|
70
|
-
|
|
72
|
+
let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
|
|
73
|
+
showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(chatSDK, 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);
|
|
71
74
|
if (showPrechat) {
|
|
72
|
-
var _state$
|
|
73
|
-
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$
|
|
75
|
+
var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
|
|
76
|
+
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";
|
|
74
77
|
if (isOutOfOperatingHours) {
|
|
75
78
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
76
79
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -94,7 +97,7 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
94
97
|
|
|
95
98
|
// If minimized, maximize the chat, if the state is missing, consider it as minimized
|
|
96
99
|
if ((state === null || state === void 0 ? void 0 : state.appStates.isMinimized) == undefined || (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.isMinimized) === true) {
|
|
97
|
-
var _state$
|
|
100
|
+
var _state$domainStates3, _state$domainStates3$, _state$domainStates4, _state$domainStates4$;
|
|
98
101
|
dispatch({
|
|
99
102
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
100
103
|
payload: false
|
|
@@ -104,8 +107,8 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
104
107
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
105
108
|
eventName: _TelemetryConstants.BroadcastEvent.MaximizeChat,
|
|
106
109
|
payload: {
|
|
107
|
-
height: state === null || state === void 0 ? void 0 : (_state$
|
|
108
|
-
width: state === null || state === void 0 ? void 0 : (_state$
|
|
110
|
+
height: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.height,
|
|
111
|
+
width: state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.widgetSize) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.width
|
|
109
112
|
}
|
|
110
113
|
});
|
|
111
114
|
}
|
|
@@ -127,9 +130,11 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
127
130
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
131
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
129
132
|
const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
133
|
+
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
130
134
|
let isStartChatSuccessful = false;
|
|
131
135
|
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
132
136
|
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
137
|
+
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);
|
|
133
138
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
|
|
134
139
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
135
140
|
(0, _endChat.chatSDKStateCleanUp)(chatSDK);
|
|
@@ -227,10 +232,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
227
232
|
|
|
228
233
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
234
|
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
|
|
236
|
+
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
237
|
+
if (!persistentChatEnabled) {
|
|
238
|
+
dispatch({
|
|
239
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
240
|
+
payload: liveChatContext
|
|
241
|
+
});
|
|
242
|
+
}
|
|
234
243
|
(0, _startChatErrorHandler.logWidgetLoadComplete)();
|
|
235
244
|
// Set post chat context in state
|
|
236
245
|
// Commenting this for now as post chat context is fetched during end chat
|
|
@@ -274,17 +283,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
274
283
|
|
|
275
284
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
285
|
const setCustomContextParams = async (state, props) => {
|
|
277
|
-
var _props$chatConfig, _props$chatConfig$Liv, _state$
|
|
286
|
+
var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates6, _persistedState$domai8;
|
|
278
287
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
288
|
const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
|
|
280
289
|
//Should not set custom context for auth chat
|
|
281
290
|
if (isAuthenticatedChat) {
|
|
282
291
|
return;
|
|
283
292
|
}
|
|
284
|
-
if (state !== null && state !== void 0 && (_state$
|
|
285
|
-
var _state$
|
|
293
|
+
if (state !== null && state !== void 0 && (_state$domainStates6 = state.domainStates) !== null && _state$domainStates6 !== void 0 && _state$domainStates6.customContext) {
|
|
294
|
+
var _state$domainStates7;
|
|
286
295
|
optionalParams = Object.assign({}, optionalParams, {
|
|
287
|
-
customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$
|
|
296
|
+
customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.customContext))
|
|
288
297
|
});
|
|
289
298
|
return;
|
|
290
299
|
}
|
|
@@ -332,9 +341,9 @@ const canStartPopoutChat = async props => {
|
|
|
332
341
|
|
|
333
342
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
343
|
const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
|
|
335
|
-
var _state$
|
|
336
|
-
const requestIdFromCache = (_state$
|
|
337
|
-
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$
|
|
344
|
+
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
345
|
+
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;
|
|
346
|
+
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
338
347
|
|
|
339
348
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
340
349
|
let conversationDetails = undefined;
|
|
@@ -66,9 +66,13 @@ class MockChatSDK {
|
|
|
66
66
|
getLiveChatConfig() {
|
|
67
67
|
return {
|
|
68
68
|
LiveWSAndLiveChatEngJoin: {
|
|
69
|
-
msdyn_postconversationsurveyenable: "true"
|
|
69
|
+
msdyn_postconversationsurveyenable: "true",
|
|
70
|
+
msdyn_conversationmode: "192350000"
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
}
|
|
74
|
+
sendTypingEvent() {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
73
77
|
}
|
|
74
78
|
exports.MockChatSDK = MockChatSDK;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { ConversationMode } from "../../../common/Constants";
|
|
2
|
+
import { isNullOrUndefined } from "../../../common/utils";
|
|
3
|
+
|
|
1
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
5
|
export const isPostChatSurveyEnabled = async chatSDK => {
|
|
3
6
|
var _chatConfig$LiveWSAnd;
|
|
4
7
|
const chatConfig = await chatSDK.getLiveChatConfig();
|
|
5
8
|
const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
|
|
6
9
|
return postChatEnabled === "true";
|
|
10
|
+
};
|
|
11
|
+
export const isPersistentChatEnabled = async conversationMode => {
|
|
12
|
+
if (isNullOrUndefined(conversationMode)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString().toLowerCase()) === ConversationMode.Persistent;
|
|
7
16
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isPersistentChatEnabled } from "./liveChatConfigUtils";
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
export const shouldSetPreChatIfPersistentChat = async (chatSDK, conversationMode, showPreChat) => {
|
|
5
|
+
const persistentEnabled = await isPersistentChatEnabled(conversationMode);
|
|
6
|
+
let skipPreChat = false;
|
|
7
|
+
if (persistentEnabled) {
|
|
8
|
+
const reconnectableChatsParams = {
|
|
9
|
+
authenticatedUserToken: chatSDK.authenticatedUserToken
|
|
10
|
+
};
|
|
11
|
+
try {
|
|
12
|
+
const reconnectableChatsResponse = await chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams);
|
|
13
|
+
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
|
14
|
+
// Skip rendering prechat on existing persistent chat session
|
|
15
|
+
skipPreChat = true;
|
|
16
|
+
}
|
|
17
|
+
} catch {
|
|
18
|
+
// eslint-disable-line no-empty
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return showPreChat && !skipPreChat;
|
|
22
|
+
};
|
|
@@ -15,6 +15,8 @@ import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurv
|
|
|
15
15
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
16
16
|
import { logWidgetLoadComplete, handleStartChatError } from "./startChatErrorHandler";
|
|
17
17
|
import { chatSDKStateCleanUp } from "./endChat";
|
|
18
|
+
import { isPersistentChatEnabled } from "./liveChatConfigUtils";
|
|
19
|
+
import { shouldSetPreChatIfPersistentChat } from "./persistentChatHelper";
|
|
18
20
|
|
|
19
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
22
|
let optionalParams = {};
|
|
@@ -55,16 +57,17 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
55
57
|
|
|
56
58
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
59
|
const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
58
|
-
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps;
|
|
60
|
+
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
|
|
59
61
|
//Handle reconnect scenario
|
|
60
62
|
|
|
61
63
|
// Getting prechat Survey Context
|
|
62
64
|
const parseToJson = false;
|
|
63
65
|
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 chatSDK.getPreChatSurvey(parseToJson));
|
|
64
|
-
|
|
66
|
+
let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
|
|
67
|
+
showPrechat = await shouldSetPreChatIfPersistentChat(chatSDK, 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);
|
|
65
68
|
if (showPrechat) {
|
|
66
|
-
var _state$
|
|
67
|
-
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$
|
|
69
|
+
var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
|
|
70
|
+
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";
|
|
68
71
|
if (isOutOfOperatingHours) {
|
|
69
72
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
70
73
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -88,7 +91,7 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
88
91
|
|
|
89
92
|
// If minimized, maximize the chat, if the state is missing, consider it as minimized
|
|
90
93
|
if ((state === null || state === void 0 ? void 0 : state.appStates.isMinimized) == undefined || (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.isMinimized) === true) {
|
|
91
|
-
var _state$
|
|
94
|
+
var _state$domainStates3, _state$domainStates3$, _state$domainStates4, _state$domainStates4$;
|
|
92
95
|
dispatch({
|
|
93
96
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
94
97
|
payload: false
|
|
@@ -98,8 +101,8 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
98
101
|
BroadcastService.postMessage({
|
|
99
102
|
eventName: BroadcastEvent.MaximizeChat,
|
|
100
103
|
payload: {
|
|
101
|
-
height: state === null || state === void 0 ? void 0 : (_state$
|
|
102
|
-
width: state === null || state === void 0 ? void 0 : (_state$
|
|
104
|
+
height: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.height,
|
|
105
|
+
width: state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.widgetSize) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.width
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
}
|
|
@@ -120,9 +123,11 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
120
123
|
|
|
121
124
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
125
|
const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
126
|
+
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
123
127
|
let isStartChatSuccessful = false;
|
|
124
128
|
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
125
129
|
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
130
|
+
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);
|
|
126
131
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
|
|
127
132
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
128
133
|
chatSDKStateCleanUp(chatSDK);
|
|
@@ -220,10 +225,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
220
225
|
|
|
221
226
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
227
|
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
|
|
229
|
+
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
230
|
+
if (!persistentChatEnabled) {
|
|
231
|
+
dispatch({
|
|
232
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
233
|
+
payload: liveChatContext
|
|
234
|
+
});
|
|
235
|
+
}
|
|
227
236
|
logWidgetLoadComplete();
|
|
228
237
|
// Set post chat context in state
|
|
229
238
|
// Commenting this for now as post chat context is fetched during end chat
|
|
@@ -266,17 +275,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
266
275
|
|
|
267
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
277
|
const setCustomContextParams = async (state, props) => {
|
|
269
|
-
var _props$chatConfig, _props$chatConfig$Liv, _state$
|
|
278
|
+
var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates6, _persistedState$domai8;
|
|
270
279
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
271
280
|
const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
|
|
272
281
|
//Should not set custom context for auth chat
|
|
273
282
|
if (isAuthenticatedChat) {
|
|
274
283
|
return;
|
|
275
284
|
}
|
|
276
|
-
if (state !== null && state !== void 0 && (_state$
|
|
277
|
-
var _state$
|
|
285
|
+
if (state !== null && state !== void 0 && (_state$domainStates6 = state.domainStates) !== null && _state$domainStates6 !== void 0 && _state$domainStates6.customContext) {
|
|
286
|
+
var _state$domainStates7;
|
|
278
287
|
optionalParams = Object.assign({}, optionalParams, {
|
|
279
|
-
customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$
|
|
288
|
+
customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.customContext))
|
|
280
289
|
});
|
|
281
290
|
return;
|
|
282
291
|
}
|
|
@@ -324,9 +333,9 @@ const canStartPopoutChat = async props => {
|
|
|
324
333
|
|
|
325
334
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
335
|
const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
|
|
327
|
-
var _state$
|
|
328
|
-
const requestIdFromCache = (_state$
|
|
329
|
-
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$
|
|
336
|
+
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
337
|
+
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;
|
|
338
|
+
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
330
339
|
|
|
331
340
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
332
341
|
let conversationDetails = undefined;
|
|
@@ -59,8 +59,12 @@ export class MockChatSDK {
|
|
|
59
59
|
getLiveChatConfig() {
|
|
60
60
|
return {
|
|
61
61
|
LiveWSAndLiveChatEngJoin: {
|
|
62
|
-
msdyn_postconversationsurveyenable: "true"
|
|
62
|
+
msdyn_postconversationsurveyenable: "true",
|
|
63
|
+
msdyn_conversationmode: "192350000"
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
66
|
}
|
|
67
|
+
sendTypingEvent() {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
66
70
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shouldSetPreChatIfPersistentChat: (chatSDK: any, conversationMode: string, showPreChat: boolean) => Promise<boolean>;
|