@microsoft/omnichannel-chat-widget 1.8.2-main.e3c1d40 → 1.8.2-main.f638bed
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 +48 -1
- package/lib/cjs/common/Constants.js +16 -3
- package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/cjs/common/utils.js +27 -2
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -4
- package/lib/cjs/components/draggable/DraggableChatWidget.js +16 -1
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +22 -9
- package/lib/cjs/components/livechatwidget/common/customEventHandler.js +53 -0
- package/lib/cjs/components/livechatwidget/common/endChat.js +18 -7
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +32 -1
- package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +18 -1
- package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +31 -7
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +15 -2
- package/lib/cjs/components/livechatwidget/common/startChat.js +6 -4
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +27 -12
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware.js +4 -3
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +12 -6
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/customEventMiddleware.js +41 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.js +45 -0
- package/lib/cjs/contexts/common/CustomEventType.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +3 -1
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/cjs/contexts/createReducer.js +30 -0
- package/lib/cjs/controller/componentController.js +2 -2
- package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +101 -36
- package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +39 -21
- package/lib/cjs/firstresponselatency/util.js +60 -31
- package/lib/cjs/plugins/newMessageEventHandler.js +12 -6
- package/lib/esm/common/Constants.js +14 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/esm/common/utils.js +21 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -4
- package/lib/esm/components/draggable/DraggableChatWidget.js +16 -1
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +22 -9
- package/lib/esm/components/livechatwidget/common/customEventHandler.js +45 -0
- package/lib/esm/components/livechatwidget/common/endChat.js +18 -7
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +32 -1
- package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +16 -0
- package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +33 -9
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +16 -3
- package/lib/esm/components/livechatwidget/common/startChat.js +6 -4
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +27 -12
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware.js +4 -4
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +12 -6
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/customEventMiddleware.js +33 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.js +38 -0
- package/lib/esm/contexts/common/CustomEventType.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +3 -1
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/esm/contexts/createReducer.js +30 -0
- package/lib/esm/controller/componentController.js +2 -2
- package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +101 -36
- package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +39 -21
- package/lib/esm/firstresponselatency/util.js +57 -29
- package/lib/esm/plugins/newMessageEventHandler.js +12 -6
- package/lib/types/common/Constants.d.ts +13 -2
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +2 -0
- package/lib/types/common/utils.d.ts +8 -0
- package/lib/types/components/livechatwidget/common/customEventHandler.d.ts +4 -0
- package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/customEventMiddleware.d.ts +22 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.d.ts +5 -0
- package/lib/types/contexts/common/CustomEventType.d.ts +6 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
- package/lib/types/firstresponselatency/FirstResponseLatencyTracker.d.ts +2 -2
- package/lib/types/firstresponselatency/util.d.ts +17 -0
- package/lib/types/plugins/newMessageEventHandler.d.ts +1 -1
- package/package.json +4 -4
|
@@ -25,8 +25,11 @@ const DraggableChatWidget = props => {
|
|
|
25
25
|
};
|
|
26
26
|
const calculateOffsetsWithinViewport = useCallback((id, offset, delta) => {
|
|
27
27
|
const draggableElement = document.getElementById(id);
|
|
28
|
+
if (isNullOrUndefined(draggableElement)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
28
31
|
const positionRelativeToViewport = draggableElement.getBoundingClientRect();
|
|
29
|
-
if (isNullOrUndefined(
|
|
32
|
+
if (isNullOrUndefined(positionRelativeToViewport) || isNullOrUndefined(offset.offsetLeft) || isNullOrUndefined(offset.offsetTop)) {
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
32
35
|
let offsetLeft = offset.offsetLeft;
|
|
@@ -68,6 +71,9 @@ const DraggableChatWidget = props => {
|
|
|
68
71
|
}
|
|
69
72
|
const cacheInitialPosition = () => {
|
|
70
73
|
const draggableElement = document.getElementById(props.elementId);
|
|
74
|
+
if (isNullOrUndefined(draggableElement)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
71
77
|
const offsetLeft = draggableElement.offsetLeft;
|
|
72
78
|
const offsetTop = draggableElement.offsetTop;
|
|
73
79
|
setInitialPosition({
|
|
@@ -77,6 +83,9 @@ const DraggableChatWidget = props => {
|
|
|
77
83
|
};
|
|
78
84
|
const calculateOffsets = () => {
|
|
79
85
|
const draggableElement = document.getElementById(props.elementId);
|
|
86
|
+
if (isNullOrUndefined(draggableElement)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
80
89
|
const offsetLeft = draggableElement.offsetLeft;
|
|
81
90
|
const offsetTop = draggableElement.offsetTop;
|
|
82
91
|
|
|
@@ -111,6 +120,9 @@ const DraggableChatWidget = props => {
|
|
|
111
120
|
resetPosition(initialPosition);
|
|
112
121
|
} else if (state.appStates.isMinimized) {
|
|
113
122
|
const draggableElement = document.getElementById(props.elementId);
|
|
123
|
+
if (isNullOrUndefined(draggableElement)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
114
126
|
const offsetLeft = draggableElement.offsetLeft;
|
|
115
127
|
const offsetTop = draggableElement.offsetTop;
|
|
116
128
|
if (!cachedPosition) {
|
|
@@ -135,6 +147,9 @@ const DraggableChatWidget = props => {
|
|
|
135
147
|
|
|
136
148
|
// Update position via DOM manipulation to prevent <Stack/> continuously rendering on style change causing high CPU spike
|
|
137
149
|
const draggableElement = document.getElementById(props.elementId);
|
|
150
|
+
if (isNullOrUndefined(draggableElement)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
138
153
|
repositionElement(draggableElement, offsetLeft, offsetTop);
|
|
139
154
|
setPosition({
|
|
140
155
|
offsetLeft,
|
|
@@ -7,34 +7,47 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
|
7
7
|
import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
|
|
8
8
|
import { executeReducer } from "../../../contexts/createReducer";
|
|
9
9
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
10
|
-
const
|
|
10
|
+
const getRegionBasedInternetTestUrl = widgetSnippet => {
|
|
11
|
+
var _widgetSnippet$match;
|
|
12
|
+
if (!widgetSnippet) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
|
|
16
|
+
const baseCdnUrl = (_widgetSnippet$match = widgetSnippet.match(widgetSnippetSourceRegex)) === null || _widgetSnippet$match === void 0 ? void 0 : _widgetSnippet$match[1];
|
|
17
|
+
return baseCdnUrl ? `${baseCdnUrl}${Constants.internetConnectionTestPath}` : null;
|
|
18
|
+
};
|
|
19
|
+
const isInternetConnected = async testUrl => {
|
|
11
20
|
try {
|
|
12
|
-
const response = await fetch(
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
const response = await fetch(testUrl, {
|
|
22
|
+
method: "GET",
|
|
23
|
+
cache: "no-cache"
|
|
24
|
+
});
|
|
25
|
+
return response.ok;
|
|
15
26
|
} catch {
|
|
16
27
|
return false;
|
|
17
28
|
}
|
|
18
29
|
};
|
|
19
30
|
export const createInternetConnectionChangeHandler = async state => {
|
|
20
31
|
const handler = async () => {
|
|
21
|
-
|
|
32
|
+
var _inMemoryState$domain, _inMemoryState$domain2;
|
|
22
33
|
const inMemoryState = executeReducer(state, {
|
|
23
34
|
type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
24
35
|
payload: null
|
|
25
36
|
});
|
|
37
|
+
const testUrl = getRegionBasedInternetTestUrl((_inMemoryState$domain = inMemoryState.domainStates.liveChatConfig) === null || _inMemoryState$domain === void 0 ? void 0 : (_inMemoryState$domain2 = _inMemoryState$domain.LiveWSAndLiveChatEngJoin) === null || _inMemoryState$domain2 === void 0 ? void 0 : _inMemoryState$domain2.msdyn_widgetsnippet);
|
|
38
|
+
const connected = testUrl ? await isInternetConnected(testUrl) : false;
|
|
26
39
|
if (!connected) {
|
|
27
|
-
var _inMemoryState$
|
|
40
|
+
var _inMemoryState$domain3, _inMemoryState$domain4;
|
|
28
41
|
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
29
42
|
Event: TelemetryEvent.NetworkDisconnected
|
|
30
43
|
});
|
|
31
|
-
NotificationHandler.notifyError(NotificationScenarios.InternetConnection, (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$
|
|
44
|
+
NotificationHandler.notifyError(NotificationScenarios.InternetConnection, (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$domain3 = inMemoryState.domainStates) === null || _inMemoryState$domain3 === void 0 ? void 0 : (_inMemoryState$domain4 = _inMemoryState$domain3.middlewareLocalizedTexts) === null || _inMemoryState$domain4 === void 0 ? void 0 : _inMemoryState$domain4.MIDDLEWARE_BANNER_NO_INTERNET_CONNECTION) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_NO_INTERNET_CONNECTION);
|
|
32
45
|
} else {
|
|
33
|
-
var _inMemoryState$
|
|
46
|
+
var _inMemoryState$domain5, _inMemoryState$domain6;
|
|
34
47
|
TelemetryHelper.logActionEvent(LogLevel.WARN, {
|
|
35
48
|
Event: TelemetryEvent.NetworkReconnected
|
|
36
49
|
});
|
|
37
|
-
NotificationHandler.notifySuccess(NotificationScenarios.InternetConnection, (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$
|
|
50
|
+
NotificationHandler.notifySuccess(NotificationScenarios.InternetConnection, (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$domain5 = inMemoryState.domainStates) === null || _inMemoryState$domain5 === void 0 ? void 0 : (_inMemoryState$domain6 = _inMemoryState$domain5.middlewareLocalizedTexts) === null || _inMemoryState$domain6 === void 0 ? void 0 : _inMemoryState$domain6.MIDDLEWARE_BANNER_INTERNET_BACK_ONLINE) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_INTERNET_BACK_ONLINE);
|
|
38
51
|
BroadcastService.postMessage({
|
|
39
52
|
eventName: BroadcastEvent.NetworkReconnected
|
|
40
53
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Constants } from "../../../common/Constants";
|
|
2
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
3
|
+
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
4
|
+
import { getCustomEventValue, isValidCustomEvent } from "../../../common/utils";
|
|
5
|
+
export const customEventCallback = facadeChatSDK => event => {
|
|
6
|
+
if (!(Constants.payload in event)) return;
|
|
7
|
+
if (isValidCustomEvent(event.payload)) {
|
|
8
|
+
const customEventPayload = event.payload;
|
|
9
|
+
try {
|
|
10
|
+
const customEventValueStr = getCustomEventValue(customEventPayload);
|
|
11
|
+
const customEventName = customEventPayload.customEventName;
|
|
12
|
+
const messageMeta = {
|
|
13
|
+
customEvent: Constants.true,
|
|
14
|
+
customEventName: customEventName,
|
|
15
|
+
customEventValue: customEventValueStr
|
|
16
|
+
};
|
|
17
|
+
const messagePayload = {
|
|
18
|
+
content: "",
|
|
19
|
+
tags: [Constants.Hidden],
|
|
20
|
+
metadata: messageMeta,
|
|
21
|
+
timestamp: new Date()
|
|
22
|
+
};
|
|
23
|
+
facadeChatSDK.sendMessage(messagePayload);
|
|
24
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.DEBUG, {
|
|
25
|
+
Event: TelemetryEvent.CustomEventAction,
|
|
26
|
+
Description: "Sent customEvent.",
|
|
27
|
+
CustomProperties: {
|
|
28
|
+
customEventName,
|
|
29
|
+
lengthCustomEventValue: customEventValueStr.length
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
TelemetryHelper.logActionEventToAllTelemetry(LogLevel.ERROR, {
|
|
34
|
+
Event: TelemetryEvent.CustomEventAction,
|
|
35
|
+
Description: "Failed to process CustomEvent.",
|
|
36
|
+
ExceptionDetails: {
|
|
37
|
+
error
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export const subscribeToSendCustomEvent = (broadcastService, facadeChatSDK, customEventCallback) => {
|
|
44
|
+
broadcastService.getMessageByEventName(Constants.sendCustomEvent).subscribe(customEventCallback(facadeChatSDK));
|
|
45
|
+
};
|
|
@@ -16,7 +16,7 @@ import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
|
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
17
|
const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
|
|
18
18
|
try {
|
|
19
|
-
var _conversationDetails$, _state$domainStates, _state$
|
|
19
|
+
var _conversationDetails$, _state$domainStates, _state$appStates5;
|
|
20
20
|
const {
|
|
21
21
|
chatConfig
|
|
22
22
|
} = props;
|
|
@@ -27,7 +27,7 @@ const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter,
|
|
|
27
27
|
|
|
28
28
|
// Use Case: When post chat is not configured
|
|
29
29
|
if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : (_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === Constants.false) {
|
|
30
|
-
var _state$appStates;
|
|
30
|
+
var _state$appStates, _state$appStates2, _state$appStates3;
|
|
31
31
|
// If ended by customer, just close chat
|
|
32
32
|
if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === ConversationEndEntity.Customer) {
|
|
33
33
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
@@ -38,6 +38,13 @@ const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter,
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Use Case: If ended by Agent, stay chat in InActive state
|
|
41
|
+
let isConversationalSurveyEnabled = state.appStates.isConversationalSurveyEnabled;
|
|
42
|
+
if (isConversationalSurveyEnabled && ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.conversationEndedBy) === ConversationEndEntity.Bot)) {
|
|
43
|
+
dispatch({
|
|
44
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
45
|
+
payload: ConversationState.InActive
|
|
46
|
+
});
|
|
47
|
+
}
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -53,7 +60,7 @@ const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter,
|
|
|
53
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
61
|
const postchatContext = (await getPostChatContext(facadeChatSDK, state, dispatch)) ?? (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.postChatContext);
|
|
55
62
|
if (postchatContext === undefined) {
|
|
56
|
-
var _state$
|
|
63
|
+
var _state$appStates4;
|
|
57
64
|
BroadcastService.postMessage({
|
|
58
65
|
eventName: BroadcastEvent.OnWidgetError,
|
|
59
66
|
payload: {
|
|
@@ -62,7 +69,7 @@ const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter,
|
|
|
62
69
|
});
|
|
63
70
|
|
|
64
71
|
// For Customer intiated conversations, just close chat widget
|
|
65
|
-
if ((state === null || state === void 0 ? void 0 : (_state$
|
|
72
|
+
if ((state === null || state === void 0 ? void 0 : (_state$appStates4 = state.appStates) === null || _state$appStates4 === void 0 ? void 0 : _state$appStates4.conversationEndedBy) === ConversationEndEntity.Customer) {
|
|
66
73
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
67
74
|
Event: TelemetryEvent.PrepareEndChat,
|
|
68
75
|
Description: PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat
|
|
@@ -80,11 +87,11 @@ const prepareEndChat = async (props, facadeChatSDK, state, dispatch, setAdapter,
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
// Log PrepareEndChat if conversation ended by customer (bot and agent cases are handled in LiveChatWidgetStateful.tsx)
|
|
83
|
-
if (state !== null && state !== void 0 && (_state$
|
|
84
|
-
var _state$
|
|
90
|
+
if (state !== null && state !== void 0 && (_state$appStates5 = state.appStates) !== null && _state$appStates5 !== void 0 && _state$appStates5.conversationEndedBy) {
|
|
91
|
+
var _state$appStates6;
|
|
85
92
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
86
93
|
Event: TelemetryEvent.PrepareEndChat,
|
|
87
|
-
Description: `${PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat} ${state === null || state === void 0 ? void 0 : (_state$
|
|
94
|
+
Description: `${PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat} ${state === null || state === void 0 ? void 0 : (_state$appStates6 = state.appStates) === null || _state$appStates6 === void 0 ? void 0 : _state$appStates6.conversationEndedBy}.`
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
97
|
const persistentEnabled = isPersistentEnabled(chatConfig);
|
|
@@ -256,6 +263,10 @@ export const closeChatStateCleanUp = dispatch => {
|
|
|
256
263
|
payload: undefined
|
|
257
264
|
});
|
|
258
265
|
// dispatch({ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE, payload: ConversationState.Closed });
|
|
266
|
+
dispatch({
|
|
267
|
+
type: LiveChatWidgetActionType.SET_CONVERSATIONAL_SURVEY_DISPLAY,
|
|
268
|
+
payload: false
|
|
269
|
+
});
|
|
259
270
|
dispatch({
|
|
260
271
|
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
261
272
|
payload: undefined
|
|
@@ -32,6 +32,11 @@ import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller
|
|
|
32
32
|
import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
|
|
33
33
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
34
34
|
import { Constants } from "../../../common/Constants";
|
|
35
|
+
import createCustomEventMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/customEventMiddleware";
|
|
36
|
+
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
37
|
+
import { executeReducer } from "../../../contexts/createReducer";
|
|
38
|
+
import { createQueueOverflowMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware";
|
|
39
|
+
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
35
40
|
|
|
36
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
42
|
export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endChat) => {
|
|
@@ -53,6 +58,20 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
53
58
|
let webChatStore = WebChatStoreLoader.store;
|
|
54
59
|
if (!webChatStore) {
|
|
55
60
|
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain7;
|
|
61
|
+
const addConversationalSurveyTagsCallback = action => {
|
|
62
|
+
var _inMemoryState$appSta;
|
|
63
|
+
const inMemoryState = executeReducer(state, {
|
|
64
|
+
type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
65
|
+
payload: null
|
|
66
|
+
});
|
|
67
|
+
const isConversationalSurvey = (_inMemoryState$appSta = inMemoryState.appStates) === null || _inMemoryState$appSta === void 0 ? void 0 : _inMemoryState$appSta.isConversationalSurvey;
|
|
68
|
+
if (isConversationalSurvey) {
|
|
69
|
+
if (!action.payload.activity.channelData.tags.includes(Constants.c2ConversationalSurveyMessageTag)) {
|
|
70
|
+
action.payload.activity.channelData.tags.push(Constants.c2ConversationalSurveyMessageTag);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return action;
|
|
74
|
+
};
|
|
56
75
|
const conversationEndCallback = async () => {
|
|
57
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
77
|
const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
|
|
@@ -82,9 +101,21 @@ export const initWebChatComposer = (props, state, dispatch, facadeChatSDK, endCh
|
|
|
82
101
|
});
|
|
83
102
|
}
|
|
84
103
|
};
|
|
104
|
+
const startConversationalSurveyCallback = async () => {
|
|
105
|
+
dispatch({
|
|
106
|
+
type: LiveChatWidgetActionType.SET_CONVERSATIONAL_SURVEY_DISPLAY,
|
|
107
|
+
payload: true
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
const endConversationalSurveyCallback = async () => {
|
|
111
|
+
dispatch({
|
|
112
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
113
|
+
payload: ConversationState.InActive
|
|
114
|
+
});
|
|
115
|
+
};
|
|
85
116
|
webChatStore = createStore({},
|
|
86
117
|
//initial state
|
|
87
|
-
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, createMessageSequenceIdOverrideMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware(honorsTargetInHTMLLinks), createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware,
|
|
118
|
+
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), createCustomEventMiddleware(BroadcastService), createQueueOverflowMiddleware(state, dispatch), channelDataMiddleware(addConversationalSurveyTagsCallback), createConversationEndMiddleware(conversationEndCallback, startConversationalSurveyCallback, endConversationalSurveyCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, createMessageSequenceIdOverrideMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware(honorsTargetInHTMLLinks), createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware,
|
|
88
119
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
120
|
...(((_props$webChatContain7 = props.webChatContainerProps) === null || _props$webChatContain7 === void 0 ? void 0 : _props$webChatContain7.storeMiddlewares) ?? []));
|
|
90
121
|
WebChatStoreLoader.store = webChatStore;
|
|
@@ -6,6 +6,22 @@ export const isPostChatSurveyEnabled = async facadeChatSDK => {
|
|
|
6
6
|
const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
|
|
7
7
|
return postChatEnabled === "true";
|
|
8
8
|
};
|
|
9
|
+
export const getPostChatSurveyConfig = async facadeChatSDK => {
|
|
10
|
+
var _chatConfig$LiveWSAnd2, _chatConfig$LiveWSAnd3, _chatConfig$LiveWSAnd4, _chatConfig$LiveWSAnd5, _chatConfig$LiveWSAnd6, _chatConfig$LiveWSAnd7, _chatConfig$LiveWSAnd8, _chatConfig$LiveWSAnd9, _chatConfig$LiveWSAnd10;
|
|
11
|
+
const chatConfig = await facadeChatSDK.getLiveChatConfig();
|
|
12
|
+
const postChatEnabled = (_chatConfig$LiveWSAnd2 = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd2 === void 0 ? void 0 : _chatConfig$LiveWSAnd2.msdyn_postconversationsurveyenable.toString().toLowerCase();
|
|
13
|
+
const agentSurveyMode = (_chatConfig$LiveWSAnd3 = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd3 === void 0 ? void 0 : (_chatConfig$LiveWSAnd4 = _chatConfig$LiveWSAnd3.msdyn_postconversationsurveymode) === null || _chatConfig$LiveWSAnd4 === void 0 ? void 0 : _chatConfig$LiveWSAnd4.toString();
|
|
14
|
+
const botSurveyMode = (_chatConfig$LiveWSAnd5 = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd5 === void 0 ? void 0 : (_chatConfig$LiveWSAnd6 = _chatConfig$LiveWSAnd5.msdyn_postconversationsurveybotsurveymode) === null || _chatConfig$LiveWSAnd6 === void 0 ? void 0 : _chatConfig$LiveWSAnd6.toString();
|
|
15
|
+
const surveyProvider = (_chatConfig$LiveWSAnd7 = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd7 === void 0 ? void 0 : (_chatConfig$LiveWSAnd8 = _chatConfig$LiveWSAnd7.msdyn_surveyprovider) === null || _chatConfig$LiveWSAnd8 === void 0 ? void 0 : _chatConfig$LiveWSAnd8.toString();
|
|
16
|
+
const isConversationalSurveyEnabled = (_chatConfig$LiveWSAnd9 = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd9 === void 0 ? void 0 : (_chatConfig$LiveWSAnd10 = _chatConfig$LiveWSAnd9.msdyn_isConversationalPostChatSurveyEnabled) === null || _chatConfig$LiveWSAnd10 === void 0 ? void 0 : _chatConfig$LiveWSAnd10.toString().toLowerCase();
|
|
17
|
+
return {
|
|
18
|
+
postChatEnabled: postChatEnabled === "true",
|
|
19
|
+
agentSurveyMode: agentSurveyMode,
|
|
20
|
+
botSurveyMode: botSurveyMode,
|
|
21
|
+
surveyProvider: surveyProvider,
|
|
22
|
+
isConversationalSurveyEnabled: isConversationalSurveyEnabled === "true"
|
|
23
|
+
};
|
|
24
|
+
};
|
|
9
25
|
export const isPersistentChatEnabled = conversationMode => {
|
|
10
26
|
if (isNullOrUndefined(conversationMode)) {
|
|
11
27
|
return false;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Constants, ParticipantType, PostChatSurveyTelemetryMessage } from "../../../common/Constants";
|
|
1
|
+
import { Constants, ParticipantType, PostChatSurveyTelemetryMessage, SurveyProvider } from "../../../common/Constants";
|
|
2
2
|
import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
3
3
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
5
|
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
6
6
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
7
|
import { addDelayInMs } from "../../../common/utils";
|
|
8
|
-
import {
|
|
8
|
+
import { getPostChatSurveyConfig } from "./liveChatConfigUtils";
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
11
|
let conversationDetails = undefined;
|
|
@@ -46,23 +46,34 @@ const setSurveyMode = async (props, participantType, state, dispatch) => {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
const renderSurvey = async (postChatContext, dispatch) => {
|
|
49
|
+
const renderSurvey = async (postChatContext, state, dispatch) => {
|
|
50
50
|
if (postChatSurveyMode === PostChatSurveyMode.Link) {
|
|
51
51
|
setWidgetStateToInactive(dispatch);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
55
|
-
await embedModePostChatWorkflow(postChatContext, dispatch);
|
|
55
|
+
await embedModePostChatWorkflow(postChatContext, state, dispatch);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// Function for embed mode postchat workflow which is essentially same for both customer and agent
|
|
60
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
const embedModePostChatWorkflow = async (postChatContext, dispatch) => {
|
|
61
|
+
const embedModePostChatWorkflow = async (postChatContext, state, dispatch) => {
|
|
62
62
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
63
63
|
Event: TelemetryEvent.EmbedModePostChatWorkflowStarted
|
|
64
64
|
});
|
|
65
65
|
if (postChatContext) {
|
|
66
|
+
if (postChatContext.isConversationalSurveyEnabled && postChatContext.surveyProvider === SurveyProvider.MicrosoftCopilotStudio) {
|
|
67
|
+
dispatch({
|
|
68
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
69
|
+
payload: ConversationState.Postchat
|
|
70
|
+
});
|
|
71
|
+
dispatch({
|
|
72
|
+
type: LiveChatWidgetActionType.SET_CONVERSATIONAL_SURVEY_DISPLAY,
|
|
73
|
+
payload: true
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
66
77
|
dispatch({
|
|
67
78
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
68
79
|
payload: ConversationState.PostchatLoading
|
|
@@ -89,7 +100,7 @@ const initiatePostChat = async (props, conversationDetailsParam, state, dispatch
|
|
|
89
100
|
conversationDetails = conversationDetailsParam;
|
|
90
101
|
const participantType = ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.participantType) ?? postchatContext.participantType;
|
|
91
102
|
await setSurveyMode(props, participantType, state, dispatch);
|
|
92
|
-
await renderSurvey(postchatContext, dispatch);
|
|
103
|
+
await renderSurvey(postchatContext, state, dispatch);
|
|
93
104
|
};
|
|
94
105
|
|
|
95
106
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -102,7 +113,14 @@ const isPostChatEnabled = (props, state) => {
|
|
|
102
113
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
114
|
const getPostChatContext = async (facadeChatSDK, state, dispatch) => {
|
|
104
115
|
try {
|
|
105
|
-
const
|
|
116
|
+
const postChatConfig = await getPostChatSurveyConfig(facadeChatSDK);
|
|
117
|
+
const postChatEnabled = postChatConfig.postChatEnabled;
|
|
118
|
+
if (postChatConfig.isConversationalSurveyEnabled) {
|
|
119
|
+
dispatch({
|
|
120
|
+
type: LiveChatWidgetActionType.SET_CONVERSATIONAL_SURVEY_ENABLED,
|
|
121
|
+
payload: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
106
124
|
if (postChatEnabled) {
|
|
107
125
|
var _state$domainStates2;
|
|
108
126
|
if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
|
|
@@ -112,11 +130,17 @@ const getPostChatContext = async (facadeChatSDK, state, dispatch) => {
|
|
|
112
130
|
Event: TelemetryEvent.PostChatContextCallSucceed,
|
|
113
131
|
Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
|
|
114
132
|
});
|
|
133
|
+
|
|
134
|
+
// Merge postChatConfig with postChatSurveyContext
|
|
135
|
+
const mergedContext = {
|
|
136
|
+
...context,
|
|
137
|
+
...postChatConfig
|
|
138
|
+
};
|
|
115
139
|
dispatch({
|
|
116
140
|
type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
|
|
117
|
-
payload:
|
|
141
|
+
payload: mergedContext
|
|
118
142
|
});
|
|
119
|
-
return
|
|
143
|
+
return mergedContext;
|
|
120
144
|
}
|
|
121
145
|
}
|
|
122
146
|
} catch (error) {
|
|
@@ -4,12 +4,19 @@ import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
|
4
4
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
5
5
|
import { PostChatSurveyTelemetryMessage } from "../../../common/Constants";
|
|
6
6
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
-
import {
|
|
7
|
+
import { getPostChatSurveyConfig } from "./liveChatConfigUtils";
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
export const setPostChatContextAndLoadSurvey = async (facadeChatSDK, dispatch, persistedChat) => {
|
|
11
11
|
try {
|
|
12
|
-
const
|
|
12
|
+
const postChatConfig = await getPostChatSurveyConfig(facadeChatSDK);
|
|
13
|
+
if (postChatConfig.isConversationalSurveyEnabled) {
|
|
14
|
+
dispatch({
|
|
15
|
+
type: LiveChatWidgetActionType.SET_CONVERSATIONAL_SURVEY_ENABLED,
|
|
16
|
+
payload: true
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const postChatEnabled = postChatConfig.postChatEnabled;
|
|
13
20
|
if (postChatEnabled) {
|
|
14
21
|
if (!persistedChat) {
|
|
15
22
|
TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
|
|
@@ -22,9 +29,15 @@ export const setPostChatContextAndLoadSurvey = async (facadeChatSDK, dispatch, p
|
|
|
22
29
|
Event: TelemetryEvent.PostChatContextCallSucceed,
|
|
23
30
|
Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
|
|
24
31
|
});
|
|
32
|
+
|
|
33
|
+
// Merge postChatConfig with postChatSurveyContext
|
|
34
|
+
const mergedContext = {
|
|
35
|
+
...context,
|
|
36
|
+
...postChatConfig
|
|
37
|
+
};
|
|
25
38
|
dispatch({
|
|
26
39
|
type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
|
|
27
|
-
payload:
|
|
40
|
+
payload: mergedContext
|
|
28
41
|
});
|
|
29
42
|
}
|
|
30
43
|
}
|
|
@@ -148,7 +148,6 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
|
|
|
148
148
|
const optionalParams = {
|
|
149
149
|
isProactiveChat
|
|
150
150
|
};
|
|
151
|
-
createTrackingForFirstMessage();
|
|
152
151
|
await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
|
|
153
152
|
};
|
|
154
153
|
|
|
@@ -197,8 +196,12 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
|
|
|
197
196
|
portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
|
|
198
197
|
};
|
|
199
198
|
const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
|
|
199
|
+
// startTime is used to determine if a message is history or new, better to be set before creating the adapter to get bandwidth
|
|
200
|
+
const startTime = new Date().getTime();
|
|
201
|
+
createTrackingForFirstMessage();
|
|
200
202
|
await facadeChatSDK.startChat(startChatOptionalParams);
|
|
201
203
|
isStartChatSuccessful = true;
|
|
204
|
+
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, startTime, props);
|
|
202
205
|
} catch (error) {
|
|
203
206
|
checkContactIdError(error);
|
|
204
207
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
@@ -216,7 +219,6 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
|
|
|
216
219
|
isStartChatSuccessful = false;
|
|
217
220
|
throw error;
|
|
218
221
|
}
|
|
219
|
-
await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
|
|
220
222
|
|
|
221
223
|
// Set app state to Active
|
|
222
224
|
if (isStartChatSuccessful) {
|
|
@@ -266,7 +268,7 @@ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props,
|
|
|
266
268
|
};
|
|
267
269
|
|
|
268
270
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
|
-
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
|
|
271
|
+
const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, startTime, props) => {
|
|
270
272
|
// New adapter creation
|
|
271
273
|
const newAdapter = await createAdapter(facadeChatSDK, props);
|
|
272
274
|
setAdapter(newAdapter);
|
|
@@ -277,7 +279,7 @@ const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, pr
|
|
|
277
279
|
});
|
|
278
280
|
if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
|
|
279
281
|
var _newAdapter$activity$;
|
|
280
|
-
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken.chatId, chatToken.visitorId));
|
|
282
|
+
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken.chatId, chatToken.visitorId, startTime));
|
|
281
283
|
}
|
|
282
284
|
};
|
|
283
285
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -53,6 +53,7 @@ import { startProactiveChat } from "../common/startProactiveChat";
|
|
|
53
53
|
import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
54
54
|
import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
55
55
|
import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
|
|
56
|
+
import { customEventCallback, subscribeToSendCustomEvent } from "../common/customEventHandler";
|
|
56
57
|
let uiTimer;
|
|
57
58
|
export const LiveChatWidgetStateful = props => {
|
|
58
59
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$styleProps, _props$webChatContain10, _props$webChatContain11, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain15, _state$appStates14, _props$webChatContain17, _props$webChatContain18, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
|
|
@@ -413,7 +414,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
413
414
|
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(msg => {
|
|
414
415
|
var _msg$payload5, _msg$payload6, _msg$payload7, _msg$payload9, _inMemoryState$appSta2, _inMemoryState$appSta3, _inMemoryState$appSta4;
|
|
415
416
|
// If chat is out of operating hours chat widget sets the conversation state to OutOfOffice.
|
|
416
|
-
if (state.appStates.outsideOperatingHours
|
|
417
|
+
if (state.appStates.outsideOperatingHours && state.appStates.conversationState !== ConversationState.Active) {
|
|
417
418
|
dispatch({
|
|
418
419
|
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
419
420
|
payload: false
|
|
@@ -580,6 +581,9 @@ export const LiveChatWidgetStateful = props => {
|
|
|
580
581
|
}
|
|
581
582
|
});
|
|
582
583
|
|
|
584
|
+
// subscribe custom event
|
|
585
|
+
subscribeToSendCustomEvent(BroadcastService, facadeChatSDK, customEventCallback);
|
|
586
|
+
|
|
583
587
|
// Check for TPC and log in telemetry if blocked
|
|
584
588
|
isCookieAllowed();
|
|
585
589
|
return () => {
|
|
@@ -611,12 +615,15 @@ export const LiveChatWidgetStateful = props => {
|
|
|
611
615
|
payload: null
|
|
612
616
|
});
|
|
613
617
|
if ("participantsRemoved" in event && (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta5 = inMemoryState.appStates) === null || _inMemoryState$appSta5 === void 0 ? void 0 : _inMemoryState$appSta5.conversationState) === ConversationState.Active) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
618
|
+
var _inMemoryState$appSta6;
|
|
619
|
+
if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta6 = inMemoryState.appStates) === null || _inMemoryState$appSta6 === void 0 ? void 0 : _inMemoryState$appSta6.isConversationalSurveyEnabled) === false) {
|
|
620
|
+
setWebChatStyles(styles => {
|
|
621
|
+
return {
|
|
622
|
+
...styles,
|
|
623
|
+
hideSendBox: true
|
|
624
|
+
};
|
|
625
|
+
});
|
|
626
|
+
}
|
|
620
627
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
621
628
|
Event: TelemetryEvent.ParticipantsRemovedEvent,
|
|
622
629
|
Description: "Participants removed event received."
|
|
@@ -712,7 +719,15 @@ export const LiveChatWidgetStateful = props => {
|
|
|
712
719
|
endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
|
|
713
720
|
return;
|
|
714
721
|
}
|
|
715
|
-
|
|
722
|
+
const inMemoryState = executeReducer(state, {
|
|
723
|
+
type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
724
|
+
payload: null
|
|
725
|
+
});
|
|
726
|
+
let isConversationalSurveyEnabled = state.appStates.isConversationalSurveyEnabled;
|
|
727
|
+
|
|
728
|
+
// In conversational survey, we need to check post chat survey logics before we set ConversationState to InActive
|
|
729
|
+
// Hence setting ConversationState to InActive will be done later in the post chat flows
|
|
730
|
+
if (!isConversationalSurveyEnabled && ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === ConversationEndEntity.Bot)) {
|
|
716
731
|
dispatch({
|
|
717
732
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
718
733
|
payload: ConversationState.InActive
|
|
@@ -753,13 +768,13 @@ export const LiveChatWidgetStateful = props => {
|
|
|
753
768
|
|
|
754
769
|
// Handle Chat disconnect cases
|
|
755
770
|
useEffect(() => {
|
|
756
|
-
var _inMemoryState$
|
|
771
|
+
var _inMemoryState$appSta7;
|
|
757
772
|
const inMemoryState = executeReducer(state, {
|
|
758
773
|
type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
|
|
759
774
|
payload: null
|
|
760
775
|
});
|
|
761
776
|
handleChatDisconnect(props, inMemoryState, setWebChatStyles);
|
|
762
|
-
const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$
|
|
777
|
+
const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta7 = inMemoryState.appStates) === null || _inMemoryState$appSta7 === void 0 ? void 0 : _inMemoryState$appSta7.chatDisconnectEventReceived;
|
|
763
778
|
if (chatDisconnectState && adapter) {
|
|
764
779
|
try {
|
|
765
780
|
adapter.end();
|
|
@@ -887,8 +902,8 @@ export const LiveChatWidgetStateful = props => {
|
|
|
887
902
|
margin-left: .25em;
|
|
888
903
|
}
|
|
889
904
|
${(sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight) && `
|
|
890
|
-
textarea.webchat__send-box-text-
|
|
891
|
-
min-height: ${sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight};
|
|
905
|
+
.webchat__auto-resize-textarea.webchat__send-box-text-box__text-area {
|
|
906
|
+
min-height: ${sendBoxTextArea === null || sendBoxTextArea === void 0 ? void 0 : sendBoxTextArea.minHeight} !important;
|
|
892
907
|
}`}
|
|
893
908
|
`), /*#__PURE__*/React.createElement(DraggableChatWidget, chatWidgetDraggableConfig, /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
894
909
|
userID: userID,
|
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
import { Constants } from "../../../../../common/Constants";
|
|
8
8
|
import { DeliveryMode } from "@microsoft/omnichannel-chat-sdk";
|
|
9
9
|
import { WebChatActionType } from "../../enums/WebChatActionType";
|
|
10
|
-
|
|
11
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
12
|
-
const channelDataMiddleware = _ref => {
|
|
11
|
+
const channelDataMiddleware = addConversationalSurveyTagsCallback => _ref => {
|
|
13
12
|
let {
|
|
14
13
|
dispatch
|
|
15
14
|
} = _ref;
|
|
16
15
|
return next => action => {
|
|
17
|
-
var _action$payload,
|
|
18
|
-
if ((action === null ||
|
|
16
|
+
var _action, _action2, _action2$payload, _action2$payload$acti;
|
|
17
|
+
if (((_action = action) === null || _action === void 0 ? void 0 : _action.type) === WebChatActionType.DIRECT_LINE_POST_ACTIVITY_PENDING && (_action2 = action) !== null && _action2 !== void 0 && (_action2$payload = _action2.payload) !== null && _action2$payload !== void 0 && (_action2$payload$acti = _action2$payload.activity) !== null && _action2$payload$acti !== void 0 && _action2$payload$acti.channelData) {
|
|
19
18
|
const channelIdTag = `${Constants.channelIdKey}${Constants.ChannelId}`;
|
|
20
19
|
const customerMessageTag = `${Constants.CustomerTag}`;
|
|
21
20
|
if (action.payload.activity.channelData.tags) {
|
|
@@ -29,6 +28,7 @@ const channelDataMiddleware = _ref => {
|
|
|
29
28
|
action.payload.activity.channelData.tags = [channelIdTag];
|
|
30
29
|
action.payload.activity.channelData.tags.push(customerMessageTag);
|
|
31
30
|
}
|
|
31
|
+
action = addConversationalSurveyTagsCallback(action);
|
|
32
32
|
action.payload.activity.channelData.metadata = {
|
|
33
33
|
deliveryMode: DeliveryMode.Bridged
|
|
34
34
|
};
|