@microsoft/omnichannel-chat-widget 0.1.0-main.2d7913d → 0.1.0-main.306098a
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/storage/default/defaultCacheManager.js +34 -0
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +114 -0
- package/lib/cjs/common/storage/default/defaultInMemoryDataStore.js +86 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +15 -0
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +31 -18
- package/lib/cjs/common/utils.js +20 -7
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -4
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
- package/lib/cjs/components/footerstateful/FooterStateful.js +5 -13
- package/lib/cjs/components/headerstateful/HeaderStateful.js +12 -5
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/authHelper.js +65 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +4 -0
- package/lib/cjs/components/livechatwidget/common/createFooter.js +7 -16
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +23 -8
- package/lib/cjs/components/livechatwidget/common/endChat.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +4 -0
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
- package/lib/cjs/components/livechatwidget/common/startChat.js +55 -27
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +139 -57
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +20 -4
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/{livechatwidget/interfaces/IAuthProps.js → webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js} +0 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +10 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -1
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +13 -5
- package/lib/cjs/contexts/createReducer.js +10 -2
- package/lib/esm/common/Constants.js +2 -0
- package/lib/esm/common/storage/default/defaultCacheManager.js +19 -0
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +102 -0
- package/lib/esm/common/storage/default/defaultInMemoryDataStore.js +71 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +15 -0
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +29 -13
- package/lib/esm/common/utils.js +14 -5
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -4
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
- package/lib/esm/components/footerstateful/FooterStateful.js +5 -13
- package/lib/esm/components/headerstateful/HeaderStateful.js +12 -5
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/authHelper.js +50 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +4 -1
- package/lib/esm/components/livechatwidget/common/createFooter.js +4 -15
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +23 -8
- package/lib/esm/components/livechatwidget/common/endChat.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +4 -0
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +55 -37
- package/lib/esm/components/livechatwidget/common/startChat.js +51 -28
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +138 -59
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +15 -2
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/{livechatwidget/interfaces/IAuthProps.js → webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js} +0 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +3 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -1
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +11 -5
- package/lib/esm/contexts/createReducer.js +10 -2
- package/lib/types/common/Constants.d.ts +1 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +4 -0
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -0
- package/lib/types/common/storage/default/defaultInMemoryDataStore.d.ts +6 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
- package/lib/types/common/utils.d.ts +5 -4
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -5
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -3
- package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -2
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IRenderingMiddlewareProps.d.ts +2 -1
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.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/defaultStyles/defaultReceivedMessageAnchorStyles.d.ts +2 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -2
- package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +1 -2
- package/package.json +5 -4
- package/lib/types/components/livechatwidget/interfaces/IAuthProps.d.ts +0 -4
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
3
|
+
import { isNullOrEmptyString } from "../../../common/utils";
|
|
4
|
+
|
|
5
|
+
const getAuthClientFunction = chatConfig => {
|
|
6
|
+
let authClientFunction = undefined;
|
|
7
|
+
|
|
8
|
+
if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
|
|
9
|
+
var _chatConfig$LiveChatC;
|
|
10
|
+
|
|
11
|
+
authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return authClientFunction;
|
|
15
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
|
|
19
|
+
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
20
|
+
|
|
21
|
+
if (getAuthToken && authClientFunction) {
|
|
22
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
23
|
+
Event: TelemetryEvent.GetAuthTokenCalled
|
|
24
|
+
});
|
|
25
|
+
const token = await getAuthToken(authClientFunction);
|
|
26
|
+
|
|
27
|
+
if (!isNullOrEmptyString(token)) {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
chatSDK.setAuthTokenProvider(async () => {
|
|
30
|
+
return token;
|
|
31
|
+
});
|
|
32
|
+
return true;
|
|
33
|
+
} else {
|
|
34
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
35
|
+
Event: TelemetryEvent.ReceivedNullOrEmptyToken
|
|
36
|
+
});
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return false;
|
|
42
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const removeAuthTokenProvider = chatSDK => {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
chatSDK.authenticatedUserToken = null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { getAuthClientFunction, handleAuthentication, removeAuthTokenProvider };
|
|
@@ -2,7 +2,8 @@ import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontr
|
|
|
2
2
|
import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
|
|
3
3
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
4
|
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
-
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
5
|
+
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
6
|
+
import { PauseActivitySubscriber } from "./ActivitySubscriber/PauseActivitySubscriber"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
7
|
|
|
7
8
|
export const createAdapter = async chatSDK => {
|
|
8
9
|
const chatAdapterOptionalParams = {
|
|
@@ -28,6 +29,8 @@ export const createAdapter = async chatSDK => {
|
|
|
28
29
|
|
|
29
30
|
if (chatSDK.isMockModeOn !== true) {
|
|
30
31
|
adapter = new ChatAdapterShim(adapter);
|
|
32
|
+
adapter.addSubscriber(new PauseActivitySubscriber());
|
|
33
|
+
return adapter.chatAdapter;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
return adapter;
|
|
@@ -3,25 +3,14 @@ import React from "react";
|
|
|
3
3
|
import { decodeComponentString } from "@microsoft/omnichannel-chat-components";
|
|
4
4
|
import { shouldShowFooter } from "../../../controller/componentController";
|
|
5
5
|
export const createFooter = (props, state) => {
|
|
6
|
-
var _props$
|
|
6
|
+
var _props$controlProps, _props$componentOverr;
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
hideDownloadTranscriptButton: true,
|
|
11
|
-
hideEmailTranscriptButton: true,
|
|
12
|
-
hideAudioNotificationButton: true
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const footer = !((_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hideFooter) && shouldShowFooter(state) ? decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.footer) || /*#__PURE__*/React.createElement(FooterStateful, {
|
|
8
|
+
const hideFooterDisplay = !((_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hideFooter) && shouldShowFooter(state) ? false : true;
|
|
9
|
+
const footer = decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.footer) || /*#__PURE__*/React.createElement(FooterStateful, {
|
|
16
10
|
footerProps: props.footerProps,
|
|
17
11
|
downloadTranscriptProps: props.downloadTranscriptProps,
|
|
18
12
|
audioNotificationProps: props.audioNotificationProps,
|
|
19
|
-
hideFooterDisplay:
|
|
20
|
-
}) : decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.footer) || /*#__PURE__*/React.createElement(FooterStateful, {
|
|
21
|
-
footerProps: footerPropsHidden,
|
|
22
|
-
downloadTranscriptProps: props.downloadTranscriptProps,
|
|
23
|
-
audioNotificationProps: props.audioNotificationProps,
|
|
24
|
-
hideFooterDisplay: true
|
|
13
|
+
hideFooterDisplay: hideFooterDisplay
|
|
25
14
|
});
|
|
26
15
|
return footer;
|
|
27
16
|
};
|
|
@@ -2,6 +2,8 @@ import { Constants } from "../../../common/Constants";
|
|
|
2
2
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
3
3
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
4
|
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
5
7
|
|
|
6
8
|
const isInternetConnected = async () => {
|
|
7
9
|
try {
|
|
@@ -18,8 +20,14 @@ export const createInternetConnectionChangeHandler = async () => {
|
|
|
18
20
|
const connected = await isInternetConnected();
|
|
19
21
|
|
|
20
22
|
if (!connected) {
|
|
23
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
24
|
+
Event: TelemetryEvent.NetworkDisconnected
|
|
25
|
+
});
|
|
21
26
|
NotificationHandler.notifyError(NotificationScenarios.InternetConnection, defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_NO_INTERNET_CONNECTION);
|
|
22
27
|
} else {
|
|
28
|
+
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
29
|
+
Event: TelemetryEvent.NetworkReconnected
|
|
30
|
+
});
|
|
23
31
|
NotificationHandler.notifySuccess(NotificationScenarios.InternetConnection, defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_INTERNET_BACK_ONLINE);
|
|
24
32
|
}
|
|
25
33
|
}; // Checking connection status on online & offline events due to possible false positives
|
|
@@ -318,7 +318,8 @@ export const dummyDefaultProps = {
|
|
|
318
318
|
hideChatTitle: false,
|
|
319
319
|
hideNotificationBubble: true,
|
|
320
320
|
unreadMessageString: "new messages",
|
|
321
|
-
largeUnreadMessageString: "99+"
|
|
321
|
+
largeUnreadMessageString: "99+",
|
|
322
|
+
ariaLabelUnreadMessageString: "you have new messages"
|
|
322
323
|
},
|
|
323
324
|
styleProps: {
|
|
324
325
|
generalStyleProps: {
|
|
@@ -869,7 +870,7 @@ export const dummyDefaultProps = {
|
|
|
869
870
|
className: undefined
|
|
870
871
|
},
|
|
871
872
|
closeButtonProps: {
|
|
872
|
-
id: "oc-lcw-header-
|
|
873
|
+
id: "oc-lcw-header-close-button",
|
|
873
874
|
type: "icon",
|
|
874
875
|
iconName: "ChromeClose",
|
|
875
876
|
ariaLabel: "Close",
|
|
@@ -1185,7 +1186,17 @@ export const dummyDefaultProps = {
|
|
|
1185
1186
|
hideSubtitle: false,
|
|
1186
1187
|
subtitleText: "Live chat support!",
|
|
1187
1188
|
hideCloseButton: false,
|
|
1188
|
-
|
|
1189
|
+
closeButtonProps: {
|
|
1190
|
+
id: "oc-lcw-proactivechat-closebutton",
|
|
1191
|
+
type: "icon",
|
|
1192
|
+
iconName: "ChromeClose",
|
|
1193
|
+
ariaLabel: "Close",
|
|
1194
|
+
imageIconProps: undefined,
|
|
1195
|
+
text: "Close",
|
|
1196
|
+
onClick: undefined,
|
|
1197
|
+
className: undefined,
|
|
1198
|
+
hideButtonTitle: true
|
|
1199
|
+
},
|
|
1189
1200
|
isBodyContainerHorizantal: false,
|
|
1190
1201
|
hideBodyTitle: false,
|
|
1191
1202
|
bodyTitleText: "Hi! Have any questions? I am here to help.",
|
|
@@ -1654,6 +1665,9 @@ export const dummyDefaultProps = {
|
|
|
1654
1665
|
},
|
|
1655
1666
|
attachmentSizeStyles: {
|
|
1656
1667
|
display: "none"
|
|
1668
|
+
},
|
|
1669
|
+
receivedMessageAnchorStyles: {
|
|
1670
|
+
color: "white"
|
|
1657
1671
|
}
|
|
1658
1672
|
},
|
|
1659
1673
|
localizedTexts: {
|
|
@@ -1681,11 +1695,12 @@ export const dummyDefaultProps = {
|
|
|
1681
1695
|
botMagicCode: {
|
|
1682
1696
|
disabled: false,
|
|
1683
1697
|
fwdUrl: ""
|
|
1698
|
+
},
|
|
1699
|
+
adaptiveCardStyles: {
|
|
1700
|
+
background: "white",
|
|
1701
|
+
color: "black"
|
|
1684
1702
|
}
|
|
1685
1703
|
},
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
setAuthTokenProviderToChatSdk: undefined
|
|
1689
|
-
},
|
|
1690
|
-
telemetryConfig: undefined
|
|
1704
|
+
telemetryConfig: undefined,
|
|
1705
|
+
getAuthToken: undefined
|
|
1691
1706
|
};
|
|
@@ -31,7 +31,7 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
|
|
|
31
31
|
if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
32
32
|
const skipEndChatSDK = false;
|
|
33
33
|
const skipCloseChat = true;
|
|
34
|
-
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat,
|
|
34
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
|
|
35
35
|
|
|
36
36
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
37
37
|
dispatch({
|
|
@@ -129,9 +129,9 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
if (postMessageToOtherTab) {
|
|
132
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
|
|
132
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
|
|
133
133
|
|
|
134
|
-
const endChatEventName = getWidgetEndChatEventName(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);
|
|
134
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
|
|
135
135
|
BroadcastService.postMessage({
|
|
136
136
|
eventName: endChatEventName
|
|
137
137
|
});
|
|
@@ -83,6 +83,10 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
} else {
|
|
86
|
+
dispatch({
|
|
87
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
88
|
+
payload: ConversationState.InActive
|
|
89
|
+
});
|
|
86
90
|
dispatch({
|
|
87
91
|
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
|
|
88
92
|
payload: true
|
|
@@ -4,25 +4,33 @@ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
|
4
4
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
5
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
6
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
|
|
9
|
+
const getChatReconnectContext = async (chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId) => {
|
|
10
|
+
if (isReconnectEnabled) {
|
|
11
|
+
try {
|
|
12
|
+
if (reconnectId) {
|
|
13
|
+
const chatReconnectOptionalParams = {
|
|
14
|
+
reconnectId: reconnectId
|
|
15
|
+
};
|
|
16
|
+
return await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
|
|
17
|
+
} else {
|
|
18
|
+
// set auth token to chat sdk to get reconnectId for auth chat
|
|
19
|
+
await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
20
|
+
const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext()); // remove auth token after reconnectId is fetched
|
|
21
|
+
// this will be reset later at start chat
|
|
22
|
+
|
|
23
|
+
removeAuthTokenProvider(chatSDK);
|
|
24
|
+
return reconnectChatContext;
|
|
24
25
|
}
|
|
25
|
-
})
|
|
26
|
+
} catch (ex) {
|
|
27
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
28
|
+
Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
|
|
29
|
+
ExceptionDetails: {
|
|
30
|
+
exception: ex
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
return null;
|
|
@@ -30,13 +38,23 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
|
30
38
|
|
|
31
39
|
|
|
32
40
|
const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
33
|
-
var _props$
|
|
41
|
+
var _props$chatConfig, _props$reconnectChatP;
|
|
42
|
+
|
|
43
|
+
let authClientFunction = undefined;
|
|
34
44
|
|
|
35
|
-
if ((_props$
|
|
45
|
+
if ((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) {
|
|
46
|
+
var _props$chatConfig2, _props$chatConfig2$Li;
|
|
47
|
+
|
|
48
|
+
authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction // TODO: Implement this after storage is in place
|
|
36
52
|
|
|
37
53
|
/* && !isLoadWithState() */
|
|
38
54
|
) {
|
|
39
|
-
|
|
55
|
+
var _props$reconnectChatP2;
|
|
56
|
+
|
|
57
|
+
const previousActiveSessionResponse = await getChatReconnectContext(chatSDK, props.chatConfig, props.getAuthToken, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled);
|
|
40
58
|
|
|
41
59
|
if (previousActiveSessionResponse && previousActiveSessionResponse.reconnectId) {
|
|
42
60
|
return previousActiveSessionResponse.reconnectId;
|
|
@@ -47,27 +65,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
47
65
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
66
|
|
|
49
67
|
|
|
50
|
-
const handleUnauthenticatedReconnectChat = async (chatSDK,
|
|
51
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
68
|
+
const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
69
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
52
70
|
|
|
53
71
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
54
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK,
|
|
72
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
55
73
|
} else {
|
|
56
|
-
await setReconnectIdAndStartChat(chatSDK,
|
|
74
|
+
await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
|
|
57
75
|
}
|
|
58
76
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
77
|
|
|
60
78
|
|
|
61
|
-
const startUnauthenticatedReconnectChat = async (chatSDK,
|
|
62
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
79
|
+
const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat) => {
|
|
80
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
63
81
|
|
|
64
82
|
if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
65
|
-
await setReconnectIdAndStartChat(chatSDK,
|
|
83
|
+
await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
|
|
66
84
|
}
|
|
67
85
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
86
|
|
|
69
87
|
|
|
70
|
-
const setReconnectIdAndStartChat = async (chatSDK,
|
|
88
|
+
const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
71
89
|
const startUnauthenticatedReconnectChat = {
|
|
72
90
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
73
91
|
};
|
|
@@ -83,7 +101,7 @@ const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapt
|
|
|
83
101
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
84
102
|
payload: ConversationState.Loading
|
|
85
103
|
});
|
|
86
|
-
await initStartChat(chatSDK,
|
|
104
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, optionalParams);
|
|
87
105
|
};
|
|
88
106
|
|
|
89
107
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
@@ -105,7 +123,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
|
|
|
105
123
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
124
|
|
|
107
125
|
|
|
108
|
-
const startNewChatEmptyRedirectionUrl = async (chatSDK,
|
|
126
|
+
const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
|
|
109
127
|
const startUnauthenticatedReconnectChat = {
|
|
110
128
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
111
129
|
};
|
|
@@ -128,25 +146,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, set
|
|
|
128
146
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
129
147
|
payload: ConversationState.Loading
|
|
130
148
|
});
|
|
131
|
-
await initStartChat(chatSDK,
|
|
149
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
132
150
|
}
|
|
133
151
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
152
|
|
|
135
153
|
|
|
136
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK,
|
|
137
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
154
|
+
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, isReconnectEnabled, reconnectId, redirectInSameWindow) => {
|
|
155
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
138
156
|
|
|
139
157
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
140
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK,
|
|
158
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
141
159
|
}
|
|
142
160
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
161
|
|
|
144
162
|
|
|
145
|
-
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK,
|
|
163
|
+
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
146
164
|
if (reconnectAvailabilityResponse.redirectURL) {
|
|
147
165
|
redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
|
|
148
166
|
} else {
|
|
149
|
-
await startNewChatEmptyRedirectionUrl(chatSDK,
|
|
167
|
+
await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
|
|
150
168
|
}
|
|
151
169
|
};
|
|
152
170
|
|
|
@@ -13,14 +13,19 @@ import { getReconnectIdForAuthenticatedChat, handleRedirectUnauthenticatedReconn
|
|
|
13
13
|
import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
|
|
14
14
|
import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
|
|
15
15
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
16
|
-
|
|
16
|
+
import { ActivityStreamHandler } from "./ActivityStreamHandler";
|
|
17
|
+
import { getAuthClientFunction, handleAuthentication } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
|
|
17
19
|
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
20
|
|
|
21
|
+
let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
|
|
19
23
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
20
|
-
var _props$reconnectChatP;
|
|
24
|
+
var _props$controlProps, _props$reconnectChatP;
|
|
21
25
|
|
|
22
26
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId; // Can connect to existing chat session
|
|
24
29
|
|
|
25
30
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
26
31
|
return;
|
|
@@ -28,9 +33,9 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
28
33
|
|
|
29
34
|
|
|
30
35
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
31
|
-
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
36
|
+
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
32
37
|
|
|
33
|
-
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.
|
|
38
|
+
await handleRedirectUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.redirectInSameWindow);
|
|
34
39
|
return;
|
|
35
40
|
} // Getting reconnectId for authenticated chat
|
|
36
41
|
|
|
@@ -47,19 +52,17 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
47
52
|
payload: ConversationState.ReconnectChat
|
|
48
53
|
});
|
|
49
54
|
return;
|
|
50
|
-
} //
|
|
55
|
+
} // Setting Proactive chat settings
|
|
51
56
|
|
|
52
57
|
|
|
53
|
-
setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
|
|
54
|
-
|
|
55
58
|
const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
|
|
56
59
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
57
60
|
|
|
58
|
-
setPreChatAndInitiateChat(chatSDK, props.
|
|
61
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
59
62
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
63
|
|
|
61
64
|
|
|
62
|
-
const setPreChatAndInitiateChat = async (chatSDK,
|
|
65
|
+
const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
63
66
|
// Getting prechat Survey Context
|
|
64
67
|
const parseToJson = false;
|
|
65
68
|
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
@@ -82,14 +85,25 @@ const setPreChatAndInitiateChat = async (chatSDK, authProps, dispatch, setAdapte
|
|
|
82
85
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
83
86
|
payload: ConversationState.Loading
|
|
84
87
|
});
|
|
85
|
-
await initStartChat(chatSDK,
|
|
88
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
86
89
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
90
|
|
|
88
91
|
|
|
89
|
-
const initStartChat = async (chatSDK,
|
|
92
|
+
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
90
93
|
try {
|
|
91
94
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
92
95
|
|
|
96
|
+
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
97
|
+
|
|
98
|
+
if (getAuthToken && authClientFunction) {
|
|
99
|
+
// set auth token to chat sdk before start chat
|
|
100
|
+
const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
101
|
+
|
|
102
|
+
if (!authSuccess) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
93
107
|
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
94
108
|
|
|
95
109
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -109,14 +123,10 @@ const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, p
|
|
|
109
123
|
TelemetryTimers.WidgetLoadTimer = createTimer();
|
|
110
124
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
111
125
|
Event: TelemetryEvent.StartChatSDKCall
|
|
112
|
-
}); // Set
|
|
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
|
-
}
|
|
126
|
+
}); // Set custom context params
|
|
119
127
|
|
|
128
|
+
setCustomContextParams(chatSDK);
|
|
129
|
+
optionalParams = Object.assign({}, params, optionalParams);
|
|
120
130
|
await chatSDK.startChat(optionalParams);
|
|
121
131
|
isStartChatSuccessful = true;
|
|
122
132
|
} catch (error) {
|
|
@@ -167,6 +177,7 @@ const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, p
|
|
|
167
177
|
await updateSessionDataForTelemetry(chatSDK, dispatch); // Set app state to Active
|
|
168
178
|
|
|
169
179
|
if (isStartChatSuccessful) {
|
|
180
|
+
ActivityStreamHandler.uncork();
|
|
170
181
|
dispatch({
|
|
171
182
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
172
183
|
payload: ConversationState.Active
|
|
@@ -199,19 +210,20 @@ const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, p
|
|
|
199
210
|
}
|
|
200
211
|
} finally {
|
|
201
212
|
optionalParams = {};
|
|
213
|
+
widgetInstanceId = "";
|
|
202
214
|
}
|
|
203
215
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
216
|
|
|
205
217
|
|
|
206
218
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
207
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
219
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
|
|
208
220
|
|
|
209
221
|
// By pass this function in case of popout chat
|
|
210
222
|
if (state.appStates.skipChatButtonRendering === true) {
|
|
211
223
|
return false;
|
|
212
224
|
}
|
|
213
225
|
|
|
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
|
|
226
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? ""); //Connect to only active chat session
|
|
215
227
|
|
|
216
228
|
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active) {
|
|
217
229
|
var _persistedState$domai7;
|
|
@@ -223,7 +235,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
223
235
|
const optionalParams = {
|
|
224
236
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
225
237
|
};
|
|
226
|
-
await initStartChat(chatSDK, props.
|
|
238
|
+
await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
227
239
|
return true;
|
|
228
240
|
} else {
|
|
229
241
|
return false;
|
|
@@ -231,17 +243,28 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
231
243
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
244
|
|
|
233
245
|
|
|
234
|
-
const setCustomContextParams =
|
|
235
|
-
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4,
|
|
246
|
+
const setCustomContextParams = chatSDK => {
|
|
247
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
|
|
236
248
|
|
|
237
249
|
// 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);
|
|
250
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
|
|
239
251
|
|
|
240
|
-
if (!
|
|
241
|
-
var _persistedState$domai9;
|
|
252
|
+
if (!isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
253
|
+
var _persistedState$domai9, _persistedState$domai10;
|
|
254
|
+
|
|
255
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
|
|
256
|
+
const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
|
|
257
|
+
TelemetryHelper.logSDKEvent(LogLevel.WARN, {
|
|
258
|
+
Event: TelemetryEvent.StartChatMethodException,
|
|
259
|
+
ExceptionDetails: {
|
|
260
|
+
exception: errorMessage
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
throw new Error(errorMessage);
|
|
264
|
+
}
|
|
242
265
|
|
|
243
266
|
optionalParams = Object.assign({}, optionalParams, {
|
|
244
|
-
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
267
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
|
|
245
268
|
});
|
|
246
269
|
}
|
|
247
270
|
};
|