@microsoft/omnichannel-chat-widget 0.1.0-main.ceb1702 → 0.1.0-main.d4c1f9e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/common/Constants.js +4 -0
- package/lib/cjs/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/cjs/common/utils.js +64 -5
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/authHelper.js +52 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +8 -3
- package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +12 -0
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +55 -35
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +131 -80
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +153 -110
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/cjs/contexts/createReducer.js +8 -0
- package/lib/cjs/controller/componentController.js +2 -2
- package/lib/esm/common/Constants.js +4 -0
- package/lib/esm/common/telemetry/TelemetryConstants.js +6 -0
- package/lib/esm/common/utils.js +48 -3
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
- package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/authHelper.js +39 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +8 -3
- package/lib/esm/components/livechatwidget/common/endChat.js +53 -21
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -2
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +56 -37
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +127 -80
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +153 -112
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +10 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
- package/lib/esm/contexts/createReducer.js +8 -0
- package/lib/esm/controller/componentController.js +2 -2
- package/lib/types/common/Constants.d.ts +2 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
- package/lib/types/common/utils.d.ts +7 -3
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +4 -0
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -3
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
- package/package.json +4 -3
|
@@ -7,21 +7,38 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
|
|
|
7
7
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
8
8
|
import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
|
|
9
9
|
import { Constants } from "../../../common/Constants";
|
|
10
|
-
import { getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
11
|
|
|
12
12
|
const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
|
|
13
|
-
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
|
|
13
|
+
var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
|
|
14
14
|
|
|
15
15
|
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;
|
|
16
|
-
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;
|
|
17
|
-
const conversationDetails = await chatSDK.getConversationDetails();
|
|
16
|
+
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; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
let conversationDetails = undefined;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
conversationDetails = await chatSDK.getConversationDetails();
|
|
22
|
+
} catch (erorr) {
|
|
23
|
+
TelemetryHelper.logActionEvent(LogLevel.ERROR, {
|
|
24
|
+
Event: TelemetryEvent.GetConversationDetailsException,
|
|
25
|
+
ExceptionDetails: {
|
|
26
|
+
exception: `Failed to get conversation details: ${erorr}`
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
|
|
20
32
|
const skipEndChatSDK = false;
|
|
21
33
|
const skipCloseChat = true;
|
|
22
|
-
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat,
|
|
34
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
|
|
23
35
|
|
|
24
36
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
37
|
+
dispatch({
|
|
38
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
39
|
+
payload: ConversationState.PostchatLoading
|
|
40
|
+
});
|
|
41
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
25
42
|
const loadPostChatEvent = {
|
|
26
43
|
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
27
44
|
};
|
|
@@ -32,9 +49,11 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
|
|
|
32
49
|
payload: ConversationState.InActive
|
|
33
50
|
});
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
|
|
53
|
+
return;
|
|
37
54
|
}
|
|
55
|
+
|
|
56
|
+
await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
|
|
38
57
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
58
|
|
|
40
59
|
|
|
@@ -44,16 +63,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
44
63
|
TelemetryHelper.logSDKEvent(LogLevel.INFO, {
|
|
45
64
|
Event: TelemetryEvent.EndChatSDKCall
|
|
46
65
|
});
|
|
47
|
-
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
|
|
48
|
-
|
|
49
|
-
dispatch({
|
|
50
|
-
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
51
|
-
payload: undefined
|
|
52
|
-
});
|
|
53
|
-
dispatch({
|
|
54
|
-
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
55
|
-
payload: undefined
|
|
56
|
-
});
|
|
66
|
+
await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
|
|
57
67
|
} catch (ex) {
|
|
58
68
|
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
59
69
|
Event: TelemetryEvent.EndChatSDKCallFailed,
|
|
@@ -63,7 +73,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
63
73
|
});
|
|
64
74
|
postMessageToOtherTab = false;
|
|
65
75
|
}
|
|
66
|
-
}
|
|
76
|
+
} // Need to clear these states immediately when chat ended from OC.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
dispatch({
|
|
80
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
81
|
+
payload: undefined
|
|
82
|
+
});
|
|
83
|
+
dispatch({
|
|
84
|
+
type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
85
|
+
payload: undefined
|
|
86
|
+
});
|
|
87
|
+
dispatch({
|
|
88
|
+
type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
89
|
+
payload: undefined
|
|
90
|
+
});
|
|
67
91
|
|
|
68
92
|
if (!skipCloseChat) {
|
|
69
93
|
try {
|
|
@@ -95,11 +119,19 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
|
|
|
95
119
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
96
120
|
payload: 0
|
|
97
121
|
});
|
|
122
|
+
dispatch({
|
|
123
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
124
|
+
payload: {
|
|
125
|
+
proactiveChatBodyTitle: "",
|
|
126
|
+
proactiveChatEnablePrechat: false,
|
|
127
|
+
proactiveChatInNewWindow: false
|
|
128
|
+
}
|
|
129
|
+
});
|
|
98
130
|
|
|
99
131
|
if (postMessageToOtherTab) {
|
|
100
|
-
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
|
|
132
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps;
|
|
101
133
|
|
|
102
|
-
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
|
|
134
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
|
|
103
135
|
BroadcastService.postMessage({
|
|
104
136
|
eventName: endChatEventName
|
|
105
137
|
});
|
|
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
|
|
|
7
7
|
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
8
8
|
import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
|
|
9
9
|
import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
|
|
10
|
-
import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
|
|
10
|
+
import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
|
|
11
11
|
import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
|
|
12
12
|
import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
|
|
13
13
|
import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
|
|
@@ -28,7 +28,8 @@ import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller
|
|
|
28
28
|
import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
|
|
29
29
|
import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
|
|
30
30
|
import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
|
|
31
|
-
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
31
|
+
import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
|
|
32
|
+
import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
33
|
|
|
33
34
|
export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
|
|
34
35
|
var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _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;
|
|
@@ -65,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
65
66
|
|
|
66
67
|
if (isPostChatEnabled === "true") {
|
|
67
68
|
if (postChatSurveyMode === PostChatSurveyMode.Embed) {
|
|
69
|
+
WebChatStoreLoader.store = null;
|
|
70
|
+
dispatch({
|
|
71
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
72
|
+
payload: ConversationState.PostchatLoading
|
|
73
|
+
});
|
|
74
|
+
await addDelayInMs(Constants.PostChatLoadingDurationInMs);
|
|
68
75
|
const loadPostChatEvent = {
|
|
69
76
|
eventName: BroadcastEvent.LoadPostChatSurvey
|
|
70
77
|
};
|
|
@@ -76,6 +83,10 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
|
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
} else {
|
|
86
|
+
dispatch({
|
|
87
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
88
|
+
payload: ConversationState.InActive
|
|
89
|
+
});
|
|
79
90
|
dispatch({
|
|
80
91
|
type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
|
|
81
92
|
payload: true
|
|
@@ -3,25 +3,34 @@ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/teleme
|
|
|
3
3
|
import { BroadcastService } from "@microsoft/omnichannel-chat-components";
|
|
4
4
|
import { ConversationState } from "../../../contexts/common/ConversationState";
|
|
5
5
|
import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
|
|
6
|
-
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
|
|
7
|
+
import { handleAuthentication, removeAuthTokenProvider } from "./authHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
|
|
9
|
+
const getChatReconnectContext = async (chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId) => {
|
|
10
|
+
if (isReconnectEnabled) {
|
|
11
|
+
try {
|
|
12
|
+
if (reconnectId) {
|
|
13
|
+
const chatReconnectOptionalParams = {
|
|
14
|
+
reconnectId: reconnectId
|
|
15
|
+
};
|
|
16
|
+
return await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
|
|
17
|
+
} else {
|
|
18
|
+
// set auth token to chat sdk to get reconnectId for auth chat
|
|
19
|
+
await handleAuthentication(chatSDK, chatConfig, getAuthToken);
|
|
20
|
+
const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext()); // remove auth token after reconnectId is fetched
|
|
21
|
+
// this will be reset later at start chat
|
|
22
|
+
|
|
23
|
+
removeAuthTokenProvider(chatSDK);
|
|
24
|
+
return reconnectChatContext;
|
|
23
25
|
}
|
|
24
|
-
})
|
|
26
|
+
} catch (ex) {
|
|
27
|
+
TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
|
|
28
|
+
Event: TelemetryEvent.GetChatReconnectContextSDKCallFailed,
|
|
29
|
+
ExceptionDetails: {
|
|
30
|
+
exception: ex
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
return null;
|
|
@@ -29,13 +38,23 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
|
|
|
29
38
|
|
|
30
39
|
|
|
31
40
|
const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
32
|
-
var _props$
|
|
41
|
+
var _props$chatConfig, _props$reconnectChatP;
|
|
42
|
+
|
|
43
|
+
let authClientFunction = undefined;
|
|
33
44
|
|
|
34
|
-
if ((_props$
|
|
45
|
+
if ((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) {
|
|
46
|
+
var _props$chatConfig2, _props$chatConfig2$Li;
|
|
47
|
+
|
|
48
|
+
authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction // TODO: Implement this after storage is in place
|
|
35
52
|
|
|
36
53
|
/* && !isLoadWithState() */
|
|
37
54
|
) {
|
|
38
|
-
|
|
55
|
+
var _props$reconnectChatP2;
|
|
56
|
+
|
|
57
|
+
const previousActiveSessionResponse = await getChatReconnectContext(chatSDK, props.chatConfig, props.getAuthToken, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled);
|
|
39
58
|
|
|
40
59
|
if (previousActiveSessionResponse && previousActiveSessionResponse.reconnectId) {
|
|
41
60
|
return previousActiveSessionResponse.reconnectId;
|
|
@@ -46,27 +65,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
|
|
|
46
65
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
66
|
|
|
48
67
|
|
|
49
|
-
const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
50
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
68
|
+
const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat, redirectInSameWindow) => {
|
|
69
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
51
70
|
|
|
52
71
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
53
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
72
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
54
73
|
} else {
|
|
55
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
74
|
+
await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
|
|
56
75
|
}
|
|
57
76
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
77
|
|
|
59
78
|
|
|
60
|
-
const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
61
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
79
|
+
const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isReconnectEnabled, reconnectId, initStartChat) => {
|
|
80
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
62
81
|
|
|
63
82
|
if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
64
|
-
await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
|
|
83
|
+
await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
|
|
65
84
|
}
|
|
66
85
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
86
|
|
|
68
87
|
|
|
69
|
-
const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
88
|
+
const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
|
|
70
89
|
const startUnauthenticatedReconnectChat = {
|
|
71
90
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
72
91
|
};
|
|
@@ -82,7 +101,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
|
|
|
82
101
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
83
102
|
payload: ConversationState.Loading
|
|
84
103
|
});
|
|
85
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
104
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, optionalParams);
|
|
86
105
|
};
|
|
87
106
|
|
|
88
107
|
const redirectPage = (redirectURL, redirectInSameWindow) => {
|
|
@@ -104,7 +123,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
|
|
|
104
123
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
124
|
|
|
106
125
|
|
|
107
|
-
const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
|
|
126
|
+
const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
|
|
108
127
|
const startUnauthenticatedReconnectChat = {
|
|
109
128
|
eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
|
|
110
129
|
};
|
|
@@ -127,25 +146,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
|
|
|
127
146
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
128
147
|
payload: ConversationState.Loading
|
|
129
148
|
});
|
|
130
|
-
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
149
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
131
150
|
}
|
|
132
151
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
152
|
|
|
134
153
|
|
|
135
|
-
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
|
|
136
|
-
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
|
|
154
|
+
const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, isReconnectEnabled, reconnectId, redirectInSameWindow) => {
|
|
155
|
+
const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, chatConfig, getAuthToken, isReconnectEnabled, reconnectId);
|
|
137
156
|
|
|
138
157
|
if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
|
|
139
|
-
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
158
|
+
await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
|
|
140
159
|
}
|
|
141
160
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
161
|
|
|
143
162
|
|
|
144
|
-
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
163
|
+
const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
|
|
145
164
|
if (reconnectAvailabilityResponse.redirectURL) {
|
|
146
165
|
redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
|
|
147
166
|
} else {
|
|
148
|
-
await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
|
|
167
|
+
await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
|
|
149
168
|
}
|
|
150
169
|
};
|
|
151
170
|
|
|
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
|
|
32
|
-
dispatch({
|
|
33
|
-
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
34
|
-
payload: ConversationState.Loading
|
|
35
|
-
});
|
|
36
32
|
dispatch({
|
|
37
33
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
38
34
|
payload: ConversationState.Postchat
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export function shareObservable(observable) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
|
|
6
|
+
let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
|
|
8
|
+
return new window.Observable(observer => {
|
|
9
|
+
if (!subscription) {
|
|
10
|
+
subscription = observable.subscribe({
|
|
11
|
+
complete() {
|
|
12
|
+
observers.forEach(observer => observer.complete());
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
error(err) {
|
|
17
|
+
observers.forEach(observer => observer.error(err));
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
next(value) {
|
|
22
|
+
observers.forEach(observer => observer.next(value));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
observers.push(observer);
|
|
29
|
+
return () => {
|
|
30
|
+
observers = observers.filter(o => o !== observer);
|
|
31
|
+
|
|
32
|
+
if (!observers.length) {
|
|
33
|
+
subscription.unsubscribe();
|
|
34
|
+
subscription = null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|