@microsoft/omnichannel-chat-widget 0.1.0-main.fb426ed → 0.1.0-main.fdf1fdf
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 +18 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +21 -3
- package/lib/cjs/common/utils.js +75 -2
- 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 +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/authHelper.js +52 -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 +13 -3
- package/lib/cjs/components/livechatwidget/common/endChat.js +68 -22
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +20 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
- 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 +163 -80
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +231 -91
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -7
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +91 -0
- 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/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -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 +3 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/cjs/contexts/createReducer.js +16 -0
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/esm/common/Constants.js +18 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +21 -3
- package/lib/esm/common/utils.js +52 -0
- 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 +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/authHelper.js +39 -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 +13 -3
- package/lib/esm/components/livechatwidget/common/endChat.js +65 -22
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +19 -5
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +56 -37
- 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 +157 -82
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +223 -94
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +82 -0
- 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/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -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 +3 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
- package/lib/esm/contexts/createReducer.js +16 -0
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/types/common/Constants.d.ts +9 -1
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +21 -4
- package/lib/types/common/utils.d.ts +7 -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/authHelper.d.ts +4 -0
- 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/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 +1 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -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/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +4 -1
- package/package.json +4 -3
|
@@ -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");
|
|
@@ -35,10 +33,23 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
|
|
|
35
33
|
|
|
36
34
|
var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
|
|
37
35
|
|
|
36
|
+
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
37
|
+
|
|
38
|
+
var _ActivityStreamHandler = require("./ActivityStreamHandler");
|
|
39
|
+
|
|
40
|
+
var _authHelper = require("./authHelper");
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
43
|
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
44
|
|
|
45
|
+
let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
|
|
40
47
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
41
|
-
var _props$reconnectChatP;
|
|
48
|
+
var _props$controlProps, _props$reconnectChatP;
|
|
49
|
+
|
|
50
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
51
|
+
|
|
52
|
+
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
|
|
42
53
|
|
|
43
54
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
44
55
|
return;
|
|
@@ -46,63 +57,99 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
46
57
|
|
|
47
58
|
|
|
48
59
|
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
49
|
-
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
60
|
+
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
50
61
|
|
|
51
|
-
await (0, _reconnectChatHelper.handleRedirectUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const parseToJson = false;
|
|
55
|
-
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
56
|
-
const showPrechat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
|
|
62
|
+
await (0, _reconnectChatHelper.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);
|
|
63
|
+
return;
|
|
64
|
+
} // Getting reconnectId for authenticated chat
|
|
57
65
|
|
|
58
|
-
const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} else {
|
|
80
|
-
dispatch({
|
|
81
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
82
|
-
payload: _ConversationState.ConversationState.Loading
|
|
83
|
-
});
|
|
84
|
-
setCustomContextParams(props, state);
|
|
85
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
67
|
+
const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
|
|
68
|
+
|
|
69
|
+
if (reconnectId) {
|
|
70
|
+
dispatch({
|
|
71
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
72
|
+
payload: reconnectId
|
|
73
|
+
});
|
|
74
|
+
dispatch({
|
|
75
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
76
|
+
payload: _ConversationState.ConversationState.ReconnectChat
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
} // Setting Proactive chat settings
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
|
|
83
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
84
|
+
|
|
85
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
88
86
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
87
|
|
|
90
88
|
|
|
91
89
|
exports.prepareStartChat = prepareStartChat;
|
|
92
90
|
|
|
93
|
-
const
|
|
91
|
+
const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
92
|
+
// Getting prechat Survey Context
|
|
93
|
+
const parseToJson = false;
|
|
94
|
+
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
95
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
96
|
+
|
|
97
|
+
if (showPrechat) {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
100
|
+
payload: preChatSurveyResponse
|
|
101
|
+
});
|
|
102
|
+
dispatch({
|
|
103
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
104
|
+
payload: _ConversationState.ConversationState.Prechat
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
} //Initiate start chat
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
dispatch({
|
|
111
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
112
|
+
payload: _ConversationState.ConversationState.Loading
|
|
113
|
+
});
|
|
114
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
115
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
119
|
+
|
|
120
|
+
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
94
121
|
try {
|
|
95
122
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
96
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
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
130
|
+
eventName: _TelemetryConstants.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
|
+
|
|
97
138
|
try {
|
|
139
|
+
//Start widget load timer
|
|
98
140
|
_TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
|
|
99
141
|
|
|
100
142
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
101
143
|
Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
|
|
102
|
-
});
|
|
144
|
+
}); // Set custom context params
|
|
103
145
|
|
|
104
|
-
|
|
146
|
+
|
|
147
|
+
setCustomContextParams(chatSDK);
|
|
148
|
+
optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
|
|
149
|
+
|
|
150
|
+
await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
|
|
105
151
|
await chatSDK.startChat(optionalParams);
|
|
152
|
+
isStartChatSuccessful = true;
|
|
106
153
|
} catch (error) {
|
|
107
154
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
108
155
|
Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
|
|
@@ -110,43 +157,54 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
110
157
|
exception: `Failed to setup startChat: ${error}`
|
|
111
158
|
}
|
|
112
159
|
});
|
|
113
|
-
|
|
160
|
+
|
|
161
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
162
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
163
|
+
|
|
164
|
+
dispatch({
|
|
165
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
166
|
+
payload: _ConversationState.ConversationState.Closed
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
169
|
+
} // New adapter creation
|
|
170
|
+
|
|
114
171
|
|
|
115
172
|
const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
|
|
116
173
|
setAdapter(newAdapter);
|
|
117
174
|
const chatToken = await chatSDK.getChatToken();
|
|
175
|
+
dispatch({
|
|
176
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
177
|
+
payload: chatToken
|
|
178
|
+
});
|
|
118
179
|
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));
|
|
119
180
|
|
|
120
|
-
if (
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
125
|
-
dispatch({
|
|
126
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
127
|
-
payload: chatToken
|
|
128
|
-
});
|
|
129
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
181
|
+
if (persistedState) {
|
|
133
182
|
dispatch({
|
|
134
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.
|
|
135
|
-
payload:
|
|
183
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
184
|
+
payload: persistedState
|
|
136
185
|
});
|
|
137
|
-
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
138
|
-
|
|
186
|
+
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
|
|
187
|
+
return;
|
|
188
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
192
|
+
dispatch({
|
|
193
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
194
|
+
payload: liveChatContext
|
|
195
|
+
}); // Set post chat context in state, no survey load
|
|
196
|
+
|
|
197
|
+
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
198
|
+
|
|
199
|
+
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
|
|
200
|
+
|
|
201
|
+
if (isStartChatSuccessful) {
|
|
202
|
+
_ActivityStreamHandler.ActivityStreamHandler.uncork();
|
|
139
203
|
|
|
140
204
|
dispatch({
|
|
141
205
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
142
206
|
payload: _ConversationState.ConversationState.Active
|
|
143
207
|
});
|
|
144
|
-
} else {
|
|
145
|
-
dispatch({
|
|
146
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
147
|
-
payload: persistedState
|
|
148
|
-
});
|
|
149
|
-
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
|
|
150
208
|
}
|
|
151
209
|
|
|
152
210
|
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
@@ -175,6 +233,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
175
233
|
payload: _ConversationState.ConversationState.OutOfOffice
|
|
176
234
|
});
|
|
177
235
|
}
|
|
236
|
+
} finally {
|
|
237
|
+
optionalParams = {};
|
|
238
|
+
widgetInstanceId = "";
|
|
178
239
|
}
|
|
179
240
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
180
241
|
|
|
@@ -182,35 +243,57 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
182
243
|
exports.initStartChat = initStartChat;
|
|
183
244
|
|
|
184
245
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
185
|
-
var
|
|
246
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
|
|
247
|
+
|
|
248
|
+
// By pass this function in case of popout chat
|
|
249
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
186
252
|
|
|
187
|
-
const
|
|
188
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
253
|
+
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, (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
|
|
189
254
|
|
|
190
|
-
if (persistedState
|
|
191
|
-
var _persistedState$
|
|
255
|
+
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) {
|
|
256
|
+
var _persistedState$domai7;
|
|
192
257
|
|
|
193
258
|
dispatch({
|
|
194
259
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
195
260
|
payload: _ConversationState.ConversationState.Loading
|
|
196
261
|
});
|
|
197
262
|
const optionalParams = {
|
|
198
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
263
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
199
264
|
};
|
|
200
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
265
|
+
await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
201
266
|
return true;
|
|
202
267
|
} else {
|
|
203
268
|
return false;
|
|
204
269
|
}
|
|
205
|
-
};
|
|
270
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
const setCustomContextParams = chatSDK => {
|
|
274
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
|
|
275
|
+
|
|
276
|
+
// Add custom context only for unauthenticated chat
|
|
277
|
+
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, widgetInstanceId ?? "");
|
|
278
|
+
|
|
279
|
+
if (!(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
280
|
+
var _persistedState$domai9, _persistedState$domai10;
|
|
281
|
+
|
|
282
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
|
|
283
|
+
const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
|
|
206
284
|
|
|
207
|
-
|
|
208
|
-
|
|
285
|
+
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.WARN, {
|
|
286
|
+
Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
|
|
287
|
+
ExceptionDetails: {
|
|
288
|
+
exception: errorMessage
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
throw new Error(errorMessage);
|
|
293
|
+
}
|
|
209
294
|
|
|
210
|
-
// Add custom context if any only for unauthenticated chat
|
|
211
|
-
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) {
|
|
212
295
|
optionalParams = Object.assign({}, optionalParams, {
|
|
213
|
-
customContext:
|
|
296
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
|
|
214
297
|
});
|
|
215
298
|
}
|
|
216
299
|
};
|