@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.c9a643a
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 +35 -11
- package/lib/cjs/common/Constants.js +50 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +42 -3
- package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
- package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
- package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +89 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -40
- package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -10
- 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 +65 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +19 -17
- package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +144 -39
- package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
- 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 +166 -50
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +284 -71
- package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +91 -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/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
- package/lib/cjs/contexts/createReducer.js +24 -10
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +46 -5
- package/lib/esm/common/telemetry/TelemetryConstants.js +42 -3
- package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
- package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
- package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +64 -1
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -38
- package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/headerstateful/HeaderStateful.js +5 -10
- 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 +50 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +19 -18
- package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +25 -5
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +134 -41
- package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
- 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 +161 -53
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +272 -76
- package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +82 -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/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
- package/lib/esm/contexts/createReducer.js +24 -9
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +25 -2
- package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +34 -5
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
- package/lib/types/common/utils.d.ts +8 -1
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
- package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
- 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 +5 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -1
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -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/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +3 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -8
- package/package.json +8 -8
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.registerTelemetryLoggers = void 0;
|
|
7
7
|
|
|
8
|
-
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
9
|
-
|
|
10
8
|
var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
|
|
11
9
|
|
|
10
|
+
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
11
|
+
|
|
12
12
|
var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
|
|
13
13
|
|
|
14
14
|
var _defaultAriaConfig = require("../../../common/telemetry/defaultConfigs/defaultAriaConfig");
|
|
@@ -17,21 +17,9 @@ var _defaultTelemetryInternalData = require("../../../common/telemetry/defaultCo
|
|
|
17
17
|
|
|
18
18
|
var _defaultTelemetryConfiguration = require("../../../common/telemetry/defaultConfigs/defaultTelemetryConfiguration");
|
|
19
19
|
|
|
20
|
-
var _package = require("@microsoft/omnichannel-chat-components/package.json");
|
|
21
|
-
|
|
22
|
-
var _package2 = require("@microsoft/omnichannel-chat-sdk/package.json");
|
|
23
|
-
|
|
24
20
|
const registerTelemetryLoggers = (props, dispatch) => {
|
|
25
21
|
var _props$liveChatContex, _props$liveChatContex2;
|
|
26
22
|
|
|
27
|
-
let widgetPackageInfo;
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
widgetPackageInfo = require("@microsoft/omnichannel-chat-widget/package.json");
|
|
31
|
-
} catch (error) {
|
|
32
|
-
widgetPackageInfo = "0.0.0-0";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
23
|
const telemetryConfig = { ..._defaultTelemetryConfiguration.defaultTelemetryConfiguration,
|
|
36
24
|
...props.telemetryConfig
|
|
37
25
|
};
|
|
@@ -53,12 +41,13 @@ const registerTelemetryLoggers = (props, dispatch) => {
|
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
telemetryData = _TelemetryHelper.TelemetryHelper.addWidgetDataToTelemetry(telemetryConfig, telemetryData);
|
|
56
|
-
telemetryData.OCChatSDKVersion =
|
|
57
|
-
telemetryData.chatComponentVersion =
|
|
58
|
-
telemetryData.chatWidgetVersion =
|
|
44
|
+
telemetryData.OCChatSDKVersion = telemetryConfig.OCChatSDKVersion ?? "0.0.0-0";
|
|
45
|
+
telemetryData.chatComponentVersion = telemetryConfig.chatComponentVersion ?? "0.0.0-0";
|
|
46
|
+
telemetryData.chatWidgetVersion = telemetryConfig.chatWidgetVersion ?? "0.0.0-0";
|
|
59
47
|
telemetryData.orgId = (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId;
|
|
60
48
|
telemetryData.widgetId = (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId;
|
|
61
49
|
telemetryData.orgUrl = (_props$chatSDK3 = props.chatSDK) === null || _props$chatSDK3 === void 0 ? void 0 : (_props$chatSDK3$omnic = _props$chatSDK3.omnichannelConfig) === null || _props$chatSDK3$omnic === void 0 ? void 0 : _props$chatSDK3$omnic.orgUrl;
|
|
50
|
+
_TelemetryManager.TelemetryManager.InternalTelemetryData = telemetryData;
|
|
62
51
|
dispatch({
|
|
63
52
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA,
|
|
64
53
|
payload: telemetryData
|
|
@@ -43,10 +43,6 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
_omnichannelChatComponents.BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
|
|
46
|
-
dispatch({
|
|
47
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
48
|
-
payload: _ConversationState.ConversationState.Loading
|
|
49
|
-
});
|
|
50
46
|
dispatch({
|
|
51
47
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
52
48
|
payload: _ConversationState.ConversationState.Postchat
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shareObservable = shareObservable;
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
function shareObservable(observable) {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
|
|
13
|
+
let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
|
|
15
|
+
return new window.Observable(observer => {
|
|
16
|
+
if (!subscription) {
|
|
17
|
+
subscription = observable.subscribe({
|
|
18
|
+
complete() {
|
|
19
|
+
observers.forEach(observer => observer.complete());
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
error(err) {
|
|
24
|
+
observers.forEach(observer => observer.error(err));
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
next(value) {
|
|
29
|
+
observers.forEach(observer => observer.next(value));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
observers.push(observer);
|
|
36
|
+
return () => {
|
|
37
|
+
observers = observers.filter(o => o !== observer);
|
|
38
|
+
|
|
39
|
+
if (!observers.length) {
|
|
40
|
+
subscription.unsubscribe();
|
|
41
|
+
subscription = null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.prepareStartChat = exports.initStartChat = void 0;
|
|
6
|
+
exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = void 0;
|
|
7
7
|
|
|
8
8
|
var _Constants = require("../../../common/Constants");
|
|
9
9
|
|
|
@@ -11,8 +11,6 @@ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants"
|
|
|
11
11
|
|
|
12
12
|
var _ConversationState = require("../../../contexts/common/ConversationState");
|
|
13
13
|
|
|
14
|
-
var _DataStoreManager = require("../../../common/contextDataStore/DataStoreManager");
|
|
15
|
-
|
|
16
14
|
var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
|
|
17
15
|
|
|
18
16
|
var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
|
|
@@ -35,16 +33,36 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
|
|
|
35
33
|
|
|
36
34
|
var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
|
|
37
35
|
|
|
36
|
+
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
37
|
+
|
|
38
|
+
var _ActivityStreamHandler = require("./ActivityStreamHandler");
|
|
39
|
+
|
|
40
|
+
var _authHelper = require("./authHelper");
|
|
41
|
+
|
|
38
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
|
|
45
|
+
let widgetInstanceId; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
|
|
39
47
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
48
|
+
var _props$controlProps, _props$reconnectChatP;
|
|
49
|
+
|
|
50
|
+
optionalParams = {}; //Resetting to ensure no stale values
|
|
51
|
+
|
|
52
|
+
widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId; // Can connect to existing chat session
|
|
53
|
+
|
|
40
54
|
if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
|
|
41
55
|
return;
|
|
42
|
-
} //
|
|
56
|
+
} // Redirecting if unauthenticated reconnect chat expired
|
|
43
57
|
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
60
|
+
var _props$reconnectChatP2, _props$reconnectChatP3, _props$reconnectChatP4;
|
|
61
|
+
|
|
62
|
+
await (0, _reconnectChatHelper.handleRedirectUnauthenticatedReconnectChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.redirectInSameWindow);
|
|
63
|
+
return;
|
|
64
|
+
} // Getting reconnectId for authenticated chat
|
|
65
|
+
|
|
48
66
|
|
|
49
67
|
const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
|
|
50
68
|
|
|
@@ -57,7 +75,26 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
57
75
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
58
76
|
payload: _ConversationState.ConversationState.ReconnectChat
|
|
59
77
|
});
|
|
60
|
-
|
|
78
|
+
return;
|
|
79
|
+
} // Setting Proactive chat settings
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
|
|
83
|
+
const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
|
|
84
|
+
|
|
85
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
|
|
86
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
exports.prepareStartChat = prepareStartChat;
|
|
90
|
+
|
|
91
|
+
const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
|
|
92
|
+
// Getting prechat Survey Context
|
|
93
|
+
const parseToJson = false;
|
|
94
|
+
const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
|
|
95
|
+
const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
|
|
96
|
+
|
|
97
|
+
if (showPrechat) {
|
|
61
98
|
dispatch({
|
|
62
99
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
|
|
63
100
|
payload: preChatSurveyResponse
|
|
@@ -66,30 +103,62 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
66
103
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
67
104
|
payload: _ConversationState.ConversationState.Prechat
|
|
68
105
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
return;
|
|
107
|
+
} //Initiate start chat
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
dispatch({
|
|
111
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
112
|
+
payload: _ConversationState.ConversationState.Loading
|
|
113
|
+
});
|
|
114
|
+
await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
|
|
76
115
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
116
|
|
|
78
117
|
|
|
79
|
-
exports.
|
|
118
|
+
exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
|
|
80
119
|
|
|
81
|
-
const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
|
|
120
|
+
const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
|
|
82
121
|
try {
|
|
83
122
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
84
123
|
|
|
124
|
+
const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
|
|
125
|
+
|
|
126
|
+
if (getAuthToken && authClientFunction) {
|
|
127
|
+
// set auth token to chat sdk before start chat
|
|
128
|
+
const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
|
|
129
|
+
|
|
130
|
+
if (!authSuccess) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let isStartChatSuccessful = false; //Check if chat retrieved from cache
|
|
136
|
+
|
|
137
|
+
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
138
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
139
|
+
|
|
140
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
141
|
+
eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
|
|
142
|
+
payload: {
|
|
143
|
+
chatId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.liveChatContext) === null || _persistedState$domai2 === void 0 ? void 0 : (_persistedState$domai3 = _persistedState$domai2.chatToken) === null || _persistedState$domai3 === void 0 ? void 0 : _persistedState$domai3.chatId,
|
|
144
|
+
requestId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai4 = persistedState.domainStates) === null || _persistedState$domai4 === void 0 ? void 0 : (_persistedState$domai5 = _persistedState$domai4.liveChatContext) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.requestId
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
85
149
|
try {
|
|
150
|
+
//Start widget load timer
|
|
86
151
|
_TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
|
|
87
152
|
|
|
88
153
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
89
154
|
Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
|
|
90
|
-
});
|
|
155
|
+
}); // Set custom context params
|
|
156
|
+
|
|
91
157
|
|
|
92
|
-
|
|
158
|
+
setCustomContextParams(chatSDK);
|
|
159
|
+
optionalParams = Object.assign({}, params, optionalParams);
|
|
160
|
+
await chatSDK.startChat(optionalParams);
|
|
161
|
+
isStartChatSuccessful = true;
|
|
93
162
|
} catch (error) {
|
|
94
163
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
95
164
|
Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
|
|
@@ -97,43 +166,54 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
97
166
|
exception: `Failed to setup startChat: ${error}`
|
|
98
167
|
}
|
|
99
168
|
});
|
|
100
|
-
|
|
169
|
+
|
|
170
|
+
isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
|
|
171
|
+
// TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
|
|
172
|
+
|
|
173
|
+
dispatch({
|
|
174
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
175
|
+
payload: _ConversationState.ConversationState.Closed
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
} // New adapter creation
|
|
179
|
+
|
|
101
180
|
|
|
102
181
|
const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
|
|
103
182
|
setAdapter(newAdapter);
|
|
104
183
|
const chatToken = await chatSDK.getChatToken();
|
|
184
|
+
dispatch({
|
|
185
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
186
|
+
payload: chatToken
|
|
187
|
+
});
|
|
105
188
|
newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
|
|
106
189
|
|
|
107
|
-
if (
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
-
if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
-
const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
|
|
112
|
-
dispatch({
|
|
113
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
|
|
114
|
-
payload: chatToken
|
|
115
|
-
});
|
|
116
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
190
|
+
if (persistedState) {
|
|
120
191
|
dispatch({
|
|
121
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.
|
|
122
|
-
payload:
|
|
192
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
193
|
+
payload: persistedState
|
|
123
194
|
});
|
|
124
|
-
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
125
|
-
|
|
195
|
+
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
|
|
196
|
+
return;
|
|
197
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
|
|
201
|
+
dispatch({
|
|
202
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
|
|
203
|
+
payload: liveChatContext
|
|
204
|
+
}); // Set post chat context in state, no survey load
|
|
205
|
+
|
|
206
|
+
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
|
|
207
|
+
|
|
208
|
+
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
|
|
209
|
+
|
|
210
|
+
if (isStartChatSuccessful) {
|
|
211
|
+
_ActivityStreamHandler.ActivityStreamHandler.uncork();
|
|
126
212
|
|
|
127
213
|
dispatch({
|
|
128
214
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
129
215
|
payload: _ConversationState.ConversationState.Active
|
|
130
216
|
});
|
|
131
|
-
} else {
|
|
132
|
-
dispatch({
|
|
133
|
-
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
134
|
-
payload: persistedState
|
|
135
|
-
});
|
|
136
|
-
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
|
|
137
217
|
}
|
|
138
218
|
|
|
139
219
|
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
@@ -162,6 +242,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
162
242
|
payload: _ConversationState.ConversationState.OutOfOffice
|
|
163
243
|
});
|
|
164
244
|
}
|
|
245
|
+
} finally {
|
|
246
|
+
optionalParams = {};
|
|
247
|
+
widgetInstanceId = "";
|
|
165
248
|
}
|
|
166
249
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
250
|
|
|
@@ -169,24 +252,57 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
169
252
|
exports.initStartChat = initStartChat;
|
|
170
253
|
|
|
171
254
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
172
|
-
var
|
|
255
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
|
|
256
|
+
|
|
257
|
+
// By pass this function in case of popout chat
|
|
258
|
+
if (state.appStates.skipChatButtonRendering === true) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
173
261
|
|
|
174
|
-
const
|
|
175
|
-
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
262
|
+
const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? ""); //Connect to only active chat session
|
|
176
263
|
|
|
177
|
-
if (persistedState
|
|
178
|
-
var _persistedState$
|
|
264
|
+
if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === _ConversationState.ConversationState.Active) {
|
|
265
|
+
var _persistedState$domai7;
|
|
179
266
|
|
|
180
267
|
dispatch({
|
|
181
268
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
182
269
|
payload: _ConversationState.ConversationState.Loading
|
|
183
270
|
});
|
|
184
271
|
const optionalParams = {
|
|
185
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
272
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
186
273
|
};
|
|
187
|
-
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
274
|
+
await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
188
275
|
return true;
|
|
189
276
|
} else {
|
|
190
277
|
return false;
|
|
191
278
|
}
|
|
279
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
const setCustomContextParams = chatSDK => {
|
|
283
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
|
|
284
|
+
|
|
285
|
+
// Add custom context only for unauthenticated chat
|
|
286
|
+
const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
|
|
287
|
+
|
|
288
|
+
if (!(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
|
|
289
|
+
var _persistedState$domai9, _persistedState$domai10;
|
|
290
|
+
|
|
291
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
|
|
292
|
+
const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
|
|
293
|
+
|
|
294
|
+
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.WARN, {
|
|
295
|
+
Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
|
|
296
|
+
ExceptionDetails: {
|
|
297
|
+
exception: errorMessage
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
throw new Error(errorMessage);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
optionalParams = Object.assign({}, optionalParams, {
|
|
305
|
+
customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
|
|
306
|
+
});
|
|
307
|
+
}
|
|
192
308
|
};
|