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