@microsoft/omnichannel-chat-widget 0.1.0-main.52da005 → 0.1.0-main.52fa2fc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -34
- package/lib/cjs/common/Constants.js +12 -3
- package/lib/cjs/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/cjs/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/cjs/common/utils.js +23 -2
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +139 -0
- package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +36 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +66 -14
- package/lib/cjs/components/livechatwidget/common/endChat.js +43 -63
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +11 -49
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -7
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +83 -64
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +91 -45
- package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/cjs/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +7 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/cjs/contexts/common/ConversationEndEntity.js +12 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +11 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/cjs/contexts/createReducer.js +36 -2
- package/lib/cjs/hooks/useDebounce.js +28 -0
- package/lib/cjs/hooks/useWindowDimensions.js +30 -0
- package/lib/cjs/plugins/newMessageEventHandler.js +14 -0
- package/lib/esm/common/Constants.js +10 -2
- package/lib/esm/common/storage/default/defaultCacheManager.js +2 -2
- package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +15 -6
- package/lib/esm/common/telemetry/TelemetryConstants.js +35 -4
- package/lib/esm/common/telemetry/TelemetryHelper.js +2 -1
- package/lib/esm/common/utils.js +20 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +12 -19
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +5 -2
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +134 -0
- package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +30 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +66 -14
- package/lib/esm/components/livechatwidget/common/endChat.js +45 -65
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -51
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +12 -7
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +83 -64
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +92 -46
- package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
- package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
- package/lib/esm/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
- package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +5 -3
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
- package/lib/esm/contexts/common/ConversationEndEntity.js +5 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +11 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +10 -4
- package/lib/esm/contexts/createReducer.js +36 -2
- package/lib/esm/hooks/useDebounce.js +22 -0
- package/lib/esm/hooks/useWindowDimensions.js +23 -0
- package/lib/esm/plugins/newMessageEventHandler.js +14 -0
- package/lib/types/common/Constants.d.ts +9 -0
- package/lib/types/common/storage/default/defaultCacheManager.d.ts +1 -1
- package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +31 -6
- package/lib/types/common/telemetry/definitions/Contracts.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +1 -0
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +4 -0
- package/lib/types/common/utils.d.ts +1 -0
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +0 -7
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
- package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +6 -1
- package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -3
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.d.ts +1 -1
- package/lib/types/contexts/common/ConversationEndEntity.d.ts +4 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +6 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -7
- package/lib/types/hooks/useDebounce.d.ts +3 -0
- package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
- package/package.json +3 -3
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
3
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
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 {
|
|
9
|
-
import { Constants } from "../../../common/Constants";
|
|
10
|
-
import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils";
|
|
8
|
+
import { getWidgetEndChatEventName } from "../../../common/utils";
|
|
11
9
|
import { getAuthClientFunction, handleAuthentication } from "./authHelper";
|
|
10
|
+
import { checkPostChatEnabled, initiatePostChat } from "./setPostChatContextAndLoadSurvey";
|
|
11
|
+
import { ConversationEndEntity } from "../../../contexts/common/ConversationEndEntity";
|
|
12
12
|
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
|
|
15
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
|
|
16
|
-
const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
|
|
17
|
-
const postChatSurveyMode = (_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;
|
|
18
|
-
|
|
19
15
|
//Unable to end chat if token has expired
|
|
20
16
|
if (props.getAuthToken) {
|
|
21
17
|
const authClientFunction = getAuthClientFunction(props.chatConfig);
|
|
22
18
|
if (props.getAuthToken && authClientFunction) {
|
|
23
|
-
// set auth token to chat sdk before
|
|
19
|
+
// set auth token to chat sdk before end chat
|
|
24
20
|
const authSuccess = await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
|
|
25
21
|
if (!authSuccess) {
|
|
26
22
|
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
@@ -32,60 +28,28 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
|
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Event: TelemetryEvent.GetConversationDetailsException,
|
|
43
|
-
ExceptionDetails: {
|
|
44
|
-
exception: `Failed to get conversation details: ${erorr}`
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
49
|
-
const skipEndChatSDK = false;
|
|
50
|
-
const skipCloseChat = true;
|
|
51
|
-
const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
52
|
-
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
|
|
53
|
-
if (chatSession) {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
chatSDK.chatToken = chatSession.chatToken ?? {};
|
|
56
|
-
chatSDK.requestId = chatSession.requestId;
|
|
31
|
+
const isPostChatEnabled = checkPostChatEnabled(props, state);
|
|
32
|
+
if (isPostChatEnabled) {
|
|
33
|
+
try {
|
|
34
|
+
await initiatePostChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
// Ending chat because something went wrong
|
|
37
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
57
38
|
}
|
|
58
|
-
|
|
39
|
+
} else {
|
|
40
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
|
|
59
41
|
dispatch({
|
|
60
|
-
type: LiveChatWidgetActionType.
|
|
61
|
-
payload:
|
|
62
|
-
});
|
|
63
|
-
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
64
|
-
const loadPostChatEvent = {
|
|
65
|
-
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
66
|
-
};
|
|
67
|
-
BroadcastService.postMessage(loadPostChatEvent);
|
|
68
|
-
} else if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
69
|
-
var _props$webChatContain, _props$webChatContain2;
|
|
42
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
43
|
+
payload: undefined
|
|
44
|
+
});
|
|
70
45
|
dispatch({
|
|
71
|
-
type: LiveChatWidgetActionType.
|
|
72
|
-
payload:
|
|
46
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
47
|
+
payload: undefined
|
|
73
48
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
-
setWebChatStyles(styles => {
|
|
79
|
-
return {
|
|
80
|
-
...styles,
|
|
81
|
-
hideSendBox: true
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
}
|
|
49
|
+
} else {
|
|
50
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
85
51
|
}
|
|
86
|
-
return;
|
|
87
52
|
}
|
|
88
|
-
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
89
53
|
};
|
|
90
54
|
|
|
91
55
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -106,7 +70,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
106
70
|
postMessageToOtherTab = false;
|
|
107
71
|
}
|
|
108
72
|
}
|
|
109
|
-
|
|
110
73
|
// Need to clear these states immediately when chat ended from OC.
|
|
111
74
|
dispatch({
|
|
112
75
|
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
@@ -126,12 +89,12 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
126
89
|
});
|
|
127
90
|
if (!skipCloseChat) {
|
|
128
91
|
try {
|
|
129
|
-
var _props$
|
|
92
|
+
var _props$webChatContain;
|
|
130
93
|
adapter === null || adapter === void 0 ? void 0 : adapter.end();
|
|
131
94
|
setAdapter(undefined);
|
|
132
95
|
setWebChatStyles({
|
|
133
96
|
...defaultWebChatContainerStatefulProps.webChatStyles,
|
|
134
|
-
...((_props$
|
|
97
|
+
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
135
98
|
});
|
|
136
99
|
WebChatStoreLoader.store = null;
|
|
137
100
|
dispatch({
|
|
@@ -139,9 +102,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
139
102
|
payload: ConversationState.Closed
|
|
140
103
|
});
|
|
141
104
|
dispatch({
|
|
142
|
-
type: LiveChatWidgetActionType.
|
|
105
|
+
type: LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
|
|
143
106
|
payload: false
|
|
144
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
|
+
});
|
|
145
120
|
dispatch({
|
|
146
121
|
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
147
122
|
payload: undefined
|
|
@@ -150,10 +125,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
150
125
|
type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
|
|
151
126
|
payload: null
|
|
152
127
|
});
|
|
153
|
-
dispatch({
|
|
154
|
-
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
155
|
-
payload: 0
|
|
156
|
-
});
|
|
157
128
|
dispatch({
|
|
158
129
|
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
159
130
|
payload: {
|
|
@@ -169,6 +140,10 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
169
140
|
eventName: endChatEventName
|
|
170
141
|
});
|
|
171
142
|
}
|
|
143
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
144
|
+
Event: TelemetryEvent.CloseChatCall,
|
|
145
|
+
Description: "Chat was closed succesfully"
|
|
146
|
+
});
|
|
172
147
|
} catch (error) {
|
|
173
148
|
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
174
149
|
Event: TelemetryEvent.CloseChatMethodException,
|
|
@@ -176,6 +151,11 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
176
151
|
exception: `Failed to endChat: ${error}`
|
|
177
152
|
}
|
|
178
153
|
});
|
|
154
|
+
} finally {
|
|
155
|
+
dispatch({
|
|
156
|
+
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
157
|
+
payload: 0
|
|
158
|
+
});
|
|
179
159
|
}
|
|
180
160
|
}
|
|
181
161
|
};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import { createStore } from "botframework-webchat";
|
|
3
|
-
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
4
|
-
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
3
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
|
-
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
7
4
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
8
5
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
9
6
|
import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
|
|
10
|
-
import {
|
|
7
|
+
import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
|
|
11
8
|
import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
|
|
12
9
|
import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
|
|
13
10
|
import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
|
|
@@ -29,11 +26,10 @@ import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontr
|
|
|
29
26
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
30
27
|
import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
|
|
31
28
|
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
32
|
-
import { Constants } from "../../../common/Constants";
|
|
33
29
|
|
|
34
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
|
|
36
|
-
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$
|
|
31
|
+
export const initWebChatComposer = (props, chatSDK, setAdapter, state, dispatch, adapter, setWebChatStyles) => {
|
|
32
|
+
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
|
|
37
33
|
const localizedTexts = {
|
|
38
34
|
...defaultMiddlewareLocalizedTexts,
|
|
39
35
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
|
|
@@ -41,19 +37,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
41
37
|
const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
|
|
42
38
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
43
39
|
const markdown = createMarkdown(((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.disableMarkdownMessageFormatting) ?? defaultWebChatContainerStatefulProps.disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
|
|
44
|
-
const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
|
|
45
|
-
const postChatSurveyMode = (_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;
|
|
46
|
-
|
|
47
40
|
// Initialize Web Chat's redux store
|
|
48
41
|
let webChatStore = WebChatStoreLoader.store;
|
|
49
42
|
if (!webChatStore) {
|
|
50
|
-
var _state$domainStates$
|
|
43
|
+
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain6;
|
|
51
44
|
const conversationEndCallback = async () => {
|
|
52
45
|
var _props$webChatContain4, _props$webChatContain5;
|
|
53
|
-
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
54
|
-
Event: TelemetryEvent.ConversationEndedThreadEventReceived,
|
|
55
|
-
Description: "Conversation is ended by agent side or by timeout."
|
|
56
|
-
});
|
|
57
46
|
if ((props === null || props === void 0 ? void 0 : (_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : (_props$webChatContain5 = _props$webChatContain4.renderingMiddlewareProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.hideSendboxOnConversationEnd) !== false) {
|
|
58
47
|
setWebChatStyles(styles => {
|
|
59
48
|
return {
|
|
@@ -62,46 +51,18 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
62
51
|
};
|
|
63
52
|
});
|
|
64
53
|
}
|
|
65
|
-
if (isPostChatEnabled === "true") {
|
|
66
|
-
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
67
|
-
WebChatStoreLoader.store = null;
|
|
68
|
-
dispatch({
|
|
69
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
70
|
-
payload: ConversationState.PostchatLoading
|
|
71
|
-
});
|
|
72
|
-
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
73
|
-
const loadPostChatEvent = {
|
|
74
|
-
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
75
|
-
};
|
|
76
|
-
BroadcastService.postMessage(loadPostChatEvent);
|
|
77
|
-
} else if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
78
|
-
dispatch({
|
|
79
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
80
|
-
payload: ConversationState.InActive
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
dispatch({
|
|
85
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
86
|
-
payload: ConversationState.InActive
|
|
87
|
-
});
|
|
88
|
-
dispatch({
|
|
89
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
|
|
90
|
-
payload: true
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
54
|
dispatch({
|
|
94
|
-
type: LiveChatWidgetActionType.
|
|
95
|
-
payload:
|
|
55
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
|
|
56
|
+
payload: true
|
|
96
57
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
59
|
+
Event: TelemetryEvent.ConversationEndedThreadEventReceived,
|
|
60
|
+
Description: "Conversation end by agent side or by timeout event received."
|
|
100
61
|
});
|
|
101
62
|
};
|
|
102
63
|
webChatStore = createStore({},
|
|
103
64
|
//initial state
|
|
104
|
-
preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$
|
|
65
|
+
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,
|
|
105
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
67
|
...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
|
|
107
68
|
WebChatStoreLoader.store = webChatStore;
|
|
@@ -111,7 +72,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
111
72
|
const webChatProps = {
|
|
112
73
|
...defaultWebChatContainerStatefulProps.webChatProps,
|
|
113
74
|
dir: state.domainStates.globalDir,
|
|
114
|
-
locale: changeLanguageCodeFormatForWebChat(getLocaleStringFromId((_state$domainStates$
|
|
75
|
+
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)),
|
|
115
76
|
store: webChatStore,
|
|
116
77
|
activityMiddleware: (_props$webChatContain7 = props.webChatContainerProps) !== null && _props$webChatContain7 !== void 0 && (_props$webChatContain8 = _props$webChatContain7.renderingMiddlewareProps) !== null && _props$webChatContain8 !== void 0 && _props$webChatContain8.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),
|
|
117
78
|
attachmentMiddleware: (_props$webChatContain9 = props.webChatContainerProps) !== null && _props$webChatContain9 !== void 0 && (_props$webChatContain10 = _props$webChatContain9.renderingMiddlewareProps) !== null && _props$webChatContain10 !== void 0 && _props$webChatContain10.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),
|
|
@@ -122,6 +83,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
122
83
|
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,
|
|
123
84
|
onTelemetry: createWebChatTelemetry(),
|
|
124
85
|
cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
|
|
86
|
+
sendTypingIndicator: true,
|
|
125
87
|
...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
|
|
126
88
|
};
|
|
127
89
|
return webChatProps;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import "regenerator-runtime/runtime";
|
|
2
2
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
|
+
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
|
|
4
|
+
import { isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
|
|
3
5
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
4
6
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
7
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
8
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
-
|
|
8
|
-
import { isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
|
|
9
|
+
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
|
|
11
12
|
var _props$chatConfig, _props$chatConfig$Liv;
|
|
@@ -53,14 +54,14 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
|
|
|
53
54
|
const chatReconnectOptionalParams = {
|
|
54
55
|
reconnectId: (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId
|
|
55
56
|
};
|
|
57
|
+
// Get auth token for getting chat reconnect context
|
|
56
58
|
if (isAuthenticatedChat) {
|
|
57
|
-
// Get auth token for for getting chat reconnect context
|
|
58
59
|
await handleAuthentication(chatSDK, chatConfig, props.getAuthToken);
|
|
59
60
|
}
|
|
60
61
|
const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
|
|
61
62
|
if (isAuthenticatedChat) {
|
|
62
63
|
// remove auth token after reconnectId is fetched
|
|
63
|
-
//
|
|
64
|
+
// AuthToken will be reset later at start chat
|
|
64
65
|
removeAuthTokenProvider(chatSDK);
|
|
65
66
|
}
|
|
66
67
|
return reconnectChatContext;
|
|
@@ -93,7 +94,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, d
|
|
|
93
94
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
94
95
|
payload: ConversationState.Loading
|
|
95
96
|
});
|
|
96
|
-
await initStartChat(chatSDK,
|
|
97
|
+
await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
|
|
97
98
|
};
|
|
98
99
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
99
100
|
const redirectPageRequest = {
|
|
@@ -108,8 +109,12 @@ const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
|
108
109
|
}
|
|
109
110
|
};
|
|
110
111
|
const isReconnectEnabled = chatConfig => {
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
if (chatConfig) {
|
|
113
|
+
var _chatConfig$LiveWSAnd, _chatConfig$LiveWSAnd2;
|
|
114
|
+
const reconnectEnabled = ((_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : (_chatConfig$LiveWSAnd2 = _chatConfig$LiveWSAnd.msdyn_enablechatreconnect) === null || _chatConfig$LiveWSAnd2 === void 0 ? void 0 : _chatConfig$LiveWSAnd2.toLowerCase()) === "true";
|
|
115
|
+
return reconnectEnabled;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
113
118
|
};
|
|
114
119
|
const hasReconnectId = reconnectAvailabilityResponse => {
|
|
115
120
|
return reconnectAvailabilityResponse && !isNullOrUndefined(reconnectAvailabilityResponse.reconnectId);
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
1
|
+
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
2
2
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
3
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
5
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
6
|
+
import { Constants } from "../../../common/Constants";
|
|
7
|
+
import { endChat } from "./endChat";
|
|
8
|
+
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
9
|
+
import { addDelayInMs } from "../../../common/utils";
|
|
10
|
+
import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
|
|
11
|
+
import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
|
|
12
|
+
import { ConversationEndEntity } from "../../../contexts/common/ConversationEndEntity";
|
|
6
13
|
|
|
7
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
|
|
15
|
+
const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
|
|
9
16
|
try {
|
|
10
17
|
if (!persistedChat) {
|
|
11
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -35,4 +42,249 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
|
|
|
35
42
|
payload: ConversationState.Postchat
|
|
36
43
|
});
|
|
37
44
|
});
|
|
38
|
-
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
const checkPostChatEnabled = (props, state) => {
|
|
49
|
+
var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
|
|
50
|
+
const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
|
|
51
|
+
return isPostChatEnabled === Constants.true;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
const initiatePostChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
|
|
56
|
+
// Check if Postchat already in progress and handle case where chat is ended by customer
|
|
57
|
+
if (state.appStates.postChatWorkflowInProgress && state.appStates.conversationEndedBy === ConversationEndEntity.Customer) {
|
|
58
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Conversation Details call required by customer as well as agent
|
|
63
|
+
const conversationDetails = await getConversationDetailsCall(chatSDK);
|
|
64
|
+
// Start Postchat workflow
|
|
65
|
+
dispatch({
|
|
66
|
+
type: LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
|
|
67
|
+
payload: true
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Below logic checks if agent or bot or noone joins conversation and handles them separately
|
|
71
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === Constants.userParticipantTypeTag) {
|
|
72
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Customer) {
|
|
73
|
+
// Set use bot settings to false
|
|
74
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
|
|
75
|
+
} else if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
|
|
76
|
+
await postChatInitiatedByAgent(props, setWebChatStyles, dispatch, state);
|
|
77
|
+
} else {
|
|
78
|
+
const error = `Conversation was Ended after agent joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
79
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
80
|
+
Event: TelemetryEvent.AppStatesException,
|
|
81
|
+
ExceptionDetails: {
|
|
82
|
+
exception: error
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
throw new Error(error);
|
|
86
|
+
}
|
|
87
|
+
} else if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === Constants.botParticipantTypeTag) {
|
|
88
|
+
// Set Use bot survey to true
|
|
89
|
+
dispatch({
|
|
90
|
+
type: LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
|
|
91
|
+
payload: true
|
|
92
|
+
});
|
|
93
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Customer) {
|
|
94
|
+
// Set use bot settings to true
|
|
95
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, true);
|
|
96
|
+
} else if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
|
|
97
|
+
await postChatInitiatedByBot(props, setWebChatStyles, dispatch, state);
|
|
98
|
+
} else {
|
|
99
|
+
const error = `Conversation was Ended after bot joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
100
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
101
|
+
Event: TelemetryEvent.AppStatesException,
|
|
102
|
+
ExceptionDetails: {
|
|
103
|
+
exception: error
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
throw new Error(error);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
if (state.appStates.conversationEndedBy === ConversationEndEntity.Customer) {
|
|
110
|
+
// No one has joined chat will be handled by postChat customer
|
|
111
|
+
await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
|
|
112
|
+
} else {
|
|
113
|
+
const error = `ConversationDetails and App state was not set correctly: conversationDetails = ${JSON.stringify(conversationDetails)} , conversationEndedBy = ${state.appStates.conversationEndedBy}`;
|
|
114
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
115
|
+
Event: TelemetryEvent.AppStatesException,
|
|
116
|
+
ExceptionDetails: {
|
|
117
|
+
exception: error
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
throw new Error(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Function for link mode postchat workflow which is essentially same for both customer and agent
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
+
const linkModePostChatWorkflow = (props, dispatch, setWebChatStyles) => {
|
|
128
|
+
var _props$webChatContain, _props$webChatContain2;
|
|
129
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
130
|
+
Event: TelemetryEvent.LinkModePostChatWorkflowStarted
|
|
131
|
+
});
|
|
132
|
+
dispatch({
|
|
133
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
134
|
+
payload: ConversationState.InActive
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Disable SendBox
|
|
138
|
+
if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
setWebChatStyles(styles => {
|
|
141
|
+
return {
|
|
142
|
+
...styles,
|
|
143
|
+
hideSendBox: true
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Function for embed mode postchat workflow which is essentially same for both customer and agent
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
const embedModePostChatWorkflow = async (dispatch, state) => {
|
|
152
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
153
|
+
Event: TelemetryEvent.EmbedModePostChatWorkflowStarted
|
|
154
|
+
});
|
|
155
|
+
if (state.domainStates.postChatContext) {
|
|
156
|
+
dispatch({
|
|
157
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
158
|
+
payload: ConversationState.PostchatLoading
|
|
159
|
+
});
|
|
160
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
161
|
+
const loadPostChatEvent = {
|
|
162
|
+
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
163
|
+
};
|
|
164
|
+
BroadcastService.postMessage(loadPostChatEvent);
|
|
165
|
+
} else {
|
|
166
|
+
const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
|
|
167
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
168
|
+
Event: TelemetryEvent.AppStatesException,
|
|
169
|
+
ExceptionDetails: {
|
|
170
|
+
exception: error
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
throw new Error(error);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// Function will handle only postchat cases initiated by customer
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
+
const postChatInitiatedByCustomer = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, shouldUseBotSetting) => {
|
|
180
|
+
let postChatSurveyMode = "";
|
|
181
|
+
if (shouldUseBotSetting) {
|
|
182
|
+
var _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4;
|
|
183
|
+
postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveybotsurveymode);
|
|
184
|
+
} else {
|
|
185
|
+
var _props$chatConfig3, _props$chatConfig3$Li, _state$domainStates$l5, _state$domainStates$l6;
|
|
186
|
+
postChatSurveyMode = ((_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : (_state$domainStates$l6 = _state$domainStates$l5.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.msdyn_postconversationsurveymode);
|
|
187
|
+
}
|
|
188
|
+
// Check if agent or bot has joined conversation
|
|
189
|
+
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
190
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
191
|
+
Event: TelemetryEvent.PostChatWorkflowFromCustomer,
|
|
192
|
+
Description: shouldUseBotSetting ? "PostChat Workflow was started by customer using bot settings" : "PostChat Workflow was started by customer using agent settings"
|
|
193
|
+
});
|
|
194
|
+
const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
195
|
+
// End chat call to end chatsdk but not close chat, only if chat ended by customer
|
|
196
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
|
|
197
|
+
// Saving request Id below for chat transcript calls
|
|
198
|
+
if (chatSession) {
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
chatSDK.chatToken = chatSession.chatToken ?? {};
|
|
201
|
+
chatSDK.requestId = chatSession.requestId;
|
|
202
|
+
}
|
|
203
|
+
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
204
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
205
|
+
} else if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
206
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
207
|
+
} else {
|
|
208
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
209
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
210
|
+
Event: TelemetryEvent.AppStatesException,
|
|
211
|
+
ExceptionDetails: {
|
|
212
|
+
exception: error
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
throw new Error(error);
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
// Agent did not join chat so end chat normally
|
|
219
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// Function will handle only postchat cases initiated by agent
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
|
|
226
|
+
var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
|
|
227
|
+
const postChatSurveyMode = ((_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : (_state$domainStates$l8 = _state$domainStates$l7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l8 === void 0 ? void 0 : _state$domainStates$l8.msdyn_postconversationsurveymode);
|
|
228
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
229
|
+
Event: TelemetryEvent.PostChatWorkflowFromAgent,
|
|
230
|
+
Description: "PostChat Workflow was started by agent"
|
|
231
|
+
});
|
|
232
|
+
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
233
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
234
|
+
} else if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
235
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
236
|
+
} else {
|
|
237
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
|
|
238
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
239
|
+
Event: TelemetryEvent.AppStatesException,
|
|
240
|
+
ExceptionDetails: {
|
|
241
|
+
exception: error
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
throw new Error(error);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Function will handle only postchat cases initiated by bot
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
|
+
const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
|
|
251
|
+
var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
|
|
252
|
+
const postChatSurveyMode = ((_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l9 = state.domainStates.liveChatConfig) === null || _state$domainStates$l9 === void 0 ? void 0 : (_state$domainStates$l10 = _state$domainStates$l9.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l10 === void 0 ? void 0 : _state$domainStates$l10.msdyn_postconversationsurveybotsurveymode);
|
|
253
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
254
|
+
Event: TelemetryEvent.PostChatWorkflowFromBot,
|
|
255
|
+
Description: "PostChat Workflow was started by bot"
|
|
256
|
+
});
|
|
257
|
+
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
258
|
+
await embedModePostChatWorkflow(dispatch, state);
|
|
259
|
+
} else if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
260
|
+
linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
|
|
261
|
+
} else {
|
|
262
|
+
const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
|
|
263
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
264
|
+
Event: TelemetryEvent.AppStatesException,
|
|
265
|
+
ExceptionDetails: {
|
|
266
|
+
exception: error
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
throw new Error(error);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
+
const getConversationDetailsCall = async chatSDK => {
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
+
let conversationDetails = undefined;
|
|
277
|
+
try {
|
|
278
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
279
|
+
} catch (error) {
|
|
280
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
281
|
+
Event: TelemetryEvent.GetConversationDetailsCallFailed,
|
|
282
|
+
ExceptionDetails: {
|
|
283
|
+
exception: `Get Conversation Details Call Failed : ${error}`
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
NotificationHandler.notifyError(NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
|
|
287
|
+
}
|
|
288
|
+
return conversationDetails;
|
|
289
|
+
};
|
|
290
|
+
export { setPostChatContextAndLoadSurvey, checkPostChatEnabled, initiatePostChat };
|