@microsoft/omnichannel-chat-widget 1.7.4-main.120159a → 1.7.4-main.1f61ac6
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/lib/cjs/common/facades/FacadeChatSDK.js +298 -0
- package/lib/cjs/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/cjs/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/cjs/common/utils.js +2 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/cjs/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/cjs/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/cjs/components/livechatwidget/common/endChat.js +21 -22
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +2 -2
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +45 -36
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/cjs/contexts/FacadeChatSDKStore.js +10 -0
- package/lib/cjs/hooks/useFacadeChatSDKStore.js +17 -0
- package/lib/cjs/index.js +9 -2
- package/lib/cjs/plugins/createChatTranscript.js +2 -2
- package/lib/esm/common/facades/FacadeChatSDK.js +291 -0
- package/lib/esm/common/facades/types/IFacadeChatSDKInput.js +1 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/esm/common/telemetry/TelemetryHelper.js +10 -0
- package/lib/esm/common/utils.js +2 -2
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
- package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
- package/lib/esm/components/livechatwidget/LiveChatWidget.js +26 -3
- package/lib/esm/components/livechatwidget/common/authHelper.js +14 -5
- package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -9
- package/lib/esm/components/livechatwidget/common/endChat.js +21 -22
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -2
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -4
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -12
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +45 -36
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -7
- package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
- package/lib/esm/contexts/FacadeChatSDKStore.js +4 -0
- package/lib/esm/hooks/useFacadeChatSDKStore.js +10 -0
- package/lib/esm/index.js +5 -4
- package/lib/esm/plugins/createChatTranscript.js +2 -2
- package/lib/types/common/facades/FacadeChatSDK.d.ts +71 -0
- package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +13 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
- package/lib/types/common/utils.d.ts +2 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +14 -1
- package/lib/types/components/livechatwidget/common/createAdapter.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/initCallingSdk.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +3 -2
- package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/updateSessionDataForTelemetry.d.ts +2 -1
- package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -1
- package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
- package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
- package/lib/types/index.d.ts +4 -3
- package/lib/types/plugins/createChatTranscript.d.ts +2 -1
- package/package.json +2 -2
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import { BotAuthActivitySubscriber } from "./ActivitySubscriber/BotAuthActivitySubscriber";
|
|
2
|
+
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
3
|
+
import { HiddenAdaptiveCardActivitySubscriber } from "./ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber";
|
|
4
|
+
import { MockChatSDK } from "../../webchatcontainerstateful/common/mockchatsdk";
|
|
1
5
|
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
2
6
|
import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
|
|
3
7
|
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
4
|
-
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
5
|
-
import { ChatAdapterShim } from "./ChatAdapterShim";
|
|
6
8
|
import { PauseActivitySubscriber } from "./ActivitySubscriber/PauseActivitySubscriber";
|
|
7
|
-
import {
|
|
8
|
-
import { HiddenAdaptiveCardActivitySubscriber } from "./ActivitySubscriber/HiddenAdaptiveCardActivitySubscriber";
|
|
9
|
+
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
9
10
|
const defaultBotAuthConfig = {
|
|
10
11
|
fetchBotAuthConfigRetries: 3,
|
|
11
12
|
fetchBotAuthConfigRetryInterval: 1000
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
export const createAdapter = async (chatSDK, props) => {
|
|
14
|
+
export const createAdapter = async (facadeChatSDK, props) => {
|
|
16
15
|
const chatAdapterOptionalParams = {
|
|
17
16
|
IC3Adapter: {
|
|
18
17
|
options: {
|
|
@@ -35,9 +34,10 @@ export const createAdapter = async (chatSDK, props) => {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
let adapter = await
|
|
37
|
+
let adapter = await facadeChatSDK.createChatAdapter(chatAdapterOptionalParams);
|
|
39
38
|
//so far, there is no need to convert to the shim adapter when using visual tests
|
|
40
|
-
|
|
39
|
+
const isMocked = facadeChatSDK.getChatSDK() instanceof MockChatSDK;
|
|
40
|
+
if (isMocked !== true) {
|
|
41
41
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4;
|
|
42
42
|
const botAuthActivitySubscriberOptionalParams = {
|
|
43
43
|
fetchBotAuthConfigRetries: (props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.botAuthConfig) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.fetchBotAuthConfigRetries) || defaultBotAuthConfig.fetchBotAuthConfigRetries,
|
|
@@ -10,12 +10,11 @@ import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
|
|
|
10
10
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
11
11
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
12
12
|
import { executeReducer } from "../../../contexts/createReducer";
|
|
13
|
-
import { handleAuthentication } from "./authHelper";
|
|
14
13
|
import { isPersistentEnabled } from "./reconnectChatHelper";
|
|
15
14
|
import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
|
|
16
15
|
|
|
17
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
const prepareEndChat = async (props,
|
|
17
|
+
const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
|
|
19
18
|
try {
|
|
20
19
|
var _conversationDetails$, _state$domainStates, _state$appStates3;
|
|
21
20
|
const {
|
|
@@ -23,8 +22,8 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
23
22
|
} = props;
|
|
24
23
|
|
|
25
24
|
// Use Case: If call is ongoing, end the call by simulating end call button click
|
|
26
|
-
endVoiceVideoCallIfOngoing(
|
|
27
|
-
const conversationDetails = await getConversationDetailsCall(
|
|
25
|
+
endVoiceVideoCallIfOngoing(facadeChatSDK, dispatch);
|
|
26
|
+
const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
|
|
28
27
|
|
|
29
28
|
// Use Case: When post chat is not configured
|
|
30
29
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : (_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === Constants.false) {
|
|
@@ -35,7 +34,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
35
34
|
Event: TelemetryEvent.PrepareEndChat,
|
|
36
35
|
Description: PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithoutPostChat
|
|
37
36
|
});
|
|
38
|
-
await endChat(props,
|
|
37
|
+
await endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
// Use Case: If ended by Agent, stay chat in InActive state
|
|
@@ -52,7 +51,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
52
51
|
|
|
53
52
|
// Use Case: Can render post chat scenarios
|
|
54
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
const postchatContext = (await getPostChatContext(
|
|
54
|
+
const postchatContext = (await getPostChatContext(facadeChatSDK, state, dispatch)) ?? (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.postChatContext);
|
|
56
55
|
if (postchatContext === undefined) {
|
|
57
56
|
var _state$appStates2;
|
|
58
57
|
BroadcastService.postMessage({
|
|
@@ -68,7 +67,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
68
67
|
Event: TelemetryEvent.PrepareEndChat,
|
|
69
68
|
Description: PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat
|
|
70
69
|
});
|
|
71
|
-
await endChat(props,
|
|
70
|
+
await endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
|
|
72
71
|
return;
|
|
73
72
|
}
|
|
74
73
|
|
|
@@ -98,7 +97,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
98
97
|
const endedByCustomer = (appStates === null || appStates === void 0 ? void 0 : appStates.conversationEndedBy) === "Customer";
|
|
99
98
|
|
|
100
99
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
-
const commonParams = [props,
|
|
100
|
+
const commonParams = [props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter];
|
|
102
101
|
if (persistentEnabled && endedByCustomer) {
|
|
103
102
|
await endChat(...commonParams, true, false, true);
|
|
104
103
|
} else {
|
|
@@ -123,7 +122,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
123
122
|
Event: TelemetryEvent.PrepareEndChat,
|
|
124
123
|
Description: PrepareEndChatDescriptionConstants.PrepareEndChatError
|
|
125
124
|
});
|
|
126
|
-
await endChat(props,
|
|
125
|
+
await endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
|
|
127
126
|
}
|
|
128
127
|
} finally {
|
|
129
128
|
//Chat token clean up
|
|
@@ -132,8 +131,9 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
|
|
|
132
131
|
};
|
|
133
132
|
|
|
134
133
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
-
const endChat = async (props,
|
|
136
|
-
|
|
134
|
+
const endChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
|
|
135
|
+
var _facadeChatSDK$getCha;
|
|
136
|
+
if (!skipEndChatSDK && facadeChatSDK !== null && facadeChatSDK !== void 0 && (_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) !== null && _facadeChatSDK$getCha !== void 0 && _facadeChatSDK$getCha.conversation) {
|
|
137
137
|
var _inMemoryState$appSta;
|
|
138
138
|
const inMemoryState = executeReducer(state, {
|
|
139
139
|
type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
@@ -146,9 +146,7 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
|
|
|
146
146
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
147
147
|
Event: TelemetryEvent.EndChatSDKCall
|
|
148
148
|
});
|
|
149
|
-
|
|
150
|
-
await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
|
|
151
|
-
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat(endChatOptionalParameters));
|
|
149
|
+
await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.endChat(endChatOptionalParameters));
|
|
152
150
|
} catch (ex) {
|
|
153
151
|
var _inMemoryState$appSta2;
|
|
154
152
|
// if the chat was disconnected or ended by the agent, we don't want to log the error
|
|
@@ -170,6 +168,7 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
|
|
|
170
168
|
postMessageToOtherTab = false;
|
|
171
169
|
} finally {
|
|
172
170
|
endChatStateCleanUp(dispatch);
|
|
171
|
+
facadeChatSDK.destroy();
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
174
|
if (!skipCloseChat) {
|
|
@@ -205,10 +204,11 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
|
|
|
205
204
|
});
|
|
206
205
|
// Always allow to close the chat for embedded mode irrespective of end chat errors
|
|
207
206
|
closeChatWidget(dispatch, props, state);
|
|
207
|
+
facadeChatSDK.destroy();
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
if (postMessageToOtherTab) {
|
|
211
|
-
const endChatEventName = await getEndChatEventName(
|
|
211
|
+
const endChatEventName = await getEndChatEventName(facadeChatSDK, props);
|
|
212
212
|
BroadcastService.postMessage({
|
|
213
213
|
eventName: endChatEventName,
|
|
214
214
|
payload: {
|
|
@@ -303,11 +303,11 @@ export const chatSDKStateCleanUp = chatSDK => {
|
|
|
303
303
|
};
|
|
304
304
|
|
|
305
305
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
306
|
-
export const endVoiceVideoCallIfOngoing = async (
|
|
306
|
+
export const endVoiceVideoCallIfOngoing = async (facadeChatSDK, dispatch) => {
|
|
307
307
|
let callId = "";
|
|
308
308
|
try {
|
|
309
|
-
if (
|
|
310
|
-
const voiceVideoCallingSdk = await
|
|
309
|
+
if (facadeChatSDK.getChatSDK().isVoiceVideoCallingEnabled()) {
|
|
310
|
+
const voiceVideoCallingSdk = await facadeChatSDK.getVoiceVideoCalling();
|
|
311
311
|
if (voiceVideoCallingSdk && voiceVideoCallingSdk.isInACall()) {
|
|
312
312
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
313
313
|
callId = voiceVideoCallingSdk.callId;
|
|
@@ -360,9 +360,8 @@ const chatTokenCleanUp = async dispatch => {
|
|
|
360
360
|
// Need to keep liveChatContext until chat is fully closed to for transcript download/email
|
|
361
361
|
};
|
|
362
362
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return getWidgetEndChatEventName(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$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.widgetInstanceId) ?? "");
|
|
363
|
+
const getEndChatEventName = async (facadeChatSDK, props) => {
|
|
364
|
+
var _facadeChatSDK$getCha2, _facadeChatSDK$getCha3, _facadeChatSDK$getCha4, _facadeChatSDK$getCha5, _props$controlProps4;
|
|
365
|
+
return getWidgetEndChatEventName((_facadeChatSDK$getCha2 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha2 === void 0 ? void 0 : (_facadeChatSDK$getCha3 = _facadeChatSDK$getCha2.omnichannelConfig) === null || _facadeChatSDK$getCha3 === void 0 ? void 0 : _facadeChatSDK$getCha3.orgId, (_facadeChatSDK$getCha4 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha4 === void 0 ? void 0 : (_facadeChatSDK$getCha5 = _facadeChatSDK$getCha4.omnichannelConfig) === null || _facadeChatSDK$getCha5 === void 0 ? void 0 : _facadeChatSDK$getCha5.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.widgetInstanceId) ?? "");
|
|
367
366
|
};
|
|
368
367
|
export { prepareEndChat, endChat };
|
|
@@ -2,12 +2,12 @@ import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryCon
|
|
|
2
2
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
export const initCallingSdk = async (
|
|
5
|
+
export const initCallingSdk = async (facadeChatSDK, setVoiceVideoCallingSDK) => {
|
|
6
6
|
try {
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
if (
|
|
8
|
+
if (facadeChatSDK.getChatSDK().getVoiceVideoCalling) {
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const callingSDK = await
|
|
10
|
+
const callingSDK = await facadeChatSDK.getChatSDK().getVoiceVideoCalling();
|
|
11
11
|
setVoiceVideoCallingSDK(callingSDK);
|
|
12
12
|
TelemetryHelper.logCallingEvent(LogLevel.INFO, {
|
|
13
13
|
Event: TelemetryEvent.CallingSDKLoadSuccess
|
|
@@ -33,7 +33,7 @@ import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontr
|
|
|
33
33
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
34
34
|
|
|
35
35
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
export const initWebChatComposer = (props, state, dispatch,
|
|
36
|
+
export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) => {
|
|
37
37
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain13, _props$webChatContain14, _defaultWebChatContai, _props$webChatContain15, _props$webChatContain16, _props$webChatContain17, _props$webChatContain18, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai2, _props$webChatContain21, _props$webChatContain22, _defaultWebChatContai3, _props$webChatContain23, _props$webChatContain24;
|
|
38
38
|
// Add a hook to make all links open a new window
|
|
39
39
|
postDomPurifyActivities();
|
|
@@ -52,7 +52,7 @@ export const initWebChatComposer = (props, state, dispatch, chatSDK, endChat) =>
|
|
|
52
52
|
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain5;
|
|
53
53
|
const conversationEndCallback = async () => {
|
|
54
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
const conversationDetails = await getConversationDetailsCall(
|
|
55
|
+
const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
|
|
56
56
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === ParticipantType.Bot) {
|
|
57
57
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
58
58
|
Event: TelemetryEvent.ConversationEndedThreadEventReceived,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ConversationMode } from "../../../common/Constants";
|
|
2
2
|
import { isNullOrUndefined } from "../../../common/utils";
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
export const isPostChatSurveyEnabled = async chatSDK => {
|
|
3
|
+
export const isPostChatSurveyEnabled = async facadeChatSDK => {
|
|
6
4
|
var _chatConfig$LiveWSAnd;
|
|
7
|
-
const chatConfig = await
|
|
5
|
+
const chatConfig = await facadeChatSDK.getLiveChatConfig();
|
|
8
6
|
const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
|
|
9
7
|
return postChatEnabled === "true";
|
|
10
8
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "regenerator-runtime/runtime";
|
|
2
2
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { ConversationMode, WidgetLoadCustomErrorString } from "../../../common/Constants";
|
|
3
4
|
import { checkContactIdError, isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
|
|
4
5
|
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
|
|
5
6
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
6
|
-
import { ConversationMode, WidgetLoadCustomErrorString } from "../../../common/Constants";
|
|
7
7
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
8
8
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
9
9
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
@@ -11,13 +11,12 @@ import { handleStartChatError } from "./startChatErrorHandler";
|
|
|
11
11
|
|
|
12
12
|
// Return value: should start normal chat flow when reconnect is enabled
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const handleChatReconnect = async (
|
|
14
|
+
const handleChatReconnect = async (facadeChatSDK, props, dispatch, setAdapter, initStartChat, state) => {
|
|
15
15
|
var _props$chatConfig, _props$chatConfig$Liv;
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
17
|
const isAuthenticatedChat = (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
|
|
18
|
-
|
|
19
18
|
// Get chat reconnect context
|
|
20
|
-
const reconnectChatContext = await getChatReconnectContext(
|
|
19
|
+
const reconnectChatContext = (await getChatReconnectContext(facadeChatSDK, props.chatConfig, props, isAuthenticatedChat, dispatch)) ?? {};
|
|
21
20
|
|
|
22
21
|
// Redirect if enabled
|
|
23
22
|
if (reconnectChatContext !== null && reconnectChatContext !== void 0 && reconnectChatContext.redirectURL) {
|
|
@@ -29,7 +28,7 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
|
|
|
29
28
|
var _props$reconnectChatP2, _props$reconnectChatP3, _props$controlProps;
|
|
30
29
|
//if reconnect id is provided in props, or hideReconnectChatPane is true, don't show reconnect pane
|
|
31
30
|
if ((_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.reconnectId && !isNullOrEmptyString((_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId) || (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hideReconnectChatPane) {
|
|
32
|
-
await setReconnectIdAndStartChat(isAuthenticatedChat,
|
|
31
|
+
await setReconnectIdAndStartChat(isAuthenticatedChat, facadeChatSDK, state, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
|
|
33
32
|
return false;
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -52,7 +51,7 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
|
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
const getChatReconnectContext = async (
|
|
54
|
+
const getChatReconnectContext = async (facadeChatSDK, chatConfig, props, isAuthenticatedChat, dispatch) => {
|
|
56
55
|
try {
|
|
57
56
|
var _props$reconnectChatP4;
|
|
58
57
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
@@ -65,13 +64,13 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
|
|
|
65
64
|
// Get auth token for getting chat reconnect context
|
|
66
65
|
if (isAuthenticatedChat) {
|
|
67
66
|
// handle authentication will throw error if auth token is not available, so no need to check for response
|
|
68
|
-
await handleAuthentication(
|
|
67
|
+
await handleAuthentication(facadeChatSDK.getChatSDK(), chatConfig, props.getAuthToken);
|
|
69
68
|
}
|
|
70
|
-
const reconnectChatContext = await (
|
|
69
|
+
const reconnectChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatReconnectContext(chatReconnectOptionalParams));
|
|
71
70
|
if (isAuthenticatedChat) {
|
|
72
71
|
// remove auth token after reconnectId is fetched
|
|
73
72
|
// AuthToken will be reset later at start chat
|
|
74
|
-
removeAuthTokenProvider(
|
|
73
|
+
removeAuthTokenProvider(facadeChatSDK.getChatSDK());
|
|
75
74
|
}
|
|
76
75
|
return reconnectChatContext;
|
|
77
76
|
}
|
|
@@ -87,14 +86,14 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
|
|
|
87
86
|
|
|
88
87
|
// when auth token is not available, propagate the error to stop the execution and ensure error pane is loaded
|
|
89
88
|
if ((error === null || error === void 0 ? void 0 : error.message) == WidgetLoadCustomErrorString.AuthenticationFailedErrorString) {
|
|
90
|
-
handleStartChatError(dispatch,
|
|
89
|
+
handleStartChatError(dispatch, facadeChatSDK, props, new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString), false);
|
|
91
90
|
throw error;
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
};
|
|
95
94
|
|
|
96
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
-
const setReconnectIdAndStartChat = async (isAuthenticatedChat,
|
|
96
|
+
const setReconnectIdAndStartChat = async (isAuthenticatedChat, facadeChatSDK, state, props, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
98
97
|
if (!isAuthenticatedChat) {
|
|
99
98
|
const startUnauthenticatedReconnectChat = {
|
|
100
99
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
@@ -112,7 +111,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, state, p
|
|
|
112
111
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
113
112
|
payload: ConversationState.Loading
|
|
114
113
|
});
|
|
115
|
-
await initStartChat(
|
|
114
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
116
115
|
};
|
|
117
116
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
118
117
|
const redirectPageRequest = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Constants, ParticipantType, PostChatSurveyTelemetryMessage } from "../../../common/Constants";
|
|
2
2
|
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
-
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
4
|
-
import { addDelayInMs } from "../../../common/utils";
|
|
5
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
6
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
7
5
|
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
6
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
+
import { addDelayInMs } from "../../../common/utils";
|
|
8
8
|
import { isPostChatSurveyEnabled } from "./liveChatConfigUtils";
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -100,14 +100,14 @@ const isPostChatEnabled = (props, state) => {
|
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
-
const getPostChatContext = async (
|
|
103
|
+
const getPostChatContext = async (facadeChatSDK, state, dispatch) => {
|
|
104
104
|
try {
|
|
105
|
-
const postChatEnabled = await isPostChatSurveyEnabled(
|
|
105
|
+
const postChatEnabled = await isPostChatSurveyEnabled(facadeChatSDK);
|
|
106
106
|
if (postChatEnabled) {
|
|
107
107
|
var _state$domainStates2;
|
|
108
108
|
if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
|
|
109
109
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
-
const context = await
|
|
110
|
+
const context = await facadeChatSDK.getPostChatSurveyContext();
|
|
111
111
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
112
112
|
Event: TelemetryEvent.PostChatContextCallSucceed,
|
|
113
113
|
Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
|
|
@@ -2,18 +2,18 @@ import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryCon
|
|
|
2
2
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
3
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
|
-
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
5
|
import { PostChatSurveyTelemetryMessage } from "../../../common/Constants";
|
|
6
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
7
|
import { isPostChatSurveyEnabled } from "./liveChatConfigUtils";
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
export const setPostChatContextAndLoadSurvey = async (
|
|
10
|
+
export const setPostChatContextAndLoadSurvey = async (facadeChatSDK, dispatch, persistedChat) => {
|
|
11
11
|
try {
|
|
12
|
-
const postChatEnabled = await isPostChatSurveyEnabled(
|
|
12
|
+
const postChatEnabled = await isPostChatSurveyEnabled(facadeChatSDK);
|
|
13
13
|
if (postChatEnabled) {
|
|
14
14
|
if (!persistedChat) {
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
const context = await
|
|
16
|
+
const context = await facadeChatSDK.getPostChatSurveyContext();
|
|
17
17
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
18
18
|
Event: TelemetryEvent.PostChatContextCallSucceed,
|
|
19
19
|
Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
|
|
@@ -26,27 +26,27 @@ let widgetInstanceId;
|
|
|
26
26
|
let popoutWidgetInstanceId;
|
|
27
27
|
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
const setAuthenticationIfApplicable = async (props,
|
|
29
|
+
const setAuthenticationIfApplicable = async (props, facadeChatSDK) => {
|
|
30
30
|
const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
|
|
31
31
|
const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
|
|
32
32
|
const authClientFunction = getAuthClientFunction(chatConfig);
|
|
33
33
|
if (getAuthToken && authClientFunction) {
|
|
34
34
|
// set auth token to chat sdk before start chat
|
|
35
|
-
const authSuccess = await handleAuthentication(
|
|
36
|
-
if (!authSuccess) {
|
|
35
|
+
const authSuccess = await handleAuthentication(facadeChatSDK.getChatSDK(), chatConfig, getAuthToken);
|
|
36
|
+
if (!authSuccess.result) {
|
|
37
37
|
throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
const prepareStartChat = async (props,
|
|
43
|
+
const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
44
44
|
optionalParams = {}; //Resetting to ensure no stale values
|
|
45
45
|
widgetInstanceId = getWidgetCacheIdfromProps(props);
|
|
46
46
|
|
|
47
47
|
// reconnect > chat from cache
|
|
48
48
|
if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
|
|
49
|
-
const shouldStartChatNormally = await handleChatReconnect(
|
|
49
|
+
const shouldStartChatNormally = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
|
|
50
50
|
if (!shouldStartChatNormally) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
@@ -58,7 +58,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Can connect to existing chat session
|
|
61
|
-
if (await canConnectToExistingChat(props,
|
|
61
|
+
if (await canConnectToExistingChat(props, facadeChatSDK, state, dispatch, setAdapter)) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -68,26 +68,30 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
68
68
|
|
|
69
69
|
// Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
|
|
70
70
|
if (isPersistentEnabled(props.chatConfig)) {
|
|
71
|
-
await setAuthenticationIfApplicable(props,
|
|
71
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
//Setting PreChat and intiate chat
|
|
75
|
-
await setPreChatAndInitiateChat(
|
|
75
|
+
await setPreChatAndInitiateChat(facadeChatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
const setPreChatAndInitiateChat = async (
|
|
79
|
+
const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
|
|
80
80
|
var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
|
|
81
|
-
//
|
|
81
|
+
// This reset needs to be done before to load prechat, because the conversation state changes from close to prechat
|
|
82
|
+
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
|
|
83
|
+
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
84
|
+
chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
|
|
85
|
+
}
|
|
82
86
|
|
|
83
87
|
// Getting prechat Survey Context
|
|
84
88
|
const parseToJson = false;
|
|
85
|
-
const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await
|
|
89
|
+
const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await facadeChatSDK.getPreChatSurvey(parseToJson));
|
|
86
90
|
let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
|
|
87
|
-
showPrechat = await shouldSetPreChatIfPersistentChat(
|
|
91
|
+
showPrechat = await shouldSetPreChatIfPersistentChat(facadeChatSDK.getChatSDK(), state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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_conversationmode, showPrechat);
|
|
88
92
|
if (showPrechat) {
|
|
89
93
|
var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
|
|
90
|
-
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toLowerCase()) === "true";
|
|
94
|
+
const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toString().toLowerCase()) === "true";
|
|
91
95
|
if (isOutOfOperatingHours) {
|
|
92
96
|
(state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
|
|
93
97
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
@@ -100,6 +104,9 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
100
104
|
return;
|
|
101
105
|
} else {
|
|
102
106
|
var _state$appStates;
|
|
107
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
108
|
+
Event: TelemetryEvent.PrechatSurveyExpected
|
|
109
|
+
});
|
|
103
110
|
dispatch({
|
|
104
111
|
type: LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
105
112
|
payload: preChatSurveyResponse
|
|
@@ -138,17 +145,17 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
|
|
|
138
145
|
const optionalParams = {
|
|
139
146
|
isProactiveChat
|
|
140
147
|
};
|
|
141
|
-
await initStartChat(
|
|
148
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
142
149
|
};
|
|
143
150
|
|
|
144
151
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
-
const initStartChat = async (
|
|
152
|
+
const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
|
|
146
153
|
var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
|
|
147
154
|
let isStartChatSuccessful = false;
|
|
148
155
|
const persistentChatEnabled = await isPersistentChatEnabled(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
|
|
149
156
|
if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
|
|
150
157
|
// Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
|
|
151
|
-
chatSDKStateCleanUp(
|
|
158
|
+
chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
|
|
152
159
|
}
|
|
153
160
|
try {
|
|
154
161
|
var _state$appStates2;
|
|
@@ -166,7 +173,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
166
173
|
});
|
|
167
174
|
|
|
168
175
|
// Auth token retrieval needs to happen during start chat to support pop-out chat
|
|
169
|
-
await setAuthenticationIfApplicable(props,
|
|
176
|
+
await setAuthenticationIfApplicable(props, facadeChatSDK);
|
|
170
177
|
|
|
171
178
|
//Check if chat retrieved from cache
|
|
172
179
|
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
@@ -189,7 +196,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
189
196
|
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
|
|
190
197
|
};
|
|
191
198
|
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
192
|
-
await
|
|
199
|
+
await facadeChatSDK.startChat(startChatOptionalParams);
|
|
193
200
|
isStartChatSuccessful = true;
|
|
194
201
|
} catch (error) {
|
|
195
202
|
checkContactIdError(error);
|
|
@@ -208,7 +215,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
208
215
|
isStartChatSuccessful = false;
|
|
209
216
|
throw error;
|
|
210
217
|
}
|
|
211
|
-
await createAdapterAndSubscribe(
|
|
218
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
212
219
|
|
|
213
220
|
// Set app state to Active
|
|
214
221
|
if (isStartChatSuccessful) {
|
|
@@ -230,14 +237,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
230
237
|
});
|
|
231
238
|
logWidgetLoadComplete(WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
|
|
232
239
|
// Set post chat context in state, load in background to do not block the load
|
|
233
|
-
setPostChatContextAndLoadSurvey(
|
|
240
|
+
setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch, true);
|
|
234
241
|
return;
|
|
235
242
|
}
|
|
236
243
|
|
|
237
244
|
// Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
|
|
238
245
|
if (!persistentChatEnabled) {
|
|
239
246
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
-
const liveChatContext = await (
|
|
247
|
+
const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
|
|
241
248
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
249
|
dispatch({
|
|
243
250
|
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
@@ -246,11 +253,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
246
253
|
}
|
|
247
254
|
logWidgetLoadComplete();
|
|
248
255
|
// Set post chat context in state, load in background to do not block the load
|
|
249
|
-
setPostChatContextAndLoadSurvey(
|
|
256
|
+
setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch);
|
|
250
257
|
// Updating chat session detail for telemetry
|
|
251
|
-
await updateTelemetryData(
|
|
258
|
+
await updateTelemetryData(facadeChatSDK, dispatch);
|
|
252
259
|
} catch (ex) {
|
|
253
|
-
handleStartChatError(dispatch,
|
|
260
|
+
handleStartChatError(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
|
|
254
261
|
} finally {
|
|
255
262
|
optionalParams = {};
|
|
256
263
|
widgetInstanceId = "";
|
|
@@ -258,20 +265,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
|
|
|
258
265
|
};
|
|
259
266
|
|
|
260
267
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
261
|
-
const createAdapterAndSubscribe = async (
|
|
262
|
-
var _newAdapter$activity$;
|
|
268
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
263
269
|
// New adapter creation
|
|
264
|
-
const newAdapter = await createAdapter(
|
|
270
|
+
const newAdapter = await createAdapter(facadeChatSDK, props);
|
|
265
271
|
setAdapter(newAdapter);
|
|
266
|
-
const chatToken = await
|
|
272
|
+
const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
|
|
267
273
|
dispatch({
|
|
268
274
|
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
269
275
|
payload: chatToken
|
|
270
276
|
});
|
|
271
|
-
|
|
277
|
+
if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
|
|
278
|
+
var _newAdapter$activity$;
|
|
279
|
+
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken.chatId, chatToken.visitorId));
|
|
280
|
+
}
|
|
272
281
|
};
|
|
273
282
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
-
const canConnectToExistingChat = async (props,
|
|
283
|
+
const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
|
|
275
284
|
var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
|
|
276
285
|
// By pass this function in case of popout chat
|
|
277
286
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.hideStartChatButton) === true) {
|
|
@@ -289,7 +298,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
|
|
|
289
298
|
const optionalParams = {
|
|
290
299
|
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
291
300
|
};
|
|
292
|
-
await initStartChat(
|
|
301
|
+
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
|
|
293
302
|
return true;
|
|
294
303
|
}
|
|
295
304
|
return false;
|
|
@@ -354,28 +363,28 @@ const canStartPopoutChat = async props => {
|
|
|
354
363
|
};
|
|
355
364
|
|
|
356
365
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
|
-
const checkIfConversationStillValid = async (
|
|
366
|
+
const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
|
|
358
367
|
var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
|
|
359
368
|
const requestIdFromCache = (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : (_state$domainStates8$ = _state$domainStates8.liveChatContext) === null || _state$domainStates8$ === void 0 ? void 0 : _state$domainStates8$.requestId;
|
|
360
369
|
const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
|
|
361
370
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
362
371
|
let conversationDetails = undefined;
|
|
363
372
|
// Preserve current requestId
|
|
364
|
-
const currentRequestId =
|
|
373
|
+
const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
|
|
365
374
|
dispatch({
|
|
366
375
|
type: LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
|
|
367
376
|
payload: currentRequestId
|
|
368
377
|
});
|
|
369
378
|
try {
|
|
370
|
-
|
|
371
|
-
conversationDetails = await getConversationDetailsCall(
|
|
379
|
+
facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
|
|
380
|
+
conversationDetails = await getConversationDetailsCall(facadeChatSDK, liveChatContext);
|
|
372
381
|
if (Object.keys(conversationDetails).length === 0 || isNullOrUndefined(conversationDetails.state) || conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
|
|
373
382
|
dispatch({
|
|
374
383
|
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
375
384
|
payload: undefined
|
|
376
385
|
});
|
|
377
386
|
if (currentRequestId) {
|
|
378
|
-
|
|
387
|
+
facadeChatSDK.getChatSDK().requestId = currentRequestId;
|
|
379
388
|
}
|
|
380
389
|
return false;
|
|
381
390
|
}
|