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