@microsoft/omnichannel-chat-widget 0.1.0-main.52da005 → 0.1.0-main.52fa2fc
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 +66 -14
- 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 +11 -7
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +83 -64
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +91 -45
- 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/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- 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 +11 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/cjs/contexts/createReducer.js +36 -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 +66 -14
- 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 +12 -7
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +83 -64
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +92 -46
- 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/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- 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 +11 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/esm/contexts/createReducer.js +36 -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/reconnectChatHelper.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 +6 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -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,250 @@ 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
|
+
// End chat call to end chatsdk but not close chat, only if chat ended by customer
|
|
204
|
+
await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
|
|
205
|
+
// Saving request Id below for chat transcript calls
|
|
206
|
+
if (chatSession) {
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
208
|
+
chatSDK.chatToken = chatSession.chatToken ?? {};
|
|
209
|
+
chatSDK.requestId = chatSession.requestId;
|
|
210
|
+
}
|
|
211
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
212
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
213
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
214
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
215
|
+
} else {
|
|
216
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
217
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
218
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
219
|
+
ExceptionDetails: {
|
|
220
|
+
exception: error
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
throw new Error(error);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
// Agent did not join chat so end chat normally
|
|
227
|
+
await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// Function will handle only postchat cases initiated by agent
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
233
|
+
const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
|
|
234
|
+
var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
|
|
235
|
+
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);
|
|
236
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
237
|
+
Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromAgent,
|
|
238
|
+
Description: "PostChat Workflow was started by agent"
|
|
239
|
+
});
|
|
240
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
241
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
242
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
243
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
244
|
+
} else {
|
|
245
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
246
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
247
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
248
|
+
ExceptionDetails: {
|
|
249
|
+
exception: error
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
throw new Error(error);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Function will handle only postchat cases initiated by bot
|
|
257
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
+
const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
|
|
259
|
+
var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
|
|
260
|
+
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);
|
|
261
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
262
|
+
Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromBot,
|
|
263
|
+
Description: "PostChat Workflow was started by bot"
|
|
264
|
+
});
|
|
265
|
+
if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
|
|
266
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
267
|
+
} else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
|
|
268
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
269
|
+
} else {
|
|
270
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
|
|
271
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
272
|
+
Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
|
|
273
|
+
ExceptionDetails: {
|
|
274
|
+
exception: error
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
throw new Error(error);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
|
+
const getConversationDetailsCall = async chatSDK => {
|
|
283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
284
|
+
let conversationDetails = undefined;
|
|
285
|
+
try {
|
|
286
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
287
|
+
} catch (error) {
|
|
288
|
+
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
289
|
+
Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallFailed,
|
|
290
|
+
ExceptionDetails: {
|
|
291
|
+
exception: `Get Conversation Details Call Failed : ${error}`
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
_NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
|
|
295
|
+
}
|
|
296
|
+
return conversationDetails;
|
|
297
|
+
};
|
|
@@ -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
|
|
@@ -32,10 +32,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
32
32
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
33
33
|
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
35
|
+
// reconnect > chat from cache
|
|
39
36
|
await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
40
37
|
|
|
41
38
|
// If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
|
|
@@ -43,6 +40,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
43
40
|
return;
|
|
44
41
|
}
|
|
45
42
|
|
|
43
|
+
// Can connect to existing chat session
|
|
44
|
+
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
46
48
|
// Setting Proactive chat settings
|
|
47
49
|
const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
|
|
48
50
|
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
|
|
@@ -84,12 +86,20 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
84
86
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
85
87
|
payload: _ConversationState.ConversationState.Loading
|
|
86
88
|
});
|
|
87
|
-
|
|
89
|
+
const optionalParams = {
|
|
90
|
+
isProactiveChat
|
|
91
|
+
};
|
|
92
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
88
93
|
};
|
|
89
94
|
|
|
90
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
96
|
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
92
|
-
const initStartChat = async (chatSDK,
|
|
97
|
+
const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
|
|
98
|
+
var _props$controlProps2;
|
|
99
|
+
let isStartChatSuccessful = false;
|
|
100
|
+
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
101
|
+
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
102
|
+
const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
|
|
93
103
|
try {
|
|
94
104
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
95
105
|
//Start widget load timer
|
|
@@ -103,10 +113,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
103
113
|
// set auth token to chat sdk before start chat
|
|
104
114
|
const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
|
|
105
115
|
if (!authSuccess) {
|
|
116
|
+
dispatch({
|
|
117
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
118
|
+
payload: _ConversationState.ConversationState.Closed
|
|
119
|
+
});
|
|
106
120
|
return;
|
|
107
121
|
}
|
|
108
122
|
}
|
|
109
|
-
let isStartChatSuccessful = false;
|
|
110
123
|
|
|
111
124
|
//Check if chat retrieved from cache
|
|
112
125
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -120,10 +133,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
120
133
|
});
|
|
121
134
|
}
|
|
122
135
|
try {
|
|
136
|
+
var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
|
|
123
137
|
// Set custom context params
|
|
124
138
|
setCustomContextParams(chatSDK);
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
const defaultOptionalParams = {
|
|
140
|
+
sendDefaultInitContext: true,
|
|
141
|
+
isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
|
|
142
|
+
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
|
|
143
|
+
};
|
|
144
|
+
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
145
|
+
await chatSDK.startChat(startChatOptionalParams);
|
|
127
146
|
isStartChatSuccessful = true;
|
|
128
147
|
} catch (error) {
|
|
129
148
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
@@ -133,12 +152,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
133
152
|
}
|
|
134
153
|
});
|
|
135
154
|
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
155
|
return;
|
|
143
156
|
}
|
|
144
157
|
|
|
@@ -167,12 +180,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
167
180
|
payload: liveChatContext
|
|
168
181
|
});
|
|
169
182
|
|
|
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
183
|
// Set app state to Active
|
|
177
184
|
if (isStartChatSuccessful) {
|
|
178
185
|
_ActivityStreamHandler.ActivityStreamHandler.uncork();
|
|
@@ -191,6 +198,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
191
198
|
Description: "Widget load complete",
|
|
192
199
|
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
200
|
});
|
|
201
|
+
|
|
202
|
+
// Set post chat context in state, no survey load
|
|
203
|
+
(0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
204
|
+
|
|
205
|
+
// Updating chat session detail for telemetry
|
|
206
|
+
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
|
|
194
207
|
} catch (ex) {
|
|
195
208
|
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
196
209
|
Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
|
|
@@ -211,16 +224,28 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
211
224
|
});
|
|
212
225
|
return;
|
|
213
226
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
if (!hideErrorUIPane) {
|
|
228
|
+
// Set app state to failing start chat if hideErrorUI is not turned on
|
|
229
|
+
dispatch({
|
|
230
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
231
|
+
payload: true
|
|
232
|
+
});
|
|
233
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
234
|
+
Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
|
|
235
|
+
Description: "Error UI Pane Loaded"
|
|
236
|
+
});
|
|
237
|
+
}
|
|
219
238
|
// Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
|
|
220
239
|
dispatch({
|
|
221
240
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
222
241
|
payload: _ConversationState.ConversationState.Loading
|
|
223
242
|
});
|
|
243
|
+
|
|
244
|
+
// If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
|
|
245
|
+
// we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
|
|
246
|
+
if (isStartChatSuccessful === true) {
|
|
247
|
+
await forceEndChat(chatSDK);
|
|
248
|
+
}
|
|
224
249
|
} finally {
|
|
225
250
|
optionalParams = {};
|
|
226
251
|
widgetInstanceId = "";
|
|
@@ -229,16 +254,27 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
|
|
|
229
254
|
|
|
230
255
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
231
256
|
exports.initStartChat = initStartChat;
|
|
257
|
+
const forceEndChat = async chatSDK => {
|
|
258
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
259
|
+
Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
|
|
260
|
+
ExceptionDetails: {
|
|
261
|
+
Exception: "SessionInit was successful, but widget load failed."
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
232
268
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
233
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$
|
|
269
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
|
|
234
270
|
// By pass this function in case of popout chat
|
|
235
271
|
if (state.appStates.hideStartChatButton === true) {
|
|
236
272
|
return false;
|
|
237
273
|
}
|
|
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$
|
|
274
|
+
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
275
|
|
|
240
276
|
//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)
|
|
277
|
+
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
278
|
var _persistedState$domai7;
|
|
243
279
|
dispatch({
|
|
244
280
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
@@ -247,7 +283,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
247
283
|
const optionalParams = {
|
|
248
284
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
249
285
|
};
|
|
250
|
-
await initStartChat(chatSDK,
|
|
286
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
|
|
251
287
|
return true;
|
|
252
288
|
} else {
|
|
253
289
|
return false;
|
|
@@ -278,39 +314,18 @@ const setCustomContextParams = chatSDK => {
|
|
|
278
314
|
};
|
|
279
315
|
|
|
280
316
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
|
-
const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
|
|
317
|
+
const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
|
|
318
|
+
var _state$domainStates, _state$domainStates$l;
|
|
319
|
+
const requestId = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
|
|
299
320
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
321
|
let conversationDetails = undefined;
|
|
301
322
|
|
|
302
|
-
//
|
|
323
|
+
//Preserve old requestId
|
|
324
|
+
const oldRequestId = chatSDK.requestId ?? "";
|
|
303
325
|
dispatch({
|
|
304
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.
|
|
305
|
-
payload:
|
|
326
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
327
|
+
payload: oldRequestId
|
|
306
328
|
});
|
|
307
|
-
const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
|
|
308
|
-
if (!authSucceed) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
//Preserve old requestId
|
|
313
|
-
const oldRequestId = chatSDK.requestId;
|
|
314
329
|
try {
|
|
315
330
|
chatSDK.requestId = requestId;
|
|
316
331
|
conversationDetails = await chatSDK.getConversationDetails();
|
|
@@ -319,6 +334,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
|
|
|
319
334
|
return false;
|
|
320
335
|
}
|
|
321
336
|
if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
|
|
337
|
+
dispatch({
|
|
338
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
339
|
+
payload: undefined
|
|
340
|
+
});
|
|
322
341
|
chatSDK.requestId = oldRequestId;
|
|
323
342
|
return false;
|
|
324
343
|
}
|