@microsoft/omnichannel-chat-widget 0.1.0-main.0c0fd47 → 0.1.0-main.0d1c6e4
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 +7 -34
- package/lib/cjs/common/Constants.js +12 -3
- package/lib/cjs/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/cjs/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/cjs/common/utils.js +23 -2
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +139 -0
- package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +36 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -10
- package/lib/cjs/components/livechatwidget/common/endChat.js +43 -63
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +11 -49
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +70 -59
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +81 -43
- package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +7 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/cjs/contexts/common/ConversationEndEntity.js +12 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
- package/lib/cjs/contexts/createReducer.js +28 -2
- package/lib/cjs/hooks/useDebounce.js +28 -0
- package/lib/cjs/hooks/useWindowDimensions.js +30 -0
- package/lib/cjs/plugins/newMessageEventHandler.js +14 -0
- package/lib/esm/common/Constants.js +10 -2
- package/lib/esm/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/esm/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/esm/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/esm/common/utils.js +20 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +134 -0
- package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +30 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -10
- package/lib/esm/components/livechatwidget/common/endChat.js +45 -65
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -51
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +6 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +70 -59
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +82 -44
- package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +5 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/esm/contexts/common/ConversationEndEntity.js +5 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
- package/lib/esm/contexts/createReducer.js +28 -2
- package/lib/esm/hooks/useDebounce.js +22 -0
- package/lib/esm/hooks/useWindowDimensions.js +23 -0
- package/lib/esm/plugins/newMessageEventHandler.js +14 -0
- package/lib/types/common/Constants.d.ts +9 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +1 -1
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +31 -6
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +1 -0
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +4 -0
- package/lib/types/common/utils.d.ts +1 -0
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +0 -7
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +6 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -3
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.d.ts +1 -1
- package/lib/types/contexts/common/ConversationEndEntity.d.ts +4 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +5 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -7
- package/lib/types/hooks/useDebounce.d.ts +3 -0
- package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
- package/package.json +3 -3
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setPostChatContextAndLoadSurvey = void 0;
|
|
6
|
+
exports.setPostChatContextAndLoadSurvey = exports.initiatePostChat = exports.checkPostChatEnabled = void 0;
|
|
7
7
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
8
8
|
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
9
9
|
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
10
10
|
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
11
11
|
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
12
|
+
var _Constants = require("../../../common/Constants");
|
|
13
|
+
var _endChat = require("./endChat");
|
|
14
|
+
var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
|
|
15
|
+
var _utils = require("../../../common/utils");
|
|
16
|
+
var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
|
|
17
|
+
var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
|
|
18
|
+
var _ConversationEndEntity = require("../../../contexts/common/ConversationEndEntity");
|
|
12
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
20
|
const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
|
|
14
21
|
try {
|
|
@@ -41,4 +48,249 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
|
|
|
41
48
|
});
|
|
42
49
|
});
|
|
43
50
|
};
|
|
44
|
-
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
|
|
54
|
+
const checkPostChatEnabled = (props, state) => {
|
|
55
|
+
var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
|
|
56
|
+
const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
|
|
57
|
+
return isPostChatEnabled === _Constants.Constants.true;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
exports.checkPostChatEnabled = checkPostChatEnabled;
|
|
62
|
+
const initiatePostChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
|
|
63
|
+
// Check if Postchat already in progress and handle case where chat is ended by customer
|
|
64
|
+
if (state.appStates.postChatWorkflowInProgress && state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
|
|
65
|
+
await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Conversation Details call required by customer as well as agent
|
|
70
|
+
const conversationDetails = await getConversationDetailsCall(chatSDK);
|
|
71
|
+
// Start Postchat workflow
|
|
72
|
+
dispatch({
|
|
73
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
|
|
74
|
+
payload: true
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Below logic checks if agent or bot or noone joins conversation and handles them separately
|
|
78
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.userParticipantTypeTag) {
|
|
79
|
+
if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
|
|
80
|
+
// Set use bot settings to false
|
|
81
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
|
|
82
|
+
} else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
|
|
83
|
+
await postChatInitiatedByAgent(props, setWebChatStyles, dispatch, state);
|
|
84
|
+
} else {
|
|
85
|
+
const error = `Conversation was Ended after agent joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
86
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
87
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
88
|
+
ExceptionDetails: {
|
|
89
|
+
exception: error
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
throw new Error(error);
|
|
93
|
+
}
|
|
94
|
+
} else if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.botParticipantTypeTag) {
|
|
95
|
+
// Set Use bot survey to true
|
|
96
|
+
dispatch({
|
|
97
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
|
|
98
|
+
payload: true
|
|
99
|
+
});
|
|
100
|
+
if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
|
|
101
|
+
// Set use bot settings to true
|
|
102
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, true);
|
|
103
|
+
} else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
|
|
104
|
+
await postChatInitiatedByBot(props, setWebChatStyles, dispatch, state);
|
|
105
|
+
} else {
|
|
106
|
+
const error = `Conversation was Ended after bot joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
107
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
108
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
109
|
+
ExceptionDetails: {
|
|
110
|
+
exception: error
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
throw new Error(error);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
|
|
117
|
+
// No one has joined chat will be handled by postChat customer
|
|
118
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
|
|
119
|
+
} else {
|
|
120
|
+
const error = `ConversationDetails and App state was not set correctly: conversationDetails = ${JSON.stringify(conversationDetails)} , conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
121
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
122
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
123
|
+
ExceptionDetails: {
|
|
124
|
+
exception: error
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
throw new Error(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Function for link mode postchat workflow which is essentially same for both customer and agent
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
exports.initiatePostChat = initiatePostChat;
|
|
135
|
+
const linkModePostChatWorkflow = (props, dispatch, setWebChatStyles) => {
|
|
136
|
+
var _props$webChatContain, _props$webChatContain2;
|
|
137
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
138
|
+
Event: _TelemetryConstants.TelemetryEvent.LinkModePostChatWorkflowStarted
|
|
139
|
+
});
|
|
140
|
+
dispatch({
|
|
141
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
142
|
+
payload: _ConversationState.ConversationState.InActive
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Disable SendBox
|
|
146
|
+
if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
|
+
setWebChatStyles(styles => {
|
|
149
|
+
return {
|
|
150
|
+
...styles,
|
|
151
|
+
hideSendBox: true
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Function for embed mode postchat workflow which is essentially same for both customer and agent
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
|
+
const embedModePostChatWorkflow = async (dispatch, state) => {
|
|
160
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
161
|
+
Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
|
|
162
|
+
});
|
|
163
|
+
if (state.domainStates.postChatContext) {
|
|
164
|
+
dispatch({
|
|
165
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
166
|
+
payload: _ConversationState.ConversationState.PostchatLoading
|
|
167
|
+
});
|
|
168
|
+
await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
|
|
169
|
+
const loadPostChatEvent = {
|
|
170
|
+
eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
|
|
171
|
+
};
|
|
172
|
+
_omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
|
|
173
|
+
} else {
|
|
174
|
+
const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
|
|
175
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
176
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
177
|
+
ExceptionDetails: {
|
|
178
|
+
exception: error
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
throw new Error(error);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// Function will handle only postchat cases initiated by customer
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
+
const postChatInitiatedByCustomer = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, shouldUseBotSetting) => {
|
|
188
|
+
let postChatSurveyMode = "";
|
|
189
|
+
if (shouldUseBotSetting) {
|
|
190
|
+
var _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4;
|
|
191
|
+
postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveybotsurveymode);
|
|
192
|
+
} else {
|
|
193
|
+
var _props$chatConfig3, _props$chatConfig3$Li, _state$domainStates$l5, _state$domainStates$l6;
|
|
194
|
+
postChatSurveyMode = ((_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : (_state$domainStates$l6 = _state$domainStates$l5.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.msdyn_postconversationsurveymode);
|
|
195
|
+
}
|
|
196
|
+
// Check if agent or bot has joined conversation
|
|
197
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
|
|
198
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
199
|
+
Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromCustomer,
|
|
200
|
+
Description: shouldUseBotSetting ? "PostChat Workflow was started by customer using bot settings" : "PostChat Workflow was started by customer using agent settings"
|
|
201
|
+
});
|
|
202
|
+
const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
203
|
+
if (chatSession) {
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
chatSDK.chatToken = chatSession.chatToken ?? {};
|
|
206
|
+
chatSDK.requestId = chatSession.requestId;
|
|
207
|
+
}
|
|
208
|
+
// End chat call to end chatsdk but not close chat, only if chat ended by customer
|
|
209
|
+
await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
|
|
210
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
211
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
212
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
213
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
214
|
+
} else {
|
|
215
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
216
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
217
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
218
|
+
ExceptionDetails: {
|
|
219
|
+
exception: error
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
throw new Error(error);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
// Agent did not join chat so end chat normally
|
|
226
|
+
await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Function will handle only postchat cases initiated by agent
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
|
+
const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
|
|
233
|
+
var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
|
|
234
|
+
const postChatSurveyMode = ((_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : (_state$domainStates$l8 = _state$domainStates$l7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l8 === void 0 ? void 0 : _state$domainStates$l8.msdyn_postconversationsurveymode);
|
|
235
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
236
|
+
Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromAgent,
|
|
237
|
+
Description: "PostChat Workflow was started by agent"
|
|
238
|
+
});
|
|
239
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
240
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
241
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
242
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
243
|
+
} else {
|
|
244
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
245
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
246
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
247
|
+
ExceptionDetails: {
|
|
248
|
+
exception: error
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
throw new Error(error);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// Function will handle only postchat cases initiated by bot
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
257
|
+
const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
|
|
258
|
+
var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
|
|
259
|
+
const postChatSurveyMode = ((_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l9 = state.domainStates.liveChatConfig) === null || _state$domainStates$l9 === void 0 ? void 0 : (_state$domainStates$l10 = _state$domainStates$l9.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l10 === void 0 ? void 0 : _state$domainStates$l10.msdyn_postconversationsurveybotsurveymode);
|
|
260
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
261
|
+
Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromBot,
|
|
262
|
+
Description: "PostChat Workflow was started by bot"
|
|
263
|
+
});
|
|
264
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
265
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
266
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
267
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
268
|
+
} else {
|
|
269
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
|
|
270
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
271
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
272
|
+
ExceptionDetails: {
|
|
273
|
+
exception: error
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
throw new Error(error);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
+
const getConversationDetailsCall = async chatSDK => {
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
|
+
let conversationDetails = undefined;
|
|
284
|
+
try {
|
|
285
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
286
|
+
} catch (error) {
|
|
287
|
+
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
288
|
+
Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallFailed,
|
|
289
|
+
ExceptionDetails: {
|
|
290
|
+
exception: `Get Conversation Details Call Failed : ${error}`
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
_NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
|
|
294
|
+
}
|
|
295
|
+
return conversationDetails;
|
|
296
|
+
};
|
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = exports.checkIfConversationStillValid = void 0;
|
|
7
|
-
var _Constants = require("../../../common/Constants");
|
|
8
7
|
var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
|
|
8
|
+
var _Constants = require("../../../common/Constants");
|
|
9
|
+
var _utils = require("../../../common/utils");
|
|
10
|
+
var _authHelper = require("./authHelper");
|
|
11
|
+
var _ActivityStreamHandler = require("./ActivityStreamHandler");
|
|
12
|
+
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
9
13
|
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
10
14
|
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
11
15
|
var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
|
|
@@ -14,13 +18,9 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
|
14
18
|
var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
|
|
15
19
|
var _createAdapter = require("./createAdapter");
|
|
16
20
|
var _newMessageEventHandler = require("../../../plugins/newMessageEventHandler");
|
|
17
|
-
var
|
|
21
|
+
var _reconnectChatHelper = require("./reconnectChatHelper");
|
|
18
22
|
var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
|
|
19
23
|
var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
|
|
20
|
-
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
21
|
-
var _ActivityStreamHandler = require("./ActivityStreamHandler");
|
|
22
|
-
var _authHelper = require("./authHelper");
|
|
23
|
-
var _reconnectChatHelper = require("./reconnectChatHelper");
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
25
|
let optionalParams = {};
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -84,12 +84,20 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
84
84
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
85
85
|
payload: _ConversationState.ConversationState.Loading
|
|
86
86
|
});
|
|
87
|
-
|
|
87
|
+
const optionalParams = {
|
|
88
|
+
isProactiveChat
|
|
89
|
+
};
|
|
90
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
94
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
92
|
-
const initStartChat = async (chatSDK,
|
|
95
|
+
const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
|
|
96
|
+
var _props$controlProps2;
|
|
97
|
+
let isStartChatSuccessful = false;
|
|
98
|
+
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
99
|
+
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
100
|
+
const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
|
|
93
101
|
try {
|
|
94
102
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
95
103
|
//Start widget load timer
|
|
@@ -103,10 +111,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
103
111
|
// set auth token to chat sdk before start chat
|
|
104
112
|
const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
|
|
105
113
|
if (!authSuccess) {
|
|
114
|
+
dispatch({
|
|
115
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
116
|
+
payload: _ConversationState.ConversationState.Closed
|
|
117
|
+
});
|
|
106
118
|
return;
|
|
107
119
|
}
|
|
108
120
|
}
|
|
109
|
-
let isStartChatSuccessful = false;
|
|
110
121
|
|
|
111
122
|
//Check if chat retrieved from cache
|
|
112
123
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -120,10 +131,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
120
131
|
});
|
|
121
132
|
}
|
|
122
133
|
try {
|
|
134
|
+
var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
|
|
123
135
|
// Set custom context params
|
|
124
136
|
setCustomContextParams(chatSDK);
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
const defaultOptionalParams = {
|
|
138
|
+
sendDefaultInitContext: true,
|
|
139
|
+
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
140
|
+
portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
|
|
141
|
+
};
|
|
142
|
+
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
143
|
+
await chatSDK.startChat(startChatOptionalParams);
|
|
127
144
|
isStartChatSuccessful = true;
|
|
128
145
|
} catch (error) {
|
|
129
146
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
@@ -133,12 +150,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
133
150
|
}
|
|
134
151
|
});
|
|
135
152
|
isStartChatSuccessful = false;
|
|
136
|
-
// Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
137
|
-
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
138
|
-
dispatch({
|
|
139
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
140
|
-
payload: _ConversationState.ConversationState.Closed
|
|
141
|
-
});
|
|
142
153
|
return;
|
|
143
154
|
}
|
|
144
155
|
|
|
@@ -167,12 +178,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
167
178
|
payload: liveChatContext
|
|
168
179
|
});
|
|
169
180
|
|
|
170
|
-
// Set post chat context in state, no survey load
|
|
171
|
-
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
172
|
-
|
|
173
|
-
// Updating chat session detail for telemetry
|
|
174
|
-
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
|
|
175
|
-
|
|
176
181
|
// Set app state to Active
|
|
177
182
|
if (isStartChatSuccessful) {
|
|
178
183
|
_ActivityStreamHandler.ActivityStreamHandler.uncork();
|
|
@@ -191,6 +196,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
191
196
|
Description: "Widget load complete",
|
|
192
197
|
ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
|
|
193
198
|
});
|
|
199
|
+
|
|
200
|
+
// Set post chat context in state, no survey load
|
|
201
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
202
|
+
|
|
203
|
+
// Updating chat session detail for telemetry
|
|
204
|
+
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
|
|
194
205
|
} catch (ex) {
|
|
195
206
|
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
196
207
|
Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
|
|
@@ -211,16 +222,28 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
211
222
|
});
|
|
212
223
|
return;
|
|
213
224
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
225
|
+
if (!hideErrorUIPane) {
|
|
226
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
227
|
+
dispatch({
|
|
228
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
229
|
+
payload: true
|
|
230
|
+
});
|
|
231
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
232
|
+
Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
|
|
233
|
+
Description: "Error UI Pane Loaded"
|
|
234
|
+
});
|
|
235
|
+
}
|
|
219
236
|
// Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
|
|
220
237
|
dispatch({
|
|
221
238
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
222
239
|
payload: _ConversationState.ConversationState.Loading
|
|
223
240
|
});
|
|
241
|
+
|
|
242
|
+
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
243
|
+
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
244
|
+
if (isStartChatSuccessful === true) {
|
|
245
|
+
await forceEndChat(chatSDK);
|
|
246
|
+
}
|
|
224
247
|
} finally {
|
|
225
248
|
optionalParams = {};
|
|
226
249
|
widgetInstanceId = "";
|
|
@@ -229,16 +252,27 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
229
252
|
|
|
230
253
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
231
254
|
exports.initStartChat = initStartChat;
|
|
255
|
+
const forceEndChat = async chatSDK => {
|
|
256
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
257
|
+
Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
|
|
258
|
+
ExceptionDetails: {
|
|
259
|
+
Exception: "SessionInit was successful, but widget load failed."
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
266
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
233
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$
|
|
267
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
|
|
234
268
|
// By pass this function in case of popout chat
|
|
235
269
|
if (state.appStates.hideStartChatButton === true) {
|
|
236
270
|
return false;
|
|
237
271
|
}
|
|
238
|
-
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$
|
|
272
|
+
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$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
|
|
239
273
|
|
|
240
274
|
//Connect to only active chat session
|
|
241
|
-
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)
|
|
275
|
+
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)) {
|
|
242
276
|
var _persistedState$domai7;
|
|
243
277
|
dispatch({
|
|
244
278
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
@@ -247,7 +281,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
247
281
|
const optionalParams = {
|
|
248
282
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
249
283
|
};
|
|
250
|
-
await initStartChat(chatSDK,
|
|
284
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
251
285
|
return true;
|
|
252
286
|
} else {
|
|
253
287
|
return false;
|
|
@@ -277,38 +311,11 @@ const setCustomContextParams = chatSDK => {
|
|
|
277
311
|
}
|
|
278
312
|
};
|
|
279
313
|
|
|
280
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
-
const handleAuthenticationIfEnabled = async (chatSDK, props) => {
|
|
282
|
-
//For auth chat
|
|
283
|
-
if (props.getAuthToken) {
|
|
284
|
-
const authClientFunction = (0, _authHelper.getAuthClientFunction)(props.chatConfig);
|
|
285
|
-
if (authClientFunction) {
|
|
286
|
-
// set auth token to chat sdk before start chat
|
|
287
|
-
const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, props.chatConfig, props.getAuthToken);
|
|
288
|
-
if (!authSuccess) {
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return true;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
314
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
315
|
const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
|
|
299
316
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
317
|
let conversationDetails = undefined;
|
|
301
318
|
|
|
302
|
-
// Show Loading screen during auth check and start chat calls
|
|
303
|
-
dispatch({
|
|
304
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
305
|
-
payload: _ConversationState.ConversationState.Loading
|
|
306
|
-
});
|
|
307
|
-
const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
|
|
308
|
-
if (!authSucceed) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
319
|
//Preserve old requestId
|
|
313
320
|
const oldRequestId = chatSDK.requestId;
|
|
314
321
|
try {
|
|
@@ -319,6 +326,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
|
|
|
319
326
|
return false;
|
|
320
327
|
}
|
|
321
328
|
if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
329
|
+
dispatch({
|
|
330
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
331
|
+
payload: undefined
|
|
332
|
+
});
|
|
322
333
|
chatSDK.requestId = oldRequestId;
|
|
323
334
|
return false;
|
|
324
335
|
}
|