@microsoft/omnichannel-chat-widget 0.1.0-main.9e62ed8 → 0.1.0-main.a60f242
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 +2 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
- package/lib/cjs/common/utils.js +48 -2
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
- package/lib/cjs/components/livechatwidget/common/endChat.js +49 -17
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +9 -0
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +115 -80
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +89 -99
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
- package/lib/cjs/controller/componentController.js +2 -2
- package/lib/esm/common/Constants.js +2 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
- package/lib/esm/common/utils.js +36 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
- package/lib/esm/components/livechatwidget/common/endChat.js +50 -18
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +10 -2
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +114 -80
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +89 -97
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
- package/lib/esm/controller/componentController.js +2 -2
- package/lib/types/common/Constants.d.ts +1 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
- package/lib/types/common/utils.d.ts +3 -0
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
- 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/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +0 -1
- package/package.json +1 -1
|
@@ -7,21 +7,38 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
|
|
|
7
7
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
8
8
|
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
9
9
|
import { Constants } from "../../../common/Constants";
|
|
10
|
-
import { getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
11
|
|
|
12
12
|
const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
|
|
13
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
|
|
13
|
+
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
|
|
14
14
|
|
|
15
15
|
const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
|
|
16
|
-
const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
|
|
17
|
-
const conversationDetails = await chatSDK.getConversationDetails();
|
|
16
|
+
const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
let conversationDetails = undefined;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
22
|
+
} catch (erorr) {
|
|
23
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
24
|
+
Event: TelemetryEvent.GetConversationDetailsException,
|
|
25
|
+
ExceptionDetails: {
|
|
26
|
+
exception: `Failed to get conversation details: ${erorr}`
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
20
32
|
const skipEndChatSDK = false;
|
|
21
33
|
const skipCloseChat = true;
|
|
22
34
|
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
|
|
23
35
|
|
|
24
36
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
37
|
+
dispatch({
|
|
38
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
39
|
+
payload: ConversationState.PostchatLoading
|
|
40
|
+
});
|
|
41
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
25
42
|
const loadPostChatEvent = {
|
|
26
43
|
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
27
44
|
};
|
|
@@ -32,9 +49,11 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
|
|
|
32
49
|
payload: ConversationState.InActive
|
|
33
50
|
});
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
|
|
53
|
+
return;
|
|
37
54
|
}
|
|
55
|
+
|
|
56
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
38
57
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
58
|
|
|
40
59
|
|
|
@@ -44,16 +63,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
44
63
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
45
64
|
Event: TelemetryEvent.EndChatSDKCall
|
|
46
65
|
});
|
|
47
|
-
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
|
|
48
|
-
|
|
49
|
-
dispatch({
|
|
50
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
51
|
-
payload: undefined
|
|
52
|
-
});
|
|
53
|
-
dispatch({
|
|
54
|
-
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
55
|
-
payload: undefined
|
|
56
|
-
});
|
|
66
|
+
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
|
|
57
67
|
} catch (ex) {
|
|
58
68
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
59
69
|
Event: TelemetryEvent.EndChatSDKCallFailed,
|
|
@@ -63,7 +73,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
63
73
|
});
|
|
64
74
|
postMessageToOtherTab = false;
|
|
65
75
|
}
|
|
66
|
-
}
|
|
76
|
+
} // Need to clear these states immediately when chat ended from OC.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
dispatch({
|
|
80
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
81
|
+
payload: undefined
|
|
82
|
+
});
|
|
83
|
+
dispatch({
|
|
84
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
85
|
+
payload: undefined
|
|
86
|
+
});
|
|
87
|
+
dispatch({
|
|
88
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
89
|
+
payload: undefined
|
|
90
|
+
});
|
|
67
91
|
|
|
68
92
|
if (!skipCloseChat) {
|
|
69
93
|
try {
|
|
@@ -95,6 +119,14 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
95
119
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
96
120
|
payload: 0
|
|
97
121
|
});
|
|
122
|
+
dispatch({
|
|
123
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
124
|
+
payload: {
|
|
125
|
+
proactiveChatBodyTitle: "",
|
|
126
|
+
proactiveChatEnablePrechat: false,
|
|
127
|
+
proactiveChatInNewWindow: false
|
|
128
|
+
}
|
|
129
|
+
});
|
|
98
130
|
|
|
99
131
|
if (postMessageToOtherTab) {
|
|
100
132
|
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
|
|
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
|
|
|
7
7
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
8
8
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
9
9
|
import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
|
|
10
|
-
import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
|
|
10
|
+
import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
|
|
11
11
|
import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
|
|
12
12
|
import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
|
|
13
13
|
import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
|
|
@@ -28,7 +28,8 @@ import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller
|
|
|
28
28
|
import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
|
|
29
29
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
30
30
|
import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
|
|
31
|
-
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
31
|
+
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
32
|
+
import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
33
|
|
|
33
34
|
export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
|
|
34
35
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
|
|
@@ -63,8 +64,15 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
WebChatStoreLoader.store = null;
|
|
68
|
+
|
|
66
69
|
if (isPostChatEnabled === "true") {
|
|
67
70
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
71
|
+
dispatch({
|
|
72
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
73
|
+
payload: ConversationState.PostchatLoading
|
|
74
|
+
});
|
|
75
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
68
76
|
const loadPostChatEvent = {
|
|
69
77
|
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
70
78
|
};
|
|
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
|
|
32
|
-
dispatch({
|
|
33
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
34
|
-
payload: ConversationState.Loading
|
|
35
|
-
});
|
|
36
32
|
dispatch({
|
|
37
33
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
38
34
|
payload: ConversationState.Postchat
|
|
@@ -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,7 +8,7 @@ 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";
|
|
@@ -20,6 +19,9 @@ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-expli
|
|
|
20
19
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
21
20
|
var _props$reconnectChatP;
|
|
22
21
|
|
|
22
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
23
|
+
// Can connect to existing chat session
|
|
24
|
+
|
|
23
25
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
24
26
|
return;
|
|
25
27
|
} // Redirecting if unauthenticated reconnect chat expired
|
|
@@ -29,42 +31,58 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
29
31
|
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
30
32
|
|
|
31
33
|
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);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const parseToJson = false;
|
|
35
|
-
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
36
|
-
const showPrechat = state.appStates.conversationState === ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
|
|
34
|
+
return;
|
|
35
|
+
} // Getting reconnectId for authenticated chat
|
|
37
36
|
|
|
38
|
-
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
38
|
+
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
39
|
+
|
|
40
|
+
if (reconnectId) {
|
|
41
|
+
dispatch({
|
|
42
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
43
|
+
payload: reconnectId
|
|
44
|
+
});
|
|
45
|
+
dispatch({
|
|
46
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
47
|
+
payload: ConversationState.ReconnectChat
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
} // Set custom context params
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
|
|
54
|
+
|
|
55
|
+
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
56
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
57
|
+
|
|
58
|
+
setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
59
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
63
|
+
// Getting prechat Survey Context
|
|
64
|
+
const parseToJson = false;
|
|
65
|
+
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
66
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
67
|
+
|
|
68
|
+
if (showPrechat) {
|
|
69
|
+
dispatch({
|
|
70
|
+
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
71
|
+
payload: preChatSurveyResponse
|
|
72
|
+
});
|
|
73
|
+
dispatch({
|
|
74
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
75
|
+
payload: ConversationState.Prechat
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
} //Initiate start chat
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
dispatch({
|
|
82
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
83
|
+
payload: ConversationState.Loading
|
|
84
|
+
});
|
|
85
|
+
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
68
86
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
87
|
|
|
70
88
|
|
|
@@ -72,12 +90,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
72
90
|
try {
|
|
73
91
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
74
92
|
|
|
75
|
-
let isStartChatSuccessful = false;
|
|
93
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
76
94
|
|
|
77
95
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
78
96
|
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
79
97
|
|
|
80
|
-
// Broadcasting limited cached chat details
|
|
81
98
|
BroadcastService.postMessage({
|
|
82
99
|
eventName: BroadcastEvent.ChatRetrievedFromCache,
|
|
83
100
|
payload: {
|
|
@@ -88,10 +105,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
88
105
|
}
|
|
89
106
|
|
|
90
107
|
try {
|
|
108
|
+
//Start widget load timer
|
|
91
109
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
92
110
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
93
111
|
Event: TelemetryEvent.StartChatSDKCall
|
|
94
|
-
});
|
|
112
|
+
}); // Set optional params
|
|
113
|
+
|
|
95
114
|
optionalParams = Object.assign({}, params, optionalParams);
|
|
96
115
|
await chatSDK.startChat(optionalParams);
|
|
97
116
|
isStartChatSuccessful = true;
|
|
@@ -102,46 +121,51 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
102
121
|
exception: `Failed to setup startChat: ${error}`
|
|
103
122
|
}
|
|
104
123
|
});
|
|
105
|
-
isStartChatSuccessful = false;
|
|
106
|
-
|
|
124
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
125
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
126
|
+
|
|
127
|
+
dispatch({
|
|
128
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
129
|
+
payload: ConversationState.Closed
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
} // New adapter creation
|
|
133
|
+
|
|
107
134
|
|
|
108
135
|
const newAdapter = await createAdapter(chatSDK);
|
|
109
136
|
setAdapter(newAdapter);
|
|
110
137
|
const chatToken = await chatSDK.getChatToken();
|
|
138
|
+
dispatch({
|
|
139
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
140
|
+
payload: chatToken
|
|
141
|
+
});
|
|
111
142
|
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));
|
|
112
143
|
|
|
113
|
-
if (
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
118
|
-
dispatch({
|
|
119
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
120
|
-
payload: chatToken
|
|
121
|
-
});
|
|
122
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
126
|
-
dispatch({
|
|
127
|
-
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
128
|
-
payload: liveChatContext
|
|
129
|
-
});
|
|
130
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
131
|
-
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
132
|
-
|
|
133
|
-
if (isStartChatSuccessful) {
|
|
134
|
-
dispatch({
|
|
135
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
136
|
-
payload: ConversationState.Active
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
144
|
+
if (persistedState) {
|
|
140
145
|
dispatch({
|
|
141
146
|
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
142
147
|
payload: persistedState
|
|
143
148
|
});
|
|
144
149
|
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
150
|
+
return;
|
|
151
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
155
|
+
dispatch({
|
|
156
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
157
|
+
payload: liveChatContext
|
|
158
|
+
}); // Set post chat context in state, no survey load
|
|
159
|
+
|
|
160
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
161
|
+
|
|
162
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
163
|
+
|
|
164
|
+
if (isStartChatSuccessful) {
|
|
165
|
+
dispatch({
|
|
166
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
167
|
+
payload: ConversationState.Active
|
|
168
|
+
});
|
|
145
169
|
}
|
|
146
170
|
|
|
147
171
|
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
@@ -168,18 +192,23 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
168
192
|
payload: ConversationState.OutOfOffice
|
|
169
193
|
});
|
|
170
194
|
}
|
|
195
|
+
} finally {
|
|
196
|
+
optionalParams = {};
|
|
171
197
|
}
|
|
172
198
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
199
|
|
|
174
200
|
|
|
175
201
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
176
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2,
|
|
202
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
177
203
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
// By pass this function in case of popout chat
|
|
205
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
181
208
|
|
|
182
|
-
|
|
209
|
+
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
|
|
210
|
+
|
|
211
|
+
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) {
|
|
183
212
|
var _persistedState$domai7;
|
|
184
213
|
|
|
185
214
|
dispatch({
|
|
@@ -194,17 +223,22 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
194
223
|
} else {
|
|
195
224
|
return false;
|
|
196
225
|
}
|
|
197
|
-
};
|
|
226
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
const setCustomContextParams = (props, chatSDK) => {
|
|
230
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
|
|
231
|
+
|
|
232
|
+
// Add custom context only for unauthenticated chat
|
|
233
|
+
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);
|
|
198
234
|
|
|
199
|
-
|
|
200
|
-
|
|
235
|
+
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)) {
|
|
236
|
+
var _persistedState$domai9;
|
|
201
237
|
|
|
202
|
-
// Add custom context if any only for unauthenticated chat
|
|
203
|
-
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
|
|
204
238
|
optionalParams = Object.assign({}, optionalParams, {
|
|
205
|
-
customContext:
|
|
239
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
|
|
206
240
|
});
|
|
207
241
|
}
|
|
208
242
|
};
|
|
209
243
|
|
|
210
|
-
export { prepareStartChat, initStartChat };
|
|
244
|
+
export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };
|