@microsoft/omnichannel-chat-widget 1.0.2 → 1.0.3-main.1acfc60
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/Constants.js +54 -1
- package/lib/cjs/common/storage/default/defaultCacheManager.js +7 -6
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +9 -7
- package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -1
- package/lib/cjs/common/utils.js +27 -5
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +1 -10
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
- package/lib/cjs/components/footerstateful/FooterStateful.js +1 -1
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +14 -13
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +2 -3
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -3
- package/lib/cjs/components/livechatwidget/common/endChat.js +197 -99
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +41 -21
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -8
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +139 -0
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +2 -255
- package/lib/cjs/components/livechatwidget/common/startChat.js +85 -69
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +162 -100
- package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
- package/lib/cjs/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +62 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware.js +25 -12
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +16 -13
- package/lib/cjs/contexts/createReducer.js +13 -23
- package/lib/cjs/controller/componentController.js +2 -1
- package/lib/cjs/index.js +20 -0
- package/lib/esm/common/Constants.js +49 -0
- package/lib/esm/common/storage/default/defaultCacheManager.js +5 -4
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +9 -7
- package/lib/esm/common/telemetry/TelemetryConstants.js +7 -1
- package/lib/esm/common/utils.js +25 -4
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -13
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
- package/lib/esm/components/footerstateful/FooterStateful.js +1 -1
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +14 -13
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +2 -3
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -3
- package/lib/esm/components/livechatwidget/common/endChat.js +196 -99
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +41 -21
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -8
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +130 -0
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -255
- package/lib/esm/components/livechatwidget/common/startChat.js +86 -70
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -102
- package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
- package/lib/esm/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +54 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/dataMaskingMiddleware.js +25 -12
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +18 -15
- package/lib/esm/contexts/createReducer.js +13 -23
- package/lib/esm/controller/componentController.js +2 -1
- package/lib/esm/index.js +4 -1
- package/lib/types/common/Constants.d.ts +21 -0
- package/lib/types/common/interfaces/IContextDataStore.d.ts +3 -3
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +2 -1
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
- package/lib/types/common/utils.d.ts +3 -2
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +6 -0
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -6
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.d.ts +9 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +8 -7
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
- package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +2 -1
- package/lib/types/index.d.ts +3 -0
- package/package.json +2 -1
- package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +0 -36
- package/lib/cjs/contexts/common/ConversationEndEntity.js +0 -12
- package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +0 -30
- package/lib/esm/contexts/common/ConversationEndEntity.js +0 -5
- package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +0 -6
- package/lib/types/contexts/common/ConversationEndEntity.d.ts +0 -4
|
@@ -5,60 +5,84 @@ import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidge
|
|
|
5
5
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
6
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
7
7
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
8
|
-
import { getWidgetEndChatEventName } from "../../../common/utils";
|
|
8
|
+
import { getWidgetEndChatEventName, isNullOrEmptyString } from "../../../common/utils";
|
|
9
9
|
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
10
|
-
import {
|
|
11
|
-
import { ConversationEndEntity } from "../../../
|
|
10
|
+
import { initiatePostChat, getPostChatContext } from "./renderSurveyHelpers";
|
|
11
|
+
import { Constants, ConversationEndEntity, ConfirmationState } from "../../../common/Constants";
|
|
12
12
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
exception: "Unable to get auth token during end chat"
|
|
26
|
-
}
|
|
27
|
-
});
|
|
14
|
+
const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
|
|
15
|
+
try {
|
|
16
|
+
var _conversationDetails$, _state$domainStates, _state$domainStates2;
|
|
17
|
+
const conversationDetails = await getConversationDetails(chatSDK);
|
|
18
|
+
|
|
19
|
+
// Use Case : When post chat is not configured
|
|
20
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : (_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === Constants.false) {
|
|
21
|
+
var _state$appStates;
|
|
22
|
+
// If ended by customer, just close chat
|
|
23
|
+
if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === ConversationEndEntity.Customer) {
|
|
24
|
+
await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
|
|
28
25
|
}
|
|
26
|
+
//Use Case: If ended by Agent, stay chat in InActive state
|
|
27
|
+
return;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
|
|
30
|
+
// Use Case : Can render post chat scenarios
|
|
31
|
+
await getPostChatContext(chatSDK, state, dispatch);
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
const postchatContext = state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.postChatContext;
|
|
35
|
+
if (postchatContext === undefined) {
|
|
36
|
+
var _state$appStates2;
|
|
37
|
+
// For Customer intiated conversations, just close chat widget
|
|
38
|
+
if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === ConversationEndEntity.Customer) {
|
|
39
|
+
await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//For agent initiated end chat, allow to download transcript
|
|
45
44
|
dispatch({
|
|
46
|
-
type: LiveChatWidgetActionType.
|
|
47
|
-
payload:
|
|
45
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
46
|
+
payload: ConversationState.InActive
|
|
48
47
|
});
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true, uwid);
|
|
51
|
+
|
|
52
|
+
// Initiate post chat render
|
|
53
|
+
if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
|
|
54
|
+
await initiatePostChat(props, conversationDetails, state, dispatch);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
var _props$controlProps;
|
|
59
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
60
|
+
Event: TelemetryEvent.EndChatFailed,
|
|
61
|
+
ExceptionDetails: {
|
|
62
|
+
exception: JSON.stringify(error)
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
//Close chat widget for any failure in embedded to allow to show start chat button
|
|
67
|
+
if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
|
|
68
|
+
await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
|
|
51
69
|
}
|
|
70
|
+
} finally {
|
|
71
|
+
//Chat token clean up
|
|
72
|
+
await chatTokenCleanUp(dispatch);
|
|
52
73
|
}
|
|
53
74
|
};
|
|
54
75
|
|
|
55
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
-
const endChat = async (props, chatSDK, setAdapter, setWebChatStyles,
|
|
57
|
-
|
|
77
|
+
const endChat = async function (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) {
|
|
78
|
+
let uwid = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : "";
|
|
79
|
+
if (!skipEndChatSDK && chatSDK.conversation) {
|
|
58
80
|
try {
|
|
59
81
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
60
82
|
Event: TelemetryEvent.EndChatSDKCall
|
|
61
83
|
});
|
|
84
|
+
//Get auth token again if chat continued for longer time, otherwise gets 401 error
|
|
85
|
+
await handleAuthenticationIfEnabled(props, chatSDK);
|
|
62
86
|
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
|
|
63
87
|
} catch (ex) {
|
|
64
88
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -68,25 +92,10 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
68
92
|
}
|
|
69
93
|
});
|
|
70
94
|
postMessageToOtherTab = false;
|
|
95
|
+
} finally {
|
|
96
|
+
await endChatStateCleanUp(dispatch);
|
|
71
97
|
}
|
|
72
98
|
}
|
|
73
|
-
// Need to clear these states immediately when chat ended from OC.
|
|
74
|
-
dispatch({
|
|
75
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
76
|
-
payload: undefined
|
|
77
|
-
});
|
|
78
|
-
dispatch({
|
|
79
|
-
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
80
|
-
payload: undefined
|
|
81
|
-
});
|
|
82
|
-
dispatch({
|
|
83
|
-
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
84
|
-
payload: undefined
|
|
85
|
-
});
|
|
86
|
-
dispatch({
|
|
87
|
-
type: LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
|
|
88
|
-
payload: false
|
|
89
|
-
});
|
|
90
99
|
if (!skipCloseChat) {
|
|
91
100
|
try {
|
|
92
101
|
var _props$webChatContain;
|
|
@@ -97,49 +106,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
97
106
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
98
107
|
});
|
|
99
108
|
WebChatStoreLoader.store = null;
|
|
100
|
-
dispatch
|
|
101
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
102
|
-
payload: ConversationState.Closed
|
|
103
|
-
});
|
|
104
|
-
dispatch({
|
|
105
|
-
type: LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
|
|
106
|
-
payload: false
|
|
107
|
-
});
|
|
108
|
-
dispatch({
|
|
109
|
-
type: LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
|
|
110
|
-
payload: false
|
|
111
|
-
});
|
|
112
|
-
dispatch({
|
|
113
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
|
|
114
|
-
payload: false
|
|
115
|
-
});
|
|
116
|
-
dispatch({
|
|
117
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
|
|
118
|
-
payload: undefined
|
|
119
|
-
});
|
|
120
|
-
dispatch({
|
|
121
|
-
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
122
|
-
payload: undefined
|
|
123
|
-
});
|
|
124
|
-
dispatch({
|
|
125
|
-
type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
|
|
126
|
-
payload: null
|
|
127
|
-
});
|
|
128
|
-
dispatch({
|
|
129
|
-
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
130
|
-
payload: {
|
|
131
|
-
proactiveChatBodyTitle: "",
|
|
132
|
-
proactiveChatEnablePrechat: false,
|
|
133
|
-
proactiveChatInNewWindow: false
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
if (postMessageToOtherTab) {
|
|
137
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
|
|
138
|
-
const endChatEventName = 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$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
|
|
139
|
-
BroadcastService.postMessage({
|
|
140
|
-
eventName: endChatEventName
|
|
141
|
-
});
|
|
142
|
-
}
|
|
109
|
+
closeChatStateCleanUp(dispatch);
|
|
143
110
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
144
111
|
Event: TelemetryEvent.CloseChatCall,
|
|
145
112
|
Description: "Chat was closed succesfully"
|
|
@@ -152,11 +119,141 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
152
119
|
}
|
|
153
120
|
});
|
|
154
121
|
} finally {
|
|
122
|
+
var _state$appStates3;
|
|
155
123
|
dispatch({
|
|
156
124
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
157
125
|
payload: 0
|
|
158
126
|
});
|
|
127
|
+
//Always allow to close the chat for embedded mode irrespective of end chat errors
|
|
128
|
+
if (!(state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.hideStartChatButton)) {
|
|
129
|
+
dispatch({
|
|
130
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
131
|
+
payload: ConversationState.Closed
|
|
132
|
+
});
|
|
133
|
+
}
|
|
159
134
|
}
|
|
160
135
|
}
|
|
136
|
+
if (postMessageToOtherTab && !isNullOrEmptyString(uwid)) {
|
|
137
|
+
const endChatEventName = await getEndChatEventName(chatSDK, props);
|
|
138
|
+
BroadcastService.postMessage({
|
|
139
|
+
eventName: endChatEventName,
|
|
140
|
+
payload: uwid
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const endChatStateCleanUp = async dispatch => {
|
|
145
|
+
// Need to clear these states immediately when chat ended from OC.
|
|
146
|
+
dispatch({
|
|
147
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
148
|
+
payload: undefined
|
|
149
|
+
});
|
|
150
|
+
dispatch({
|
|
151
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
152
|
+
payload: undefined
|
|
153
|
+
});
|
|
154
|
+
dispatch({
|
|
155
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
156
|
+
payload: undefined
|
|
157
|
+
});
|
|
158
|
+
dispatch({
|
|
159
|
+
type: LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
|
|
160
|
+
payload: false
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const closeChatStateCleanUp = async dispatch => {
|
|
164
|
+
dispatch({
|
|
165
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
166
|
+
payload: undefined
|
|
167
|
+
});
|
|
168
|
+
// dispatch({ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE, payload: ConversationState.Closed });
|
|
169
|
+
dispatch({
|
|
170
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
171
|
+
payload: undefined
|
|
172
|
+
});
|
|
173
|
+
dispatch({
|
|
174
|
+
type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
|
|
175
|
+
payload: null
|
|
176
|
+
});
|
|
177
|
+
dispatch({
|
|
178
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
|
|
179
|
+
payload: ConversationEndEntity.NotSet
|
|
180
|
+
});
|
|
181
|
+
dispatch({
|
|
182
|
+
type: LiveChatWidgetActionType.SET_CONFIRMATION_STATE,
|
|
183
|
+
payload: ConfirmationState.NotSet
|
|
184
|
+
});
|
|
185
|
+
dispatch({
|
|
186
|
+
type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
|
|
187
|
+
payload: false
|
|
188
|
+
});
|
|
189
|
+
dispatch({
|
|
190
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
191
|
+
payload: {
|
|
192
|
+
proactiveChatBodyTitle: "",
|
|
193
|
+
proactiveChatEnablePrechat: false,
|
|
194
|
+
proactiveChatInNewWindow: false
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
const handleAuthenticationIfEnabled = async (props, chatSDK) => {
|
|
201
|
+
//Unable to end chat if token has expired
|
|
202
|
+
if (props.getAuthToken) {
|
|
203
|
+
const authClientFunction = getAuthClientFunction(props.chatConfig);
|
|
204
|
+
if (props.getAuthToken && authClientFunction) {
|
|
205
|
+
// set auth token to chat sdk before end chat
|
|
206
|
+
const authSuccess = await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
|
|
207
|
+
if (!authSuccess) {
|
|
208
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
209
|
+
Event: TelemetryEvent.GetAuthTokenFailed,
|
|
210
|
+
ExceptionDetails: {
|
|
211
|
+
exception: "Unable to get auth token during end chat"
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
throw new Error("handleAuthenticationIfEnabled:Failed to get authentication token");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
|
+
const chatTokenCleanUp = async dispatch => {
|
|
222
|
+
//Just do cleanup here
|
|
223
|
+
dispatch({
|
|
224
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
225
|
+
payload: undefined
|
|
226
|
+
});
|
|
227
|
+
dispatch({
|
|
228
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
229
|
+
payload: undefined
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
234
|
+
const getEndChatEventName = async (chatSDK, props) => {
|
|
235
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2;
|
|
236
|
+
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$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
+
const getConversationDetails = async chatSDK => {
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
|
+
let conversationDetails = undefined;
|
|
243
|
+
try {
|
|
244
|
+
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
245
|
+
Event: TelemetryEvent.GetConversationDetailsCallStarted,
|
|
246
|
+
Description: "Conversation details call started"
|
|
247
|
+
});
|
|
248
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
249
|
+
} catch (error) {
|
|
250
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
251
|
+
Event: TelemetryEvent.GetConversationDetailsCallFailed,
|
|
252
|
+
ExceptionDetails: {
|
|
253
|
+
exception: `Get Conversation Details Call Failed : ${error}`
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return conversationDetails;
|
|
161
258
|
};
|
|
162
|
-
export { prepareEndChat, endChat };
|
|
259
|
+
export { prepareEndChat, endChat, getConversationDetails };
|
|
@@ -26,35 +26,39 @@ import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontr
|
|
|
26
26
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
27
27
|
import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
|
|
28
28
|
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
29
|
+
import { ConversationEndEntity, ParticipantType } from "../../../common/Constants";
|
|
30
|
+
import { getConversationDetails } from "./endChat";
|
|
31
|
+
import HyperlinkTextOverrideRenderer from "../../webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer";
|
|
29
32
|
|
|
30
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
export const initWebChatComposer = (props,
|
|
32
|
-
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l4, _state$domainStates$l5, _props$
|
|
34
|
+
export const initWebChatComposer = (props, state, dispatch, chatSDK) => {
|
|
35
|
+
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, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
|
|
33
36
|
const localizedTexts = {
|
|
34
37
|
...defaultMiddlewareLocalizedTexts,
|
|
35
38
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
|
|
36
39
|
};
|
|
37
|
-
const
|
|
40
|
+
const hyperlinkTextOverride = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hyperlinkTextOverride) ?? defaultWebChatContainerStatefulProps.hyperlinkTextOverride;
|
|
41
|
+
const disableNewLineMarkdownSupport = ((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.disableNewLineMarkdownSupport) ?? defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
|
|
38
42
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
-
const markdown = createMarkdown(((_props$
|
|
43
|
+
const markdown = createMarkdown(((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.disableMarkdownMessageFormatting) ?? defaultWebChatContainerStatefulProps.disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
|
|
40
44
|
// Initialize Web Chat's redux store
|
|
41
45
|
let webChatStore = WebChatStoreLoader.store;
|
|
42
46
|
if (!webChatStore) {
|
|
43
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$
|
|
47
|
+
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain5;
|
|
44
48
|
const conversationEndCallback = async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
const conversationDetails = await getConversationDetails(chatSDK);
|
|
51
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === ParticipantType.Bot) {
|
|
52
|
+
dispatch({
|
|
53
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
|
|
54
|
+
payload: ConversationEndEntity.Bot
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
dispatch({
|
|
58
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
|
|
59
|
+
payload: ConversationEndEntity.Agent
|
|
52
60
|
});
|
|
53
61
|
}
|
|
54
|
-
dispatch({
|
|
55
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
|
|
56
|
-
payload: true
|
|
57
|
-
});
|
|
58
62
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
59
63
|
Event: TelemetryEvent.ConversationEndedThreadEventReceived,
|
|
60
64
|
Description: "Conversation end by agent side or by timeout event received."
|
|
@@ -64,9 +68,25 @@ export const initWebChatComposer = (props, chatSDK, setAdapter, state, dispatch,
|
|
|
64
68
|
//initial state
|
|
65
69
|
preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware,
|
|
66
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
-
...(((_props$
|
|
71
|
+
...(((_props$webChatContain5 = props.webChatContainerProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.storeMiddlewares) ?? []));
|
|
68
72
|
WebChatStoreLoader.store = webChatStore;
|
|
69
73
|
}
|
|
74
|
+
const hyperlinkTextOverrideRenderer = new HyperlinkTextOverrideRenderer(hyperlinkTextOverride);
|
|
75
|
+
const markdownRenderers = [hyperlinkTextOverrideRenderer];
|
|
76
|
+
const renderMarkdown = text => {
|
|
77
|
+
var _props$webChatContain6, _props$webChatContain7;
|
|
78
|
+
if ((_props$webChatContain6 = props.webChatContainerProps) !== null && _props$webChatContain6 !== void 0 && (_props$webChatContain7 = _props$webChatContain6.webChatProps) !== null && _props$webChatContain7 !== void 0 && _props$webChatContain7.renderMarkdown) {
|
|
79
|
+
var _props$webChatContain8;
|
|
80
|
+
text = (_props$webChatContain8 = props.webChatContainerProps) === null || _props$webChatContain8 === void 0 ? void 0 : _props$webChatContain8.webChatProps.renderMarkdown(text);
|
|
81
|
+
} else {
|
|
82
|
+
const render = disableNewLineMarkdownSupport ? markdown.renderInline.bind(markdown) : markdown.render.bind(markdown);
|
|
83
|
+
text = render(text);
|
|
84
|
+
}
|
|
85
|
+
markdownRenderers.forEach(renderer => {
|
|
86
|
+
text = renderer.render(text);
|
|
87
|
+
});
|
|
88
|
+
return text;
|
|
89
|
+
};
|
|
70
90
|
|
|
71
91
|
// Initialize the remaining Web Chat props
|
|
72
92
|
const webChatProps = {
|
|
@@ -74,10 +94,10 @@ export const initWebChatComposer = (props, chatSDK, setAdapter, state, dispatch,
|
|
|
74
94
|
dir: state.domainStates.globalDir,
|
|
75
95
|
locale: changeLanguageCodeFormatForWebChat(getLocaleStringFromId((_state$domainStates$l4 = state.domainStates.liveChatConfig) === null || _state$domainStates$l4 === void 0 ? void 0 : (_state$domainStates$l5 = _state$domainStates$l4.ChatWidgetLanguage) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.msdyn_localeid)),
|
|
76
96
|
store: webChatStore,
|
|
77
|
-
activityMiddleware: (_props$
|
|
78
|
-
attachmentMiddleware: (_props$
|
|
79
|
-
activityStatusMiddleware: (_props$
|
|
80
|
-
renderMarkdown
|
|
97
|
+
activityMiddleware: (_props$webChatContain9 = props.webChatContainerProps) !== null && _props$webChatContain9 !== void 0 && (_props$webChatContain10 = _props$webChatContain9.renderingMiddlewareProps) !== null && _props$webChatContain10 !== void 0 && _props$webChatContain10.disableActivityMiddleware ? undefined : createActivityMiddleware((_state$domainStates$r = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r === void 0 ? void 0 : _state$domainStates$r.systemMessageStyleProps, (_state$domainStates$r2 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r2 === void 0 ? void 0 : _state$domainStates$r2.userMessageStyleProps),
|
|
98
|
+
attachmentMiddleware: (_props$webChatContain11 = props.webChatContainerProps) !== null && _props$webChatContain11 !== void 0 && (_props$webChatContain12 = _props$webChatContain11.renderingMiddlewareProps) !== null && _props$webChatContain12 !== void 0 && _props$webChatContain12.disableAttachmentMiddleware ? undefined : createAttachmentMiddleware(((_state$domainStates$r3 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r3 === void 0 ? void 0 : (_state$domainStates$r4 = _state$domainStates$r3.attachmentProps) === null || _state$domainStates$r4 === void 0 ? void 0 : _state$domainStates$r4.enableInlinePlaying) ?? defaultAttachmentProps.enableInlinePlaying),
|
|
99
|
+
activityStatusMiddleware: (_props$webChatContain13 = props.webChatContainerProps) !== null && _props$webChatContain13 !== void 0 && (_props$webChatContain14 = _props$webChatContain13.renderingMiddlewareProps) !== null && _props$webChatContain14 !== void 0 && _props$webChatContain14.disableActivityStatusMiddleware ? undefined : (_defaultWebChatContai = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai === void 0 ? void 0 : _defaultWebChatContai.activityStatusMiddleware,
|
|
100
|
+
renderMarkdown,
|
|
81
101
|
avatarMiddleware: (_props$webChatContain15 = props.webChatContainerProps) !== null && _props$webChatContain15 !== void 0 && (_props$webChatContain16 = _props$webChatContain15.renderingMiddlewareProps) !== null && _props$webChatContain16 !== void 0 && _props$webChatContain16.disableAvatarMiddleware ? undefined : createAvatarMiddleware((_state$domainStates$r5 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r5 === void 0 ? void 0 : _state$domainStates$r5.avatarStyleProps, (_state$domainStates$r6 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r6 === void 0 ? void 0 : _state$domainStates$r6.avatarTextStyleProps),
|
|
82
102
|
groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
|
|
83
103
|
typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
|
|
@@ -17,18 +17,17 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
|
|
|
17
17
|
|
|
18
18
|
// Get chat reconnect context
|
|
19
19
|
const reconnectChatContext = await getChatReconnectContext(chatSDK, props.chatConfig, props, isAuthenticatedChat);
|
|
20
|
+
|
|
21
|
+
//Redirect if enabled
|
|
22
|
+
if (reconnectChatContext !== null && reconnectChatContext !== void 0 && reconnectChatContext.redirectURL) {
|
|
23
|
+
var _props$reconnectChatP;
|
|
24
|
+
redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
20
27
|
if (hasReconnectId(reconnectChatContext)) {
|
|
21
28
|
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
22
|
-
//Redirect if enabled
|
|
23
|
-
if (reconnectChatContext.redirectURL && !isNullOrEmptyString(reconnectChatContext.redirectURL)) {
|
|
24
|
-
var _props$reconnectChatP;
|
|
25
|
-
redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
29
|
//if reconnect id is provided in props, don't show reconnect pane
|
|
30
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)) {
|
|
31
|
-
const reconnectChatContext = await getChatReconnectContext(chatSDK, props.chatConfig, props, isAuthenticatedChat);
|
|
32
31
|
await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
@@ -51,6 +50,10 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
|
|
|
51
50
|
const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticatedChat) => {
|
|
52
51
|
try {
|
|
53
52
|
var _props$reconnectChatP4;
|
|
53
|
+
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
54
|
+
Event: TelemetryEvent.GetChatReconnectContextSDKCallStarted,
|
|
55
|
+
Description: "Reconnect context SDK call started"
|
|
56
|
+
});
|
|
54
57
|
const chatReconnectOptionalParams = {
|
|
55
58
|
reconnectId: (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId
|
|
56
59
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Constants, ParticipantType } from "../../../common/Constants";
|
|
2
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
4
|
+
import { addDelayInMs } from "../../../common/utils";
|
|
5
|
+
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
6
|
+
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
7
|
+
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
let conversationDetails = undefined;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
let postChatSurveyMode = undefined;
|
|
12
|
+
const getBotSurveyMode = (props, state) => {
|
|
13
|
+
var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
|
|
14
|
+
return ((_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_postconversationsurveybotsurveymode) ?? ((_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_postconversationsurveybotsurveymode);
|
|
15
|
+
};
|
|
16
|
+
const getUserSurveyMode = (props, state) => {
|
|
17
|
+
var _props$chatConfig2, _props$chatConfig2$Li, _props$chatConfig3, _props$chatConfig3$Li;
|
|
18
|
+
if (!((_props$chatConfig2 = props.chatConfig) !== null && _props$chatConfig2 !== void 0 && (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) !== null && _props$chatConfig2$Li !== void 0 && _props$chatConfig2$Li.msdyn_postconversationsurveymode)) {
|
|
19
|
+
var _state$domainStates, _state$domainStates$l3, _state$domainStates$l4;
|
|
20
|
+
return (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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_postconversationsurveymode) ?? PostChatSurveyMode.Embed;
|
|
21
|
+
}
|
|
22
|
+
return (_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;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Set Survey mode based on conversation ended by entity
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const setSurveyMode = async (props, participantType, state, dispatch) => {
|
|
28
|
+
if (participantType === ParticipantType.User) {
|
|
29
|
+
postChatSurveyMode = getUserSurveyMode(props, state);
|
|
30
|
+
dispatch({
|
|
31
|
+
type: LiveChatWidgetActionType.SET_SURVEY_MODE,
|
|
32
|
+
payload: postChatSurveyMode
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (participantType === ParticipantType.Bot) {
|
|
37
|
+
postChatSurveyMode = getBotSurveyMode(props, state);
|
|
38
|
+
dispatch({
|
|
39
|
+
type: LiveChatWidgetActionType.SET_SURVEY_MODE,
|
|
40
|
+
payload: postChatSurveyMode
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const renderSurvey = async (state, dispatch) => {
|
|
46
|
+
if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
47
|
+
setWidgetStateToInactive(dispatch);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
51
|
+
await embedModePostChatWorkflow(state, dispatch);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Function for embed mode postchat workflow which is essentially same for both customer and agent
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
+
const embedModePostChatWorkflow = async (state, dispatch) => {
|
|
58
|
+
var _state$domainStates2;
|
|
59
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
60
|
+
Event: TelemetryEvent.EmbedModePostChatWorkflowStarted
|
|
61
|
+
});
|
|
62
|
+
if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
|
|
63
|
+
dispatch({
|
|
64
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
65
|
+
payload: ConversationState.PostchatLoading
|
|
66
|
+
});
|
|
67
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
68
|
+
dispatch({
|
|
69
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
70
|
+
payload: ConversationState.Postchat
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
|
|
74
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
75
|
+
Event: TelemetryEvent.AppStatesException,
|
|
76
|
+
ExceptionDetails: {
|
|
77
|
+
exception: error
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
const initiatePostChat = async (props, conversationDetailsParam, state, dispatch) => {
|
|
85
|
+
var _conversationDetails;
|
|
86
|
+
conversationDetails = conversationDetailsParam;
|
|
87
|
+
await setSurveyMode(props, (_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.participantType, state, dispatch);
|
|
88
|
+
await renderSurvey(state, dispatch);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
const isPostChatEnabled = (props, state) => {
|
|
93
|
+
var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l5, _state$domainStates$l6;
|
|
94
|
+
const isPostChatEnabled = ((_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_postconversationsurveyenable) ?? ((_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_postconversationsurveyenable);
|
|
95
|
+
return isPostChatEnabled === Constants.true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
const getPostChatContext = async (chatSDK, state, dispatch) => {
|
|
100
|
+
try {
|
|
101
|
+
var _state$domainStates3;
|
|
102
|
+
if ((state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.postChatContext) === undefined) {
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
const context = await chatSDK.getPostChatSurveyContext();
|
|
105
|
+
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
106
|
+
Event: TelemetryEvent.PostChatContextCallSucceed,
|
|
107
|
+
Description: "Postchat context call succeed."
|
|
108
|
+
});
|
|
109
|
+
dispatch({
|
|
110
|
+
type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
|
|
111
|
+
payload: context
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
116
|
+
Event: TelemetryEvent.PostChatContextCallFailed,
|
|
117
|
+
Description: "Failed to get post chat context."
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Function for link mode postchat workflow which is essentially same for both customer and agent
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
+
const setWidgetStateToInactive = async dispatch => {
|
|
125
|
+
dispatch({
|
|
126
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
127
|
+
payload: ConversationState.InActive
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export { initiatePostChat, setWidgetStateToInactive, getPostChatContext, isPostChatEnabled as checkPostChatEnabled };
|