@microsoft/omnichannel-chat-widget 0.1.0-main.ae3aa42 → 0.1.0-main.b511ad6
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/README.md +32 -0
- package/lib/cjs/common/Constants.js +16 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +26 -3
- package/lib/cjs/common/telemetry/TelemetryManager.js +7 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +8 -9
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +63 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
- 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/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -15
- package/lib/cjs/components/livechatwidget/common/endChat.js +63 -16
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +20 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
- 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 +177 -67
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +206 -85
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +1 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +24 -21
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/cjs/contexts/createReducer.js +16 -0
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +16 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +26 -3
- package/lib/esm/common/telemetry/TelemetryManager.js +6 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +8 -6
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +44 -0
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
- 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/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -15
- package/lib/esm/components/livechatwidget/common/endChat.js +61 -17
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +19 -5
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
- 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 +172 -68
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +197 -87
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +1 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +24 -21
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/esm/contexts/createReducer.js +16 -0
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +8 -1
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +25 -5
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -1
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/utils.d.ts +6 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -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/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
- package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +24 -21
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ChatSDKError
|
|
2
|
-
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
1
|
+
import { ChatSDKError } from "../../../common/Constants";
|
|
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,14 +8,21 @@ 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 } from "../../../common/utils";
|
|
11
|
+
import { createTimer, getStateFromCache, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
13
12
|
import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconnectChat } from "./reconnectChatHelper";
|
|
14
13
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
15
|
-
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
14
|
+
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
15
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
16
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
|
|
18
|
+
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
19
|
|
|
17
20
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
18
21
|
var _props$reconnectChatP;
|
|
19
22
|
|
|
23
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
24
|
+
// Can connect to existing chat session
|
|
25
|
+
|
|
20
26
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
21
27
|
return;
|
|
22
28
|
} // Redirecting if unauthenticated reconnect chat expired
|
|
@@ -25,54 +31,121 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
25
31
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
26
32
|
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
27
33
|
|
|
28
|
-
await handleRedirectUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const parseToJson = false;
|
|
32
|
-
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
33
|
-
const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
|
|
34
|
+
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
|
|
35
|
+
return;
|
|
36
|
+
} // Getting reconnectId for authenticated chat
|
|
34
37
|
|
|
35
|
-
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
40
|
+
|
|
41
|
+
if (reconnectId) {
|
|
42
|
+
dispatch({
|
|
43
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
44
|
+
payload: reconnectId
|
|
45
|
+
});
|
|
46
|
+
dispatch({
|
|
47
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
48
|
+
payload: ConversationState.ReconnectChat
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
} // Set custom context params
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
|
|
55
|
+
|
|
56
|
+
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
57
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
58
|
+
|
|
59
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
60
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
64
|
+
// Getting prechat Survey Context
|
|
65
|
+
const parseToJson = false;
|
|
66
|
+
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
67
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
68
|
+
|
|
69
|
+
if (showPrechat) {
|
|
70
|
+
dispatch({
|
|
71
|
+
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
72
|
+
payload: preChatSurveyResponse
|
|
73
|
+
});
|
|
74
|
+
dispatch({
|
|
75
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
76
|
+
payload: ConversationState.Prechat
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
} //Initiate start chat
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
dispatch({
|
|
83
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
84
|
+
payload: ConversationState.Loading
|
|
85
|
+
});
|
|
86
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
87
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
91
|
+
if (getAuthToken) {
|
|
92
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
93
|
+
Event: TelemetryEvent.GetAuthTokenCalled
|
|
94
|
+
});
|
|
95
|
+
let authClientFunction = undefined;
|
|
96
|
+
|
|
97
|
+
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
98
|
+
var _chatConfig$LiveChatC;
|
|
99
|
+
|
|
100
|
+
authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const token = await getAuthToken(authClientFunction);
|
|
104
|
+
|
|
105
|
+
if (!isNullOrEmptyString(token)) {
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
chatSDK.setAuthTokenProvider(async () => {
|
|
108
|
+
return token;
|
|
54
109
|
});
|
|
55
110
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
payload: ConversationState.Loading
|
|
111
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
112
|
+
Event: TelemetryEvent.ReceivedNullOrEmptyToken
|
|
59
113
|
});
|
|
60
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
61
114
|
}
|
|
62
115
|
}
|
|
63
116
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
117
|
|
|
65
118
|
|
|
66
|
-
const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
|
|
119
|
+
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
67
120
|
try {
|
|
68
121
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
69
122
|
|
|
123
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
124
|
+
|
|
125
|
+
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
126
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
127
|
+
|
|
128
|
+
BroadcastService.postMessage({
|
|
129
|
+
eventName: BroadcastEvent.ChatRetrievedFromCache,
|
|
130
|
+
payload: {
|
|
131
|
+
chatId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.liveChatContext) === null || _persistedState$domai2 === void 0 ? void 0 : (_persistedState$domai3 = _persistedState$domai2.chatToken) === null || _persistedState$domai3 === void 0 ? void 0 : _persistedState$domai3.chatId,
|
|
132
|
+
requestId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai4 = persistedState.domainStates) === null || _persistedState$domai4 === void 0 ? void 0 : (_persistedState$domai5 = _persistedState$domai4.liveChatContext) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.requestId
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
70
137
|
try {
|
|
138
|
+
//Start widget load timer
|
|
71
139
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
72
140
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
73
141
|
Event: TelemetryEvent.StartChatSDKCall
|
|
74
|
-
});
|
|
75
|
-
|
|
142
|
+
}); // Set optional params
|
|
143
|
+
|
|
144
|
+
optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
|
|
145
|
+
|
|
146
|
+
await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
147
|
+
await chatSDK.startChat(optionalParams);
|
|
148
|
+
isStartChatSuccessful = true;
|
|
76
149
|
} catch (error) {
|
|
77
150
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
78
151
|
Event: TelemetryEvent.StartChatMethodException,
|
|
@@ -80,43 +153,52 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
80
153
|
exception: `Failed to setup startChat: ${error}`
|
|
81
154
|
}
|
|
82
155
|
});
|
|
83
|
-
|
|
156
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
157
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
158
|
+
|
|
159
|
+
dispatch({
|
|
160
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
161
|
+
payload: ConversationState.Closed
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
} // New adapter creation
|
|
165
|
+
|
|
84
166
|
|
|
85
167
|
const newAdapter = await createAdapter(chatSDK);
|
|
86
168
|
setAdapter(newAdapter);
|
|
87
169
|
const chatToken = await chatSDK.getChatToken();
|
|
170
|
+
dispatch({
|
|
171
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
172
|
+
payload: chatToken
|
|
173
|
+
});
|
|
88
174
|
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));
|
|
89
175
|
|
|
90
|
-
if (
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
95
|
-
dispatch({
|
|
96
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
97
|
-
payload: chatToken
|
|
98
|
-
});
|
|
99
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
176
|
+
if (persistedState) {
|
|
103
177
|
dispatch({
|
|
104
|
-
type: LiveChatWidgetActionType.
|
|
105
|
-
payload:
|
|
178
|
+
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
179
|
+
payload: persistedState
|
|
106
180
|
});
|
|
107
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
108
|
-
|
|
181
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
182
|
+
return;
|
|
183
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
187
|
+
dispatch({
|
|
188
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
189
|
+
payload: liveChatContext
|
|
190
|
+
}); // Set post chat context in state, no survey load
|
|
191
|
+
|
|
192
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
193
|
+
|
|
194
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
109
195
|
|
|
196
|
+
if (isStartChatSuccessful) {
|
|
197
|
+
ActivityStreamHandler.uncork();
|
|
110
198
|
dispatch({
|
|
111
199
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
112
200
|
payload: ConversationState.Active
|
|
113
201
|
});
|
|
114
|
-
} else {
|
|
115
|
-
dispatch({
|
|
116
|
-
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
117
|
-
payload: persistedState
|
|
118
|
-
});
|
|
119
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
120
202
|
}
|
|
121
203
|
|
|
122
204
|
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
@@ -143,31 +225,53 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
143
225
|
payload: ConversationState.OutOfOffice
|
|
144
226
|
});
|
|
145
227
|
}
|
|
228
|
+
} finally {
|
|
229
|
+
optionalParams = {};
|
|
146
230
|
}
|
|
147
231
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
232
|
|
|
149
233
|
|
|
150
234
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
151
|
-
var
|
|
235
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
152
236
|
|
|
153
|
-
|
|
154
|
-
|
|
237
|
+
// By pass this function in case of popout chat
|
|
238
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
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); //Connect to only active chat session
|
|
155
243
|
|
|
156
|
-
if (persistedState
|
|
157
|
-
var _persistedState$
|
|
244
|
+
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) {
|
|
245
|
+
var _persistedState$domai7;
|
|
158
246
|
|
|
159
247
|
dispatch({
|
|
160
248
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
161
249
|
payload: ConversationState.Loading
|
|
162
250
|
});
|
|
163
251
|
const optionalParams = {
|
|
164
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
252
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
165
253
|
};
|
|
166
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
254
|
+
await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
167
255
|
return true;
|
|
168
256
|
} else {
|
|
169
257
|
return false;
|
|
170
258
|
}
|
|
259
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
const setCustomContextParams = (props, chatSDK) => {
|
|
263
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
|
|
264
|
+
|
|
265
|
+
// Add custom context only for unauthenticated chat
|
|
266
|
+
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);
|
|
267
|
+
|
|
268
|
+
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
269
|
+
var _persistedState$domai9;
|
|
270
|
+
|
|
271
|
+
optionalParams = Object.assign({}, optionalParams, {
|
|
272
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
|
|
273
|
+
});
|
|
274
|
+
}
|
|
171
275
|
};
|
|
172
276
|
|
|
173
|
-
export { prepareStartChat, initStartChat };
|
|
277
|
+
export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };
|