@microsoft/omnichannel-chat-widget 0.1.0-main.8e79cb8 → 0.1.0-main.a72fbb6
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 +14 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +18 -2
- package/lib/cjs/common/utils.js +49 -3
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -2
- package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -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 +124 -84
- package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +172 -89
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
- 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/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/cjs/contexts/createReducer.js +8 -0
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/esm/common/Constants.js +14 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +18 -2
- package/lib/esm/common/utils.js +37 -1
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
- package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -2
- package/lib/esm/components/livechatwidget/common/endChat.js +53 -20
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -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 +125 -86
- package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +168 -91
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
- 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/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/esm/contexts/createReducer.js +8 -0
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/types/common/Constants.d.ts +7 -0
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +18 -3
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
- package/lib/types/common/utils.d.ts +3 -0
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +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 +1 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
- package/package.json +2 -2
|
@@ -44,9 +44,9 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
|
44
44
|
exports.getChatReconnectContext = getChatReconnectContext;
|
|
45
45
|
|
|
46
46
|
const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
47
|
-
var _props$reconnectChatP, _props$
|
|
47
|
+
var _props$reconnectChatP, _props$authProps;
|
|
48
48
|
|
|
49
|
-
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$
|
|
49
|
+
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
|
|
50
50
|
|
|
51
51
|
/* && !isLoadWithState() */
|
|
52
52
|
) {
|
|
@@ -63,31 +63,31 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
63
63
|
|
|
64
64
|
exports.getReconnectIdForAuthenticatedChat = getReconnectIdForAuthenticatedChat;
|
|
65
65
|
|
|
66
|
-
const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
66
|
+
const handleUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
67
67
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
68
68
|
|
|
69
69
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
70
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
70
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
71
71
|
} else {
|
|
72
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
72
|
+
await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
|
|
73
73
|
}
|
|
74
74
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
exports.handleUnauthenticatedReconnectChat = handleUnauthenticatedReconnectChat;
|
|
78
78
|
|
|
79
|
-
const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
79
|
+
const startUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
80
80
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
81
81
|
|
|
82
82
|
if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
83
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
83
|
+
await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
|
|
84
84
|
}
|
|
85
85
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
exports.startUnauthenticatedReconnectChat = startUnauthenticatedReconnectChat;
|
|
89
89
|
|
|
90
|
-
const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
90
|
+
const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
91
91
|
const startUnauthenticatedReconnectChat = {
|
|
92
92
|
eventName: _TelemetryConstants.BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
93
93
|
};
|
|
@@ -105,7 +105,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
|
|
|
105
105
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
106
106
|
payload: _ConversationState.ConversationState.Loading
|
|
107
107
|
});
|
|
108
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
108
|
+
await initStartChat(chatSDK, authProps, dispatch, setAdapter, optionalParams);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
@@ -128,7 +128,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
|
|
|
128
128
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
|
|
131
|
+
const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, setAdapter, initStartChat) => {
|
|
132
132
|
const startUnauthenticatedReconnectChat = {
|
|
133
133
|
eventName: _TelemetryConstants.BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
134
134
|
};
|
|
@@ -153,26 +153,26 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
|
|
|
153
153
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
154
154
|
payload: _ConversationState.ConversationState.Loading
|
|
155
155
|
});
|
|
156
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
156
|
+
await initStartChat(chatSDK, authProps, dispatch, setAdapter);
|
|
157
157
|
}
|
|
158
158
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
161
|
+
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
162
162
|
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
163
163
|
|
|
164
164
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
165
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
165
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
166
166
|
}
|
|
167
167
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
|
|
169
169
|
|
|
170
170
|
exports.handleRedirectUnauthenticatedReconnectChat = handleRedirectUnauthenticatedReconnectChat;
|
|
171
171
|
|
|
172
|
-
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
172
|
+
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
173
173
|
if (reconnectAvailabilityResponse.redirectURL) {
|
|
174
174
|
redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
|
|
175
175
|
} else {
|
|
176
|
-
await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
|
|
176
|
+
await startNewChatEmptyRedirectionUrl(chatSDK, authProps, dispatch, setAdapter, initStartChat);
|
|
177
177
|
}
|
|
178
178
|
};
|
|
@@ -43,10 +43,6 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
|
|
46
|
-
dispatch({
|
|
47
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
48
|
-
payload: _ConversationState.ConversationState.Loading
|
|
49
|
-
});
|
|
50
46
|
dispatch({
|
|
51
47
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
52
48
|
payload: _ConversationState.ConversationState.Postchat
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.prepareStartChat = exports.initStartChat = void 0;
|
|
6
|
+
exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = void 0;
|
|
7
7
|
|
|
8
8
|
var _Constants = require("../../../common/Constants");
|
|
9
9
|
|
|
@@ -11,8 +11,6 @@ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants"
|
|
|
11
11
|
|
|
12
12
|
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
13
13
|
|
|
14
|
-
var _DataStoreManager = require("../../../common/contextDataStore/DataStoreManager");
|
|
15
|
-
|
|
16
14
|
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
17
15
|
|
|
18
16
|
var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
|
|
@@ -43,6 +41,9 @@ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-expli
|
|
|
43
41
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
44
42
|
var _props$reconnectChatP;
|
|
45
43
|
|
|
44
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
45
|
+
// Can connect to existing chat session
|
|
46
|
+
|
|
46
47
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
47
48
|
return;
|
|
48
49
|
} // Redirecting if unauthenticated reconnect chat expired
|
|
@@ -51,58 +52,75 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
51
52
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
52
53
|
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
53
54
|
|
|
54
|
-
await (0, _reconnectChatHelper.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);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const parseToJson = false;
|
|
58
|
-
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
59
|
-
const showPrechat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
|
|
55
|
+
await (0, _reconnectChatHelper.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);
|
|
56
|
+
return;
|
|
57
|
+
} // Getting reconnectId for authenticated chat
|
|
60
58
|
|
|
61
|
-
const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
85
|
-
payload: _ConversationState.ConversationState.Loading
|
|
86
|
-
});
|
|
87
|
-
setCustomContextParams(props, state);
|
|
88
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
60
|
+
const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
|
|
61
|
+
|
|
62
|
+
if (reconnectId) {
|
|
63
|
+
dispatch({
|
|
64
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
65
|
+
payload: reconnectId
|
|
66
|
+
});
|
|
67
|
+
dispatch({
|
|
68
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
69
|
+
payload: _ConversationState.ConversationState.ReconnectChat
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
} // Set custom context params
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
|
|
76
|
+
|
|
77
|
+
const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
|
|
78
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
79
|
+
|
|
80
|
+
setPreChatAndInitiateChat(chatSDK, props.authProps, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
91
81
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
82
|
|
|
93
83
|
|
|
94
84
|
exports.prepareStartChat = prepareStartChat;
|
|
95
85
|
|
|
96
|
-
const
|
|
86
|
+
const setPreChatAndInitiateChat = async (chatSDK, authProps, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
87
|
+
// Getting prechat Survey Context
|
|
88
|
+
const parseToJson = false;
|
|
89
|
+
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
90
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
91
|
+
|
|
92
|
+
if (showPrechat) {
|
|
93
|
+
dispatch({
|
|
94
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
95
|
+
payload: preChatSurveyResponse
|
|
96
|
+
});
|
|
97
|
+
dispatch({
|
|
98
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
99
|
+
payload: _ConversationState.ConversationState.Prechat
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
} //Initiate start chat
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
dispatch({
|
|
106
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
107
|
+
payload: _ConversationState.ConversationState.Loading
|
|
108
|
+
});
|
|
109
|
+
await initStartChat(chatSDK, authProps, dispatch, setAdapter);
|
|
110
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
114
|
+
|
|
115
|
+
const initStartChat = async (chatSDK, authProps, dispatch, setAdapter, params, persistedState) => {
|
|
97
116
|
try {
|
|
98
117
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
99
118
|
|
|
100
|
-
let isStartChatSuccessful = false;
|
|
119
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
101
120
|
|
|
102
121
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
103
122
|
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
104
123
|
|
|
105
|
-
// Broadcasting limited cached chat details
|
|
106
124
|
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
107
125
|
eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
|
|
108
126
|
payload: {
|
|
@@ -113,13 +131,20 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
113
131
|
}
|
|
114
132
|
|
|
115
133
|
try {
|
|
134
|
+
//Start widget load timer
|
|
116
135
|
_TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
|
|
117
136
|
|
|
118
137
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
119
138
|
Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
|
|
120
|
-
});
|
|
139
|
+
}); // Set optional params
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
|
|
143
|
+
|
|
144
|
+
if (authProps && authProps.setAuthTokenProviderToChatSdk) {
|
|
145
|
+
await authProps.setAuthTokenProviderToChatSdk(chatSDK, authProps.authClientFunction);
|
|
146
|
+
}
|
|
121
147
|
|
|
122
|
-
optionalParams = Object.assign({}, params, optionalParams);
|
|
123
148
|
await chatSDK.startChat(optionalParams);
|
|
124
149
|
isStartChatSuccessful = true;
|
|
125
150
|
} catch (error) {
|
|
@@ -130,46 +155,51 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
130
155
|
}
|
|
131
156
|
});
|
|
132
157
|
|
|
133
|
-
isStartChatSuccessful = false;
|
|
134
|
-
|
|
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.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
163
|
+
payload: _ConversationState.ConversationState.Closed
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
} // New adapter creation
|
|
167
|
+
|
|
135
168
|
|
|
136
169
|
const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
|
|
137
170
|
setAdapter(newAdapter);
|
|
138
171
|
const chatToken = await chatSDK.getChatToken();
|
|
172
|
+
dispatch({
|
|
173
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
174
|
+
payload: chatToken
|
|
175
|
+
});
|
|
139
176
|
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
|
|
140
177
|
|
|
141
|
-
if (
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
146
|
-
dispatch({
|
|
147
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
148
|
-
payload: chatToken
|
|
149
|
-
});
|
|
150
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
154
|
-
dispatch({
|
|
155
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
156
|
-
payload: liveChatContext
|
|
157
|
-
});
|
|
158
|
-
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
159
|
-
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
|
|
160
|
-
|
|
161
|
-
if (isStartChatSuccessful) {
|
|
162
|
-
dispatch({
|
|
163
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
164
|
-
payload: _ConversationState.ConversationState.Active
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
178
|
+
if (persistedState) {
|
|
168
179
|
dispatch({
|
|
169
180
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
170
181
|
payload: persistedState
|
|
171
182
|
});
|
|
172
183
|
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
|
|
184
|
+
return;
|
|
185
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
189
|
+
dispatch({
|
|
190
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
191
|
+
payload: liveChatContext
|
|
192
|
+
}); // Set post chat context in state, no survey load
|
|
193
|
+
|
|
194
|
+
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
195
|
+
|
|
196
|
+
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
|
|
197
|
+
|
|
198
|
+
if (isStartChatSuccessful) {
|
|
199
|
+
dispatch({
|
|
200
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
201
|
+
payload: _ConversationState.ConversationState.Active
|
|
202
|
+
});
|
|
173
203
|
}
|
|
174
204
|
|
|
175
205
|
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
@@ -198,6 +228,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
198
228
|
payload: _ConversationState.ConversationState.OutOfOffice
|
|
199
229
|
});
|
|
200
230
|
}
|
|
231
|
+
} finally {
|
|
232
|
+
optionalParams = {};
|
|
201
233
|
}
|
|
202
234
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
235
|
|
|
@@ -205,13 +237,16 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
205
237
|
exports.initStartChat = initStartChat;
|
|
206
238
|
|
|
207
239
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
208
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2,
|
|
240
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
|
|
241
|
+
|
|
242
|
+
// By pass this function in case of popout chat
|
|
243
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
209
246
|
|
|
210
|
-
const
|
|
211
|
-
const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
212
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
247
|
+
const persistedState = (0, _utils.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
|
|
213
248
|
|
|
214
|
-
if (persistedState
|
|
249
|
+
if (persistedState && !(0, _utils.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.ConversationState.Active) {
|
|
215
250
|
var _persistedState$domai7;
|
|
216
251
|
|
|
217
252
|
dispatch({
|
|
@@ -221,20 +256,25 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
221
256
|
const optionalParams = {
|
|
222
257
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
223
258
|
};
|
|
224
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
259
|
+
await initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
|
|
225
260
|
return true;
|
|
226
261
|
} else {
|
|
227
262
|
return false;
|
|
228
263
|
}
|
|
229
|
-
};
|
|
264
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
const setCustomContextParams = (props, chatSDK) => {
|
|
268
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
|
|
269
|
+
|
|
270
|
+
// Add custom context only for unauthenticated chat
|
|
271
|
+
const persistedState = (0, _utils.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);
|
|
230
272
|
|
|
231
|
-
|
|
232
|
-
|
|
273
|
+
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
274
|
+
var _persistedState$domai9;
|
|
233
275
|
|
|
234
|
-
// Add custom context if any only for unauthenticated chat
|
|
235
|
-
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
|
|
236
276
|
optionalParams = Object.assign({}, optionalParams, {
|
|
237
|
-
customContext:
|
|
277
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
|
|
238
278
|
});
|
|
239
279
|
}
|
|
240
280
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|