@microsoft/omnichannel-chat-widget 0.1.0-main.84a7035 → 0.1.0-main.886e5cf
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 +24 -3
- package/lib/cjs/common/telemetry/TelemetryManager.js +7 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +16 -13
- 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/defaultProps/dummyDefaultProps.js +11 -14
- 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 +15 -15
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +149 -70
- package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +198 -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/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 +24 -3
- package/lib/esm/common/telemetry/TelemetryManager.js +6 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +17 -11
- 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/defaultProps/dummyDefaultProps.js +11 -14
- 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 +17 -16
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +149 -73
- package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +190 -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/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 +23 -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 +5 -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 +5 -4
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
- 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/IAuthProps.d.ts +4 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- 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
|
@@ -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";
|
|
@@ -26,10 +26,13 @@ import gifUploadMiddleware from "../../webchatcontainerstateful/webchatcontrolle
|
|
|
26
26
|
import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlPlayerMiddleware";
|
|
27
27
|
import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
|
|
28
28
|
import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
|
|
29
|
-
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
29
|
+
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
30
|
+
import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
|
|
31
|
+
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
32
|
+
import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
33
|
|
|
31
34
|
export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
|
|
32
|
-
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;
|
|
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;
|
|
33
36
|
|
|
34
37
|
const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
|
|
35
38
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
|
|
@@ -63,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
63
66
|
|
|
64
67
|
if (isPostChatEnabled === "true") {
|
|
65
68
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
69
|
+
WebChatStoreLoader.store = null;
|
|
70
|
+
dispatch({
|
|
71
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
72
|
+
payload: ConversationState.PostchatLoading
|
|
73
|
+
});
|
|
74
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
66
75
|
const loadPostChatEvent = {
|
|
67
76
|
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
68
77
|
};
|
|
@@ -84,10 +93,14 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
84
93
|
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
85
94
|
payload: undefined
|
|
86
95
|
});
|
|
96
|
+
dispatch({
|
|
97
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
98
|
+
payload: undefined
|
|
99
|
+
});
|
|
87
100
|
};
|
|
88
101
|
|
|
89
102
|
webChatStore = createStore({}, //initial state
|
|
90
|
-
preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
104
|
...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
|
|
92
105
|
WebChatStoreLoader.store = webChatStore;
|
|
93
106
|
} // Initialize the remaining Web Chat props
|
|
@@ -105,7 +118,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
105
118
|
groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
|
|
106
119
|
typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
|
|
107
120
|
onTelemetry: createWebChatTelemetry(),
|
|
108
|
-
|
|
121
|
+
cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
|
|
122
|
+
...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
|
|
109
123
|
};
|
|
110
124
|
return webChatProps;
|
|
111
125
|
};
|
|
@@ -3,8 +3,9 @@ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/teleme
|
|
|
3
3
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
4
4
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
5
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
|
-
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
7
|
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
9
|
const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
9
10
|
try {
|
|
10
11
|
if (reconnectId) {
|
|
@@ -29,9 +30,9 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
32
|
-
var _props$reconnectChatP, _props$
|
|
33
|
+
var _props$reconnectChatP, _props$authProps;
|
|
33
34
|
|
|
34
|
-
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$
|
|
35
|
+
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$authProps = props.authProps) !== null && _props$authProps !== void 0 && _props$authProps.authClientFunction // TODO: Implement this after storage is in place
|
|
35
36
|
|
|
36
37
|
/* && !isLoadWithState() */
|
|
37
38
|
) {
|
|
@@ -46,27 +47,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
46
47
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
48
|
|
|
48
49
|
|
|
49
|
-
const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
50
|
+
const handleUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
50
51
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
51
52
|
|
|
52
53
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
53
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
54
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
54
55
|
} else {
|
|
55
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
56
|
+
await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
|
|
56
57
|
}
|
|
57
58
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
59
|
|
|
59
60
|
|
|
60
|
-
const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
61
|
+
const startUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
61
62
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
62
63
|
|
|
63
64
|
if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
64
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
65
|
+
await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
|
|
65
66
|
}
|
|
66
67
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
70
|
+
const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
70
71
|
const startUnauthenticatedReconnectChat = {
|
|
71
72
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
72
73
|
};
|
|
@@ -82,7 +83,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
|
|
|
82
83
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
83
84
|
payload: ConversationState.Loading
|
|
84
85
|
});
|
|
85
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
86
|
+
await initStartChat(chatSDK, authProps, dispatch, setAdapter, optionalParams);
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
@@ -104,7 +105,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
|
|
|
104
105
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
106
|
|
|
106
107
|
|
|
107
|
-
const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
|
|
108
|
+
const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, setAdapter, initStartChat) => {
|
|
108
109
|
const startUnauthenticatedReconnectChat = {
|
|
109
110
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
110
111
|
};
|
|
@@ -127,25 +128,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
|
|
|
127
128
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
128
129
|
payload: ConversationState.Loading
|
|
129
130
|
});
|
|
130
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
131
|
+
await initStartChat(chatSDK, authProps, dispatch, setAdapter);
|
|
131
132
|
}
|
|
132
133
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
134
|
|
|
134
135
|
|
|
135
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
136
|
+
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
136
137
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
137
138
|
|
|
138
139
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
139
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
140
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
140
141
|
}
|
|
141
142
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
143
|
|
|
143
144
|
|
|
144
|
-
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
145
|
+
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
145
146
|
if (reconnectAvailabilityResponse.redirectURL) {
|
|
146
147
|
redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
|
|
147
148
|
} else {
|
|
148
|
-
await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
|
|
149
|
+
await startNewChatEmptyRedirectionUrl(chatSDK, authProps, dispatch, setAdapter, initStartChat);
|
|
149
150
|
}
|
|
150
151
|
};
|
|
151
152
|
|
|
@@ -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
|
-
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,20 @@ 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, 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
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
18
|
|
|
17
19
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
18
20
|
var _props$reconnectChatP;
|
|
19
21
|
|
|
22
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
23
|
+
// Can connect to existing chat session
|
|
24
|
+
|
|
20
25
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
21
26
|
return;
|
|
22
27
|
} // Redirecting if unauthenticated reconnect chat expired
|
|
@@ -25,54 +30,95 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
25
30
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
26
31
|
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
27
32
|
|
|
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
|
|
33
|
+
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.authProps, 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);
|
|
34
|
+
return;
|
|
35
|
+
} // Getting reconnectId for authenticated chat
|
|
34
36
|
|
|
35
|
-
const reconnectId = await getReconnectIdForAuthenticatedChat(props, chatSDK);
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
payload: ConversationState.Loading
|
|
59
|
-
});
|
|
60
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
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, props.authProps, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
63
59
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
60
|
|
|
65
61
|
|
|
66
|
-
const
|
|
62
|
+
const setPreChatAndInitiateChat = async (chatSDK, authProps, 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, authProps, dispatch, setAdapter);
|
|
86
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, persistedState) => {
|
|
67
90
|
try {
|
|
68
91
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
69
92
|
|
|
93
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
94
|
+
|
|
95
|
+
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
96
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
97
|
+
|
|
98
|
+
BroadcastService.postMessage({
|
|
99
|
+
eventName: BroadcastEvent.ChatRetrievedFromCache,
|
|
100
|
+
payload: {
|
|
101
|
+
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,
|
|
102
|
+
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
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
70
107
|
try {
|
|
108
|
+
//Start widget load timer
|
|
71
109
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
72
110
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
73
111
|
Event: TelemetryEvent.StartChatSDKCall
|
|
74
|
-
});
|
|
75
|
-
|
|
112
|
+
}); // Set optional params
|
|
113
|
+
|
|
114
|
+
optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
|
|
115
|
+
|
|
116
|
+
if (authProps && authProps.setAuthTokenProviderToChatSdk) {
|
|
117
|
+
await authProps.setAuthTokenProviderToChatSdk(chatSDK, authProps.authClientFunction);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
await chatSDK.startChat(optionalParams);
|
|
121
|
+
isStartChatSuccessful = true;
|
|
76
122
|
} catch (error) {
|
|
77
123
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
78
124
|
Event: TelemetryEvent.StartChatMethodException,
|
|
@@ -80,43 +126,51 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
80
126
|
exception: `Failed to setup startChat: ${error}`
|
|
81
127
|
}
|
|
82
128
|
});
|
|
83
|
-
|
|
129
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
130
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
131
|
+
|
|
132
|
+
dispatch({
|
|
133
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
134
|
+
payload: ConversationState.Closed
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
} // New adapter creation
|
|
138
|
+
|
|
84
139
|
|
|
85
140
|
const newAdapter = await createAdapter(chatSDK);
|
|
86
141
|
setAdapter(newAdapter);
|
|
87
142
|
const chatToken = await chatSDK.getChatToken();
|
|
143
|
+
dispatch({
|
|
144
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
145
|
+
payload: chatToken
|
|
146
|
+
});
|
|
88
147
|
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
148
|
|
|
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());
|
|
149
|
+
if (persistedState) {
|
|
103
150
|
dispatch({
|
|
104
|
-
type: LiveChatWidgetActionType.
|
|
105
|
-
payload:
|
|
151
|
+
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
152
|
+
payload: persistedState
|
|
106
153
|
});
|
|
107
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch);
|
|
108
|
-
|
|
154
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
155
|
+
return;
|
|
156
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
157
|
|
|
158
|
+
|
|
159
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
160
|
+
dispatch({
|
|
161
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
162
|
+
payload: liveChatContext
|
|
163
|
+
}); // Set post chat context in state, no survey load
|
|
164
|
+
|
|
165
|
+
await setPostChatContextAndLoadSurvey(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
166
|
+
|
|
167
|
+
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
168
|
+
|
|
169
|
+
if (isStartChatSuccessful) {
|
|
110
170
|
dispatch({
|
|
111
171
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
112
172
|
payload: ConversationState.Active
|
|
113
173
|
});
|
|
114
|
-
} else {
|
|
115
|
-
dispatch({
|
|
116
|
-
type: LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
117
|
-
payload: persistedState
|
|
118
|
-
});
|
|
119
|
-
await setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
|
|
120
174
|
}
|
|
121
175
|
|
|
122
176
|
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
@@ -143,31 +197,53 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
143
197
|
payload: ConversationState.OutOfOffice
|
|
144
198
|
});
|
|
145
199
|
}
|
|
200
|
+
} finally {
|
|
201
|
+
optionalParams = {};
|
|
146
202
|
}
|
|
147
203
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
204
|
|
|
149
205
|
|
|
150
206
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
151
|
-
var
|
|
207
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
152
208
|
|
|
153
|
-
|
|
154
|
-
|
|
209
|
+
// By pass this function in case of popout chat
|
|
210
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
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
215
|
|
|
156
|
-
if (persistedState
|
|
157
|
-
var _persistedState$
|
|
216
|
+
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) {
|
|
217
|
+
var _persistedState$domai7;
|
|
158
218
|
|
|
159
219
|
dispatch({
|
|
160
220
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
161
221
|
payload: ConversationState.Loading
|
|
162
222
|
});
|
|
163
223
|
const optionalParams = {
|
|
164
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
224
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
165
225
|
};
|
|
166
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
226
|
+
await initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
|
|
167
227
|
return true;
|
|
168
228
|
} else {
|
|
169
229
|
return false;
|
|
170
230
|
}
|
|
231
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
const setCustomContextParams = (props, chatSDK) => {
|
|
235
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
|
|
236
|
+
|
|
237
|
+
// Add custom context only for unauthenticated chat
|
|
238
|
+
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);
|
|
239
|
+
|
|
240
|
+
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)) {
|
|
241
|
+
var _persistedState$domai9;
|
|
242
|
+
|
|
243
|
+
optionalParams = Object.assign({}, optionalParams, {
|
|
244
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
|
|
245
|
+
});
|
|
246
|
+
}
|
|
171
247
|
};
|
|
172
248
|
|
|
173
|
-
export { prepareStartChat, initStartChat };
|
|
249
|
+
export { prepareStartChat, initStartChat, setPreChatAndInitiateChat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|