@microsoft/omnichannel-chat-widget 0.1.0-main.592da7b → 0.1.0-main.60c3e17
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/Constants.js +4 -0
- package/lib/cjs/common/storage/default/defaultCacheManager.js +34 -0
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +114 -0
- package/lib/cjs/common/storage/default/defaultInMemoryDataStore.js +86 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +19 -0
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +31 -18
- package/lib/cjs/common/utils.js +64 -5
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -5
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
- package/lib/cjs/components/footerstateful/FooterStateful.js +5 -13
- package/lib/cjs/components/headerstateful/HeaderStateful.js +14 -7
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/authHelper.js +65 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createFooter.js +7 -16
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +51 -19
- package/lib/cjs/components/livechatwidget/common/endChat.js +52 -24
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +12 -0
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +135 -83
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +188 -108
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +6 -4
- package/lib/cjs/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +20 -4
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +10 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -1
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +13 -6
- package/lib/cjs/contexts/createReducer.js +10 -2
- package/lib/cjs/controller/componentController.js +2 -2
- package/lib/esm/common/Constants.js +4 -0
- package/lib/esm/common/storage/default/defaultCacheManager.js +19 -0
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +102 -0
- package/lib/esm/common/storage/default/defaultInMemoryDataStore.js +71 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +19 -0
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +29 -13
- package/lib/esm/common/utils.js +48 -3
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -5
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
- package/lib/esm/components/footerstateful/FooterStateful.js +5 -13
- package/lib/esm/components/headerstateful/HeaderStateful.js +14 -7
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/authHelper.js +50 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createFooter.js +4 -15
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +51 -19
- package/lib/esm/components/livechatwidget/common/endChat.js +53 -25
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -2
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +56 -37
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +131 -83
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +188 -110
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +5 -4
- package/lib/esm/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +15 -2
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +3 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -1
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +11 -6
- package/lib/esm/contexts/createReducer.js +10 -2
- package/lib/esm/controller/componentController.js +2 -2
- package/lib/types/common/Constants.d.ts +2 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +4 -0
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -0
- package/lib/types/common/storage/default/defaultInMemoryDataStore.d.ts +6 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +11 -2
- package/lib/types/common/utils.d.ts +7 -3
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -2
- package/lib/types/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.d.ts +2 -2
- package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +4 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IRenderingMiddlewareProps.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.d.ts +2 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -2
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -2
- package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +1 -2
- package/package.json +5 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChatSDKError } from "../../../common/Constants";
|
|
2
2
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
|
-
import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
|
|
5
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
5
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
7
6
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
@@ -9,16 +8,24 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
|
9
8
|
import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
|
|
10
9
|
import { createAdapter } from "./createAdapter";
|
|
11
10
|
import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
|
|
12
|
-
import { createTimer,
|
|
11
|
+
import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
|
|
13
12
|
import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
|
|
14
13
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
15
14
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
16
|
-
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
15
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
16
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
17
|
+
import { getAuthClientFunction, handleAuthentication } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
18
|
|
|
18
19
|
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
20
|
|
|
21
|
+
let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
|
|
20
23
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
21
|
-
var _props$reconnectChatP;
|
|
24
|
+
var _props$controlProps, _props$reconnectChatP;
|
|
25
|
+
|
|
26
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
27
|
+
|
|
28
|
+
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId; // Can connect to existing chat session
|
|
22
29
|
|
|
23
30
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
24
31
|
return;
|
|
@@ -26,31 +33,37 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
29
|
-
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
36
|
+
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
30
37
|
|
|
31
|
-
await handleRedirectUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
} // Getting reconnectId for authenticated chat
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
44
|
+
|
|
45
|
+
if (reconnectId) {
|
|
46
|
+
dispatch({
|
|
47
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
48
|
+
payload: reconnectId
|
|
49
|
+
});
|
|
50
|
+
dispatch({
|
|
51
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
52
|
+
payload: ConversationState.ReconnectChat
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
} // Setting Proactive chat settings
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
59
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
60
|
+
|
|
61
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
62
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
63
|
|
|
36
|
-
if (reconnectId) {
|
|
37
|
-
dispatch({
|
|
38
|
-
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
39
|
-
payload: reconnectId
|
|
40
|
-
});
|
|
41
|
-
dispatch({
|
|
42
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
43
|
-
payload: ConversationState.ReconnectChat
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
setCustomContextParams(props, chatSDK);
|
|
47
|
-
setupChatState(chatSDK, dispatch, setAdapter, state.appStates.conversationState === ConversationState.ProactiveChat, state.appStates.proactiveChatStates.proactiveChatEnablePrechat);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
64
|
|
|
52
|
-
const
|
|
53
|
-
// Getting
|
|
65
|
+
const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
66
|
+
// Getting prechat Survey Context
|
|
54
67
|
const parseToJson = false;
|
|
55
68
|
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
56
69
|
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
@@ -64,26 +77,38 @@ const setupChatState = async (chatSDK, dispatch, setAdapter, isProactiveChat, pr
|
|
|
64
77
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
65
78
|
payload: ConversationState.Prechat
|
|
66
79
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
return;
|
|
81
|
+
} //Initiate start chat
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
dispatch({
|
|
85
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
86
|
+
payload: ConversationState.Loading
|
|
87
|
+
});
|
|
88
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
74
89
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
90
|
|
|
76
91
|
|
|
77
|
-
const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
|
|
92
|
+
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
78
93
|
try {
|
|
79
94
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
97
|
+
|
|
98
|
+
if (getAuthToken && authClientFunction) {
|
|
99
|
+
// set auth token to chat sdk before start chat
|
|
100
|
+
const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
101
|
+
|
|
102
|
+
if (!authSuccess) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
82
108
|
|
|
83
109
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
84
110
|
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
85
111
|
|
|
86
|
-
// Broadcasting limited cached chat details
|
|
87
112
|
BroadcastService.postMessage({
|
|
88
113
|
eventName: BroadcastEvent.ChatRetrievedFromCache,
|
|
89
114
|
payload: {
|
|
@@ -94,10 +119,13 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
94
119
|
}
|
|
95
120
|
|
|
96
121
|
try {
|
|
122
|
+
//Start widget load timer
|
|
97
123
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
98
124
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
99
125
|
Event: TelemetryEvent.StartChatSDKCall
|
|
100
|
-
});
|
|
126
|
+
}); // Set custom context params
|
|
127
|
+
|
|
128
|
+
setCustomContextParams(chatSDK);
|
|
101
129
|
optionalParams = Object.assign({}, params, optionalParams);
|
|
102
130
|
await chatSDK.startChat(optionalParams);
|
|
103
131
|
isStartChatSuccessful = true;
|
|
@@ -108,46 +136,52 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
108
136
|
exception: `Failed to setup startChat: ${error}`
|
|
109
137
|
}
|
|
110
138
|
});
|
|
111
|
-
isStartChatSuccessful = false;
|
|
112
|
-
|
|
139
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
140
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
141
|
+
|
|
142
|
+
dispatch({
|
|
143
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
144
|
+
payload: ConversationState.Closed
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
} // New adapter creation
|
|
148
|
+
|
|
113
149
|
|
|
114
150
|
const newAdapter = await createAdapter(chatSDK);
|
|
115
151
|
setAdapter(newAdapter);
|
|
116
152
|
const chatToken = await chatSDK.getChatToken();
|
|
153
|
+
dispatch({
|
|
154
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
155
|
+
payload: chatToken
|
|
156
|
+
});
|
|
117
157
|
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
|
|
118
158
|
|
|
119
|
-
if (
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
121
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
124
|
-
dispatch({
|
|
125
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
126
|
-
payload: chatToken
|
|
127
|
-
});
|
|
128
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
132
|
-
dispatch({
|
|
133
|
-
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
134
|
-
payload: liveChatContext
|
|
135
|
-
});
|
|
136
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
137
|
-
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
138
|
-
|
|
139
|
-
if (isStartChatSuccessful) {
|
|
140
|
-
dispatch({
|
|
141
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
142
|
-
payload: ConversationState.Active
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
159
|
+
if (persistedState) {
|
|
146
160
|
dispatch({
|
|
147
161
|
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
148
162
|
payload: persistedState
|
|
149
163
|
});
|
|
150
164
|
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
165
|
+
return;
|
|
166
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
170
|
+
dispatch({
|
|
171
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
172
|
+
payload: liveChatContext
|
|
173
|
+
}); // Set post chat context in state, no survey load
|
|
174
|
+
|
|
175
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
176
|
+
|
|
177
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
178
|
+
|
|
179
|
+
if (isStartChatSuccessful) {
|
|
180
|
+
ActivityStreamHandler.uncork();
|
|
181
|
+
dispatch({
|
|
182
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
183
|
+
payload: ConversationState.Active
|
|
184
|
+
});
|
|
151
185
|
}
|
|
152
186
|
|
|
153
187
|
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
@@ -176,18 +210,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
176
210
|
}
|
|
177
211
|
} finally {
|
|
178
212
|
optionalParams = {};
|
|
213
|
+
widgetInstanceId = "";
|
|
179
214
|
}
|
|
180
215
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
216
|
|
|
182
217
|
|
|
183
218
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
184
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2,
|
|
219
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
|
|
220
|
+
|
|
221
|
+
// By pass this function in case of popout chat
|
|
222
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
185
225
|
|
|
186
|
-
const
|
|
187
|
-
const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
188
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
226
|
+
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$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? ""); //Connect to only active chat session
|
|
189
227
|
|
|
190
|
-
if (persistedState
|
|
228
|
+
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) {
|
|
191
229
|
var _persistedState$domai7;
|
|
192
230
|
|
|
193
231
|
dispatch({
|
|
@@ -197,28 +235,38 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
197
235
|
const optionalParams = {
|
|
198
236
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
199
237
|
};
|
|
200
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
238
|
+
await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
201
239
|
return true;
|
|
202
240
|
} else {
|
|
203
241
|
return false;
|
|
204
242
|
}
|
|
205
|
-
};
|
|
243
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
244
|
+
|
|
206
245
|
|
|
207
|
-
const setCustomContextParams =
|
|
208
|
-
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4,
|
|
246
|
+
const setCustomContextParams = chatSDK => {
|
|
247
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
|
|
209
248
|
|
|
210
|
-
// Add custom context
|
|
211
|
-
const
|
|
212
|
-
const widgetStateFromCache = (_DataStoreManager$cli2 = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.getData(widgetStateEventName, "localStorage");
|
|
213
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
249
|
+
// Add custom context only for unauthenticated chat
|
|
250
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
|
|
214
251
|
|
|
215
|
-
if (!(
|
|
216
|
-
var _persistedState$domai9;
|
|
252
|
+
if (!isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
253
|
+
var _persistedState$domai9, _persistedState$domai10;
|
|
254
|
+
|
|
255
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
|
|
256
|
+
const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
|
|
257
|
+
TelemetryHelper.logSDKEvent(LogLevel.WARN, {
|
|
258
|
+
Event: TelemetryEvent.StartChatMethodException,
|
|
259
|
+
ExceptionDetails: {
|
|
260
|
+
exception: errorMessage
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
throw new Error(errorMessage);
|
|
264
|
+
}
|
|
217
265
|
|
|
218
266
|
optionalParams = Object.assign({}, optionalParams, {
|
|
219
|
-
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
267
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
|
|
220
268
|
});
|
|
221
269
|
}
|
|
222
270
|
};
|
|
223
271
|
|
|
224
|
-
export { prepareStartChat, initStartChat,
|
|
272
|
+
export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };
|