@microsoft/omnichannel-chat-widget 0.1.0-main.bf74329 → 0.1.0-main.c1bbb91
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/assets/Icons.js +4 -2
- package/lib/cjs/common/Constants.js +24 -4
- package/lib/cjs/common/KeyCodes.js +3 -1
- package/lib/cjs/common/contextDataStore/DataStoreManager.js +3 -1
- package/lib/cjs/common/storage/default/defaultCacheManager.js +5 -3
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +12 -5
- package/lib/cjs/common/telemetry/TelemetryHelper.js +7 -2
- package/lib/cjs/common/telemetry/TelemetryManager.js +3 -1
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +2 -2
- package/lib/cjs/components/chatbuttonstateful/common/styleProps/defaultOutOfOfficeChatButtonStyleProps.js +3 -0
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +1 -1
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +6 -4
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +3 -1
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +3 -1
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +3 -1
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +3 -1
- package/lib/cjs/components/livechatwidget/common/Deferred.js +3 -1
- package/lib/cjs/components/livechatwidget/common/defaultProps/defaultScrollBarProps.js +14 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +67 -16
- package/lib/cjs/components/livechatwidget/common/endChat.js +42 -2
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +13 -19
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +75 -114
- package/lib/cjs/components/livechatwidget/common/startChat.js +162 -45
- package/lib/cjs/components/livechatwidget/interfaces/IScrollBarProps.js +1 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +152 -116
- package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +22 -2
- package/lib/cjs/components/loadingpanestateful/common/errorUIStyleProps/errorUILoadingPaneStyleProps.js +57 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +2 -2
- package/lib/cjs/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockadapter.js +3 -1
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +3 -1
- package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +3 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +3 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +5 -6
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware.js +12 -1
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +29 -27
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +6 -3
- package/lib/cjs/contexts/createReducer.js +19 -2
- package/lib/cjs/controller/componentController.js +1 -1
- package/lib/cjs/hooks/useDebounce.js +28 -0
- package/lib/cjs/hooks/useWindowDimensions.js +30 -0
- package/lib/cjs/plugins/newMessageEventHandler.js +4 -0
- package/lib/esm/assets/Icons.js +2 -1
- package/lib/esm/common/Constants.js +21 -3
- package/lib/esm/common/KeyCodes.js +3 -1
- package/lib/esm/common/contextDataStore/DataStoreManager.js +3 -1
- package/lib/esm/common/storage/default/defaultCacheManager.js +5 -3
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/esm/common/telemetry/TelemetryConstants.js +12 -5
- package/lib/esm/common/telemetry/TelemetryHelper.js +7 -2
- package/lib/esm/common/telemetry/TelemetryManager.js +3 -1
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +2 -2
- package/lib/esm/components/chatbuttonstateful/common/styleProps/defaultOutOfOfficeChatButtonStyleProps.js +3 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +1 -1
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +6 -4
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +3 -1
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +3 -1
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +3 -1
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +3 -1
- package/lib/esm/components/livechatwidget/common/Deferred.js +3 -1
- package/lib/esm/components/livechatwidget/common/defaultProps/defaultScrollBarProps.js +7 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +67 -16
- package/lib/esm/components/livechatwidget/common/endChat.js +42 -2
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -19
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +72 -109
- package/lib/esm/components/livechatwidget/common/startChat.js +161 -45
- package/lib/esm/components/livechatwidget/interfaces/IScrollBarProps.js +1 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +153 -117
- package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +22 -2
- package/lib/esm/components/loadingpanestateful/common/errorUIStyleProps/errorUILoadingPaneStyleProps.js +50 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +2 -2
- package/lib/esm/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockadapter.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +5 -6
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware.js +12 -1
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +29 -27
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +6 -3
- package/lib/esm/contexts/createReducer.js +19 -2
- package/lib/esm/controller/componentController.js +1 -1
- package/lib/esm/hooks/useDebounce.js +22 -0
- package/lib/esm/hooks/useWindowDimensions.js +23 -0
- package/lib/esm/plugins/newMessageEventHandler.js +4 -0
- package/lib/types/assets/Icons.d.ts +1 -0
- package/lib/types/common/Constants.d.ts +14 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +1 -1
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +11 -4
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +4 -4
- package/lib/types/common/telemetry/definitions/Payload.d.ts +1 -0
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +4 -0
- package/lib/types/components/livechatwidget/common/defaultProps/defaultScrollBarProps.d.ts +2 -0
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -7
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +3 -1
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
- package/lib/types/components/livechatwidget/interfaces/IScrollBarProps.d.ts +22 -0
- package/lib/types/components/loadingpanestateful/common/errorUIStyleProps/errorUILoadingPaneStyleProps.d.ts +2 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.d.ts +1 -1
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +29 -27
- package/lib/types/hooks/useDebounce.d.ts +3 -0
- package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
- package/package.json +3 -3
|
@@ -1,85 +1,88 @@
|
|
|
1
1
|
import "regenerator-runtime/runtime";
|
|
2
2
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
|
|
4
|
+
import { isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
|
|
3
5
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
4
6
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
7
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
8
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
-
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
|
|
8
9
|
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
} catch (ex) {
|
|
28
|
-
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
29
|
-
Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
|
|
30
|
-
ExceptionDetails: {
|
|
31
|
-
exception: ex
|
|
32
|
-
}
|
|
33
|
-
});
|
|
11
|
+
const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
|
|
12
|
+
var _props$chatConfig, _props$chatConfig$Liv;
|
|
13
|
+
if (!isReconnectEnabled(props.chatConfig)) return;
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
const isAuthenticatedChat = (_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;
|
|
17
|
+
|
|
18
|
+
// Get chat reconnect context
|
|
19
|
+
const reconnectChatContext = await getChatReconnectContext(chatSDK, props.chatConfig, props, isAuthenticatedChat);
|
|
20
|
+
if (hasReconnectId(reconnectChatContext)) {
|
|
21
|
+
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
22
|
+
//Redirect if enabled
|
|
23
|
+
if (reconnectChatContext.redirectURL && !isNullOrEmptyString(reconnectChatContext.redirectURL)) {
|
|
24
|
+
var _props$reconnectChatP;
|
|
25
|
+
redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
|
|
26
|
+
return;
|
|
34
27
|
}
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
};
|
|
38
28
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _props$chatConfig2, _props$chatConfig2$Li;
|
|
45
|
-
authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
|
|
46
|
-
}
|
|
47
|
-
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction
|
|
48
|
-
// TODO: Implement this after storage is in place
|
|
49
|
-
/* && !isLoadWithState() */) {
|
|
50
|
-
var _props$reconnectChatP2;
|
|
51
|
-
const previousActiveSessionResponse = await getChatReconnectContext(chatSDK, props.chatConfig, props.getAuthToken, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled);
|
|
52
|
-
if (previousActiveSessionResponse && previousActiveSessionResponse.reconnectId) {
|
|
53
|
-
return previousActiveSessionResponse.reconnectId;
|
|
29
|
+
//if reconnect id is provided in props, don't show reconnect pane
|
|
30
|
+
if ((_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.reconnectId && !isNullOrEmptyString((_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId)) {
|
|
31
|
+
const reconnectChatContext = await getChatReconnectContext(chatSDK, props.chatConfig, props, isAuthenticatedChat);
|
|
32
|
+
await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
|
|
33
|
+
return;
|
|
54
34
|
}
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
};
|
|
58
35
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
36
|
+
//show reconnect pane
|
|
37
|
+
state.appStates.conversationState = ConversationState.ReconnectChat;
|
|
38
|
+
dispatch({
|
|
39
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
40
|
+
payload: reconnectChatContext.reconnectId ?? ""
|
|
41
|
+
});
|
|
42
|
+
dispatch({
|
|
43
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
44
|
+
payload: ConversationState.ReconnectChat
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
66
47
|
}
|
|
67
48
|
};
|
|
68
49
|
|
|
69
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticatedChat) => {
|
|
52
|
+
try {
|
|
53
|
+
var _props$reconnectChatP4;
|
|
54
|
+
const chatReconnectOptionalParams = {
|
|
55
|
+
reconnectId: (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId
|
|
56
|
+
};
|
|
57
|
+
if (isAuthenticatedChat) {
|
|
58
|
+
// Get auth token for for getting chat reconnect context
|
|
59
|
+
await handleAuthentication(chatSDK, chatConfig, props.getAuthToken);
|
|
60
|
+
}
|
|
61
|
+
const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
|
|
62
|
+
if (isAuthenticatedChat) {
|
|
63
|
+
// remove auth token after reconnectId is fetched
|
|
64
|
+
// this will be reset later at start chat
|
|
65
|
+
removeAuthTokenProvider(chatSDK);
|
|
66
|
+
}
|
|
67
|
+
return reconnectChatContext;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
70
|
+
Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
|
|
71
|
+
ExceptionDetails: {
|
|
72
|
+
exception: error
|
|
73
|
+
}
|
|
74
|
+
});
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
-
const setReconnectIdAndStartChat = async (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
80
|
+
if (!isAuthenticatedChat) {
|
|
81
|
+
const startUnauthenticatedReconnectChat = {
|
|
82
|
+
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
83
|
+
};
|
|
84
|
+
BroadcastService.postMessage(startUnauthenticatedReconnectChat);
|
|
85
|
+
}
|
|
83
86
|
const optionalParams = {
|
|
84
87
|
reconnectId: reconnectId
|
|
85
88
|
};
|
|
@@ -91,7 +94,7 @@ const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dis
|
|
|
91
94
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
92
95
|
payload: ConversationState.Loading
|
|
93
96
|
});
|
|
94
|
-
await initStartChat(chatSDK,
|
|
97
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
95
98
|
};
|
|
96
99
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
97
100
|
const redirectPageRequest = {
|
|
@@ -105,51 +108,11 @@ const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
|
105
108
|
window.location.href = redirectURL;
|
|
106
109
|
}
|
|
107
110
|
};
|
|
108
|
-
const
|
|
109
|
-
|
|
111
|
+
const isReconnectEnabled = chatConfig => {
|
|
112
|
+
var _chatConfig$LiveWSAnd;
|
|
113
|
+
return chatConfig && ((_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_enablechatreconnect) && (chatConfig.LiveWSAndLiveChatEngJoin.msdyn_enablechatreconnect === "true" || chatConfig.LiveWSAndLiveChatEngJoin.msdyn_enablechatreconnect === true);
|
|
110
114
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
|
|
114
|
-
const startUnauthenticatedReconnectChat = {
|
|
115
|
-
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
116
|
-
};
|
|
117
|
-
BroadcastService.postMessage(startUnauthenticatedReconnectChat);
|
|
118
|
-
// Getting PreChat Survey Context
|
|
119
|
-
const parseToJson = false;
|
|
120
|
-
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
121
|
-
if (preChatSurveyResponse) {
|
|
122
|
-
dispatch({
|
|
123
|
-
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
124
|
-
payload: preChatSurveyResponse
|
|
125
|
-
});
|
|
126
|
-
dispatch({
|
|
127
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
128
|
-
payload: ConversationState.Prechat
|
|
129
|
-
});
|
|
130
|
-
} else {
|
|
131
|
-
dispatch({
|
|
132
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
133
|
-
payload: ConversationState.Loading
|
|
134
|
-
});
|
|
135
|
-
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, isReconnectEnabled, reconnectId, redirectInSameWindow) => {
|
|
141
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
142
|
-
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
143
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
|
-
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
149
|
-
if (reconnectAvailabilityResponse.redirectURL) {
|
|
150
|
-
redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
|
|
151
|
-
} else {
|
|
152
|
-
await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
|
|
153
|
-
}
|
|
115
|
+
const hasReconnectId = reconnectAvailabilityResponse => {
|
|
116
|
+
return reconnectAvailabilityResponse && !isNullOrUndefined(reconnectAvailabilityResponse.reconnectId);
|
|
154
117
|
};
|
|
155
|
-
export {
|
|
118
|
+
export { handleChatReconnect, isReconnectEnabled, getChatReconnectContext };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { ChatSDKError } from "../../../common/Constants";
|
|
2
1
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
|
|
3
|
+
import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
|
|
4
|
+
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
5
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
6
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
3
7
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
8
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
9
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
@@ -8,13 +12,9 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
|
8
12
|
import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
9
13
|
import { createAdapter } from "./createAdapter";
|
|
10
14
|
import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
|
|
11
|
-
import {
|
|
12
|
-
import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
|
|
15
|
+
import { handleChatReconnect } from "./reconnectChatHelper";
|
|
13
16
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
14
17
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
15
|
-
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
16
|
-
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
17
|
-
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
18
18
|
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
let optionalParams = {};
|
|
@@ -23,7 +23,7 @@ let widgetInstanceId;
|
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
25
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
26
|
-
var _props$controlProps
|
|
26
|
+
var _props$controlProps;
|
|
27
27
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
28
28
|
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
|
|
29
29
|
|
|
@@ -31,25 +31,10 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
31
31
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
+
await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
34
35
|
|
|
35
|
-
//
|
|
36
|
-
if (
|
|
37
|
-
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
38
|
-
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.redirectInSameWindow);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Getting reconnectId for authenticated chat
|
|
43
|
-
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
44
|
-
if (reconnectId) {
|
|
45
|
-
dispatch({
|
|
46
|
-
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
47
|
-
payload: reconnectId
|
|
48
|
-
});
|
|
49
|
-
dispatch({
|
|
50
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
51
|
-
payload: ConversationState.ReconnectChat
|
|
52
|
-
});
|
|
36
|
+
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
37
|
+
if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
|
|
53
38
|
return;
|
|
54
39
|
}
|
|
55
40
|
|
|
@@ -58,11 +43,20 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
58
43
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
|
|
59
44
|
|
|
60
45
|
//Setting PreChat and intiate chat
|
|
61
|
-
setPreChatAndInitiateChat(chatSDK,
|
|
46
|
+
setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, undefined, props);
|
|
62
47
|
};
|
|
63
48
|
|
|
64
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
const setPreChatAndInitiateChat = async (chatSDK,
|
|
50
|
+
const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
51
|
+
//Handle reconnect scenario
|
|
52
|
+
if (state) {
|
|
53
|
+
await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
54
|
+
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
55
|
+
if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
66
60
|
// Getting prechat Survey Context
|
|
67
61
|
const parseToJson = false;
|
|
68
62
|
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
@@ -84,13 +78,27 @@ const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, disp
|
|
|
84
78
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
85
79
|
payload: ConversationState.Loading
|
|
86
80
|
});
|
|
87
|
-
|
|
81
|
+
const optionalParams = {
|
|
82
|
+
isProactiveChat
|
|
83
|
+
};
|
|
84
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
88
85
|
};
|
|
89
86
|
|
|
90
87
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
-
const initStartChat = async (chatSDK,
|
|
88
|
+
const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
|
|
89
|
+
var _props$controlProps2;
|
|
90
|
+
let isStartChatSuccessful = false;
|
|
91
|
+
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
92
|
+
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
93
|
+
const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
|
|
92
94
|
try {
|
|
93
95
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
96
|
+
//Start widget load timer
|
|
97
|
+
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
98
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
99
|
+
Event: TelemetryEvent.WidgetLoadStarted,
|
|
100
|
+
Description: "Widget loading started"
|
|
101
|
+
});
|
|
94
102
|
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
95
103
|
if (getAuthToken && authClientFunction) {
|
|
96
104
|
// set auth token to chat sdk before start chat
|
|
@@ -99,7 +107,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
99
107
|
return;
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
|
-
let isStartChatSuccessful = false;
|
|
103
110
|
|
|
104
111
|
//Check if chat retrieved from cache
|
|
105
112
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -113,16 +120,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
113
120
|
});
|
|
114
121
|
}
|
|
115
122
|
try {
|
|
116
|
-
|
|
117
|
-
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
118
|
-
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
119
|
-
Event: TelemetryEvent.StartChatSDKCall
|
|
120
|
-
});
|
|
121
|
-
|
|
123
|
+
var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
|
|
122
124
|
// Set custom context params
|
|
123
125
|
setCustomContextParams(chatSDK);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
const defaultOptionalParams = {
|
|
127
|
+
sendDefaultInitContext: true,
|
|
128
|
+
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
129
|
+
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
|
|
130
|
+
};
|
|
131
|
+
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
132
|
+
await chatSDK.startChat(startChatOptionalParams);
|
|
126
133
|
isStartChatSuccessful = true;
|
|
127
134
|
} catch (error) {
|
|
128
135
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -155,7 +162,7 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
155
162
|
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
156
163
|
payload: persistedState
|
|
157
164
|
});
|
|
158
|
-
|
|
165
|
+
setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
159
166
|
return;
|
|
160
167
|
}
|
|
161
168
|
|
|
@@ -167,7 +174,7 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
167
174
|
});
|
|
168
175
|
|
|
169
176
|
// Set post chat context in state, no survey load
|
|
170
|
-
|
|
177
|
+
setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
171
178
|
|
|
172
179
|
// Updating chat session detail for telemetry
|
|
173
180
|
await updateSessionDataForTelemetry(chatSDK, dispatch);
|
|
@@ -175,6 +182,11 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
175
182
|
// Set app state to Active
|
|
176
183
|
if (isStartChatSuccessful) {
|
|
177
184
|
ActivityStreamHandler.uncork();
|
|
185
|
+
// Update start chat failure app state if chat loads successfully
|
|
186
|
+
dispatch({
|
|
187
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
188
|
+
payload: false
|
|
189
|
+
});
|
|
178
190
|
dispatch({
|
|
179
191
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
180
192
|
payload: ConversationState.Active
|
|
@@ -203,6 +215,29 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
203
215
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
204
216
|
payload: ConversationState.OutOfOffice
|
|
205
217
|
});
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (!hideErrorUIPane) {
|
|
221
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
222
|
+
dispatch({
|
|
223
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
224
|
+
payload: true
|
|
225
|
+
});
|
|
226
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
227
|
+
Event: TelemetryEvent.ErrorUIPaneLoaded,
|
|
228
|
+
Description: "Error UI Pane Loaded"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
|
|
232
|
+
dispatch({
|
|
233
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
234
|
+
payload: ConversationState.Loading
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
238
|
+
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
239
|
+
if (isStartChatSuccessful === true) {
|
|
240
|
+
await forceEndChat(chatSDK);
|
|
206
241
|
}
|
|
207
242
|
} finally {
|
|
208
243
|
optionalParams = {};
|
|
@@ -210,14 +245,25 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
210
245
|
}
|
|
211
246
|
};
|
|
212
247
|
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
+
const forceEndChat = async chatSDK => {
|
|
250
|
+
TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
|
|
251
|
+
Event: TelemetryEvent.WidgetLoadFailed,
|
|
252
|
+
ExceptionDetails: {
|
|
253
|
+
Exception: "SessionInit was successful, but widget load failed."
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
|
|
257
|
+
};
|
|
258
|
+
|
|
213
259
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
214
260
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
215
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$
|
|
261
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6, _persistedState$appSt;
|
|
216
262
|
// By pass this function in case of popout chat
|
|
217
|
-
if (state.appStates.
|
|
263
|
+
if (state.appStates.hideStartChatButton === true) {
|
|
218
264
|
return false;
|
|
219
265
|
}
|
|
220
|
-
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$
|
|
266
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
|
|
221
267
|
|
|
222
268
|
//Connect to only active chat session
|
|
223
269
|
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active) {
|
|
@@ -229,7 +275,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
229
275
|
const optionalParams = {
|
|
230
276
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
231
277
|
};
|
|
232
|
-
await initStartChat(chatSDK,
|
|
278
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
233
279
|
return true;
|
|
234
280
|
} else {
|
|
235
281
|
return false;
|
|
@@ -258,4 +304,74 @@ const setCustomContextParams = chatSDK => {
|
|
|
258
304
|
});
|
|
259
305
|
}
|
|
260
306
|
};
|
|
261
|
-
|
|
307
|
+
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
309
|
+
const handleAuthenticationIfEnabled = async (chatSDK, props) => {
|
|
310
|
+
//For auth chat
|
|
311
|
+
if (props.getAuthToken) {
|
|
312
|
+
const authClientFunction = getAuthClientFunction(props.chatConfig);
|
|
313
|
+
if (authClientFunction) {
|
|
314
|
+
// set auth token to chat sdk before start chat
|
|
315
|
+
const authSuccess = await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
|
|
316
|
+
if (!authSuccess) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
+
const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
|
|
327
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
328
|
+
let conversationDetails = undefined;
|
|
329
|
+
|
|
330
|
+
// Show Loading screen during auth check and start chat calls
|
|
331
|
+
dispatch({
|
|
332
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
333
|
+
payload: ConversationState.Loading
|
|
334
|
+
});
|
|
335
|
+
const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
|
|
336
|
+
if (!authSucceed) {
|
|
337
|
+
var _props$controlProps4;
|
|
338
|
+
if (!(props !== null && props !== void 0 && (_props$controlProps4 = props.controlProps) !== null && _props$controlProps4 !== void 0 && _props$controlProps4.hideErrorUIPane)) {
|
|
339
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
340
|
+
dispatch({
|
|
341
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
342
|
+
payload: true
|
|
343
|
+
});
|
|
344
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
345
|
+
Event: TelemetryEvent.ErrorUIPaneLoaded,
|
|
346
|
+
Description: "Error UI Pane Loaded"
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//Preserve old requestId
|
|
353
|
+
const oldRequestId = chatSDK.requestId;
|
|
354
|
+
try {
|
|
355
|
+
chatSDK.requestId = requestId;
|
|
356
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
357
|
+
if (Object.keys(conversationDetails).length === 0) {
|
|
358
|
+
chatSDK.requestId = oldRequestId;
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
if (conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
362
|
+
chatSDK.requestId = oldRequestId;
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
return true;
|
|
366
|
+
} catch (erorr) {
|
|
367
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
368
|
+
Event: TelemetryEvent.GetConversationDetailsException,
|
|
369
|
+
ExceptionDetails: {
|
|
370
|
+
exception: `Conversation is not valid: ${erorr}`
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
chatSDK.requestId = oldRequestId;
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
export { prepareStartChat, initStartChat, setPreChatAndInitiateChat, checkIfConversationStillValid };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|