@microsoft/omnichannel-chat-widget 0.1.0-main.ae27766 → 0.1.0-main.c2417f9
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 +32 -0
- package/lib/cjs/common/Constants.js +14 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +19 -3
- package/lib/cjs/common/telemetry/TelemetryManager.js +7 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +17 -16
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +17 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -13
- package/lib/cjs/components/livechatwidget/common/endChat.js +28 -13
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +12 -3
- package/lib/cjs/components/livechatwidget/common/startChat.js +49 -10
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +132 -30
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -5
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -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/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 +1 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +24 -21
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/cjs/contexts/createReducer.js +16 -0
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +14 -2
- package/lib/esm/common/telemetry/TelemetryConstants.js +19 -3
- package/lib/esm/common/telemetry/TelemetryManager.js +6 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +18 -13
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +8 -0
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +18 -7
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +7 -13
- package/lib/esm/components/livechatwidget/common/endChat.js +26 -14
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +11 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +51 -14
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +122 -30
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +6 -7
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +16 -0
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -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/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 +1 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +24 -21
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/esm/contexts/createReducer.js +16 -0
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +7 -1
- package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +19 -5
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/utils.d.ts +2 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- 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/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +24 -21
- package/package.json +2 -2
|
@@ -35,7 +35,11 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
|
|
|
35
35
|
|
|
36
36
|
var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
|
|
37
37
|
|
|
38
|
+
var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
|
|
39
|
+
|
|
38
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
|
|
39
43
|
const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
40
44
|
var _props$reconnectChatP;
|
|
41
45
|
|
|
@@ -74,11 +78,13 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
|
|
|
74
78
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
75
79
|
payload: _ConversationState.ConversationState.Prechat
|
|
76
80
|
});
|
|
81
|
+
setCustomContextParams(props, state);
|
|
77
82
|
} else {
|
|
78
83
|
dispatch({
|
|
79
84
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
80
85
|
payload: _ConversationState.ConversationState.Loading
|
|
81
86
|
});
|
|
87
|
+
setCustomContextParams(props, state);
|
|
82
88
|
await initStartChat(chatSDK, dispatch, setAdapter);
|
|
83
89
|
}
|
|
84
90
|
}
|
|
@@ -91,6 +97,21 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
91
97
|
try {
|
|
92
98
|
var _newAdapter$activity$, _TelemetryTimers$Widg;
|
|
93
99
|
|
|
100
|
+
let isStartChatSuccessful = false;
|
|
101
|
+
|
|
102
|
+
if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
|
|
103
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
|
|
104
|
+
|
|
105
|
+
// Broadcasting limited cached chat details
|
|
106
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
107
|
+
eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
|
|
108
|
+
payload: {
|
|
109
|
+
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,
|
|
110
|
+
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
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
94
115
|
try {
|
|
95
116
|
_TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
|
|
96
117
|
|
|
@@ -98,7 +119,9 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
98
119
|
Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
|
|
99
120
|
});
|
|
100
121
|
|
|
101
|
-
|
|
122
|
+
optionalParams = Object.assign({}, params, optionalParams);
|
|
123
|
+
await chatSDK.startChat(optionalParams);
|
|
124
|
+
isStartChatSuccessful = true;
|
|
102
125
|
} catch (error) {
|
|
103
126
|
_TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
104
127
|
Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
|
|
@@ -106,6 +129,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
106
129
|
exception: `Failed to setup startChat: ${error}`
|
|
107
130
|
}
|
|
108
131
|
});
|
|
132
|
+
|
|
133
|
+
isStartChatSuccessful = false;
|
|
109
134
|
}
|
|
110
135
|
|
|
111
136
|
const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
|
|
@@ -133,10 +158,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
133
158
|
await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
|
|
134
159
|
await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
|
|
135
160
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
161
|
+
if (isStartChatSuccessful) {
|
|
162
|
+
dispatch({
|
|
163
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
164
|
+
payload: _ConversationState.ConversationState.Active
|
|
165
|
+
});
|
|
166
|
+
}
|
|
140
167
|
} else {
|
|
141
168
|
dispatch({
|
|
142
169
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
|
|
@@ -178,24 +205,36 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
|
|
|
178
205
|
exports.initStartChat = initStartChat;
|
|
179
206
|
|
|
180
207
|
const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
|
|
181
|
-
var _DataStoreManager$cli, _persistedState$
|
|
208
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
|
|
182
209
|
|
|
183
|
-
const
|
|
210
|
+
const widgetStateEventName = (0, _utils.getWidgetCacheId)((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) ?? "");
|
|
211
|
+
const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
184
212
|
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
185
213
|
|
|
186
|
-
if (persistedState !== null && persistedState !== void 0 && (_persistedState$
|
|
187
|
-
var _persistedState$
|
|
214
|
+
if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
|
|
215
|
+
var _persistedState$domai7;
|
|
188
216
|
|
|
189
217
|
dispatch({
|
|
190
218
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
191
219
|
payload: _ConversationState.ConversationState.Loading
|
|
192
220
|
});
|
|
193
221
|
const optionalParams = {
|
|
194
|
-
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$
|
|
222
|
+
liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
|
|
195
223
|
};
|
|
196
224
|
await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
197
225
|
return true;
|
|
198
226
|
} else {
|
|
199
227
|
return false;
|
|
200
228
|
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const setCustomContextParams = (props, state) => {
|
|
232
|
+
var _props$chatConfig, _state$domainStates;
|
|
233
|
+
|
|
234
|
+
// Add custom context if any only for unauthenticated chat
|
|
235
|
+
if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
|
|
236
|
+
optionalParams = Object.assign({}, optionalParams, {
|
|
237
|
+
customContext: state.domainStates.customContext
|
|
238
|
+
});
|
|
239
|
+
}
|
|
201
240
|
};
|
|
@@ -107,7 +107,8 @@ const LiveChatWidgetStateful = props => {
|
|
|
107
107
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
108
108
|
}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
109
|
|
|
110
|
-
const chatSDK = (0, _useChatSDKStore.default)();
|
|
110
|
+
const chatSDK = (0, _useChatSDKStore.default)(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
|
|
111
112
|
const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = (0, _react2.useState)(undefined);
|
|
112
113
|
const {
|
|
113
114
|
Composer
|
|
@@ -121,6 +122,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
121
122
|
_TelemetryManager.TelemetryTimers.LcwLoadToChatButtonTimer = (0, _utils.createTimer)();
|
|
122
123
|
const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
|
|
123
124
|
const currentMessageCountRef = (0, _react2.useRef)(0);
|
|
125
|
+
let widgetStateEventName = "";
|
|
124
126
|
(0, _react2.useEffect)(() => {
|
|
125
127
|
var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
|
|
126
128
|
|
|
@@ -135,6 +137,10 @@ const LiveChatWidgetStateful = props => {
|
|
|
135
137
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
|
|
136
138
|
payload: ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.skipChatButtonRendering) || false
|
|
137
139
|
});
|
|
140
|
+
dispatch({
|
|
141
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
142
|
+
payload: false
|
|
143
|
+
});
|
|
138
144
|
(0, _initCallingSdk.initCallingSdk)(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
139
145
|
sdkCreated && dispatch({
|
|
140
146
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
@@ -163,7 +169,8 @@ const LiveChatWidgetStateful = props => {
|
|
|
163
169
|
};
|
|
164
170
|
(0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams);
|
|
165
171
|
}
|
|
166
|
-
}, []);
|
|
172
|
+
}, []); // useEffect for when skip chat button rendering
|
|
173
|
+
|
|
167
174
|
(0, _react2.useEffect)(() => {
|
|
168
175
|
if (state.appStates.skipChatButtonRendering) {
|
|
169
176
|
var _props$reconnectChatP3;
|
|
@@ -199,9 +206,25 @@ const LiveChatWidgetStateful = props => {
|
|
|
199
206
|
});
|
|
200
207
|
}
|
|
201
208
|
}
|
|
202
|
-
}, [state.appStates.skipChatButtonRendering]);
|
|
209
|
+
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
210
|
+
|
|
203
211
|
(0, _react2.useEffect)(() => {
|
|
204
|
-
|
|
212
|
+
var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
|
|
213
|
+
|
|
214
|
+
// Add the custom context on receiving the SetCustomContext event
|
|
215
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
216
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
217
|
+
Event: _TelemetryConstants.TelemetryEvent.CustomContextReceived,
|
|
218
|
+
Description: "CustomContext received."
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
dispatch({
|
|
222
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
223
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartProactiveChat).subscribe(msg => {
|
|
205
228
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
206
229
|
Event: _TelemetryConstants.TelemetryEvent.StartProactiveChatEventReceived,
|
|
207
230
|
Description: "Start proactive chat event received."
|
|
@@ -217,51 +240,124 @@ const LiveChatWidgetStateful = props => {
|
|
|
217
240
|
Description: "Start proactive chat method called, when chat was already triggered."
|
|
218
241
|
});
|
|
219
242
|
}
|
|
220
|
-
}); //
|
|
243
|
+
}); // Start chat from SDK Event
|
|
244
|
+
|
|
221
245
|
|
|
246
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(() => {
|
|
247
|
+
var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli;
|
|
222
248
|
|
|
223
|
-
_omnichannelChatComponents.BroadcastService.getMessageByEventName("StartChat").subscribe(() => {
|
|
224
249
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
225
250
|
Event: _TelemetryConstants.TelemetryEvent.StartChatEventRecevied,
|
|
226
251
|
Description: "Start chat event received."
|
|
227
|
-
});
|
|
252
|
+
}); // Getting updated state from cache
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
const widgetStateEventName = (0, _utils.getWidgetCacheId)((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) ?? "");
|
|
256
|
+
const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
|
|
257
|
+
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
258
|
+
|
|
259
|
+
if (persistedState.appStates.conversationState === _ConversationState.ConversationState.Closed || persistedState.appStates.conversationState === _ConversationState.ConversationState.InActive || persistedState.appStates.conversationState === _ConversationState.ConversationState.Postchat) {
|
|
260
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
261
|
+
eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
(0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
|
|
265
|
+
} else {
|
|
266
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
|
|
228
267
|
|
|
229
|
-
if (state.appStates.isMinimized) {
|
|
230
268
|
dispatch({
|
|
231
269
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
|
|
232
270
|
payload: false
|
|
233
271
|
});
|
|
234
|
-
|
|
235
|
-
|
|
272
|
+
|
|
273
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
274
|
+
eventName: _TelemetryConstants.BroadcastEvent.MaximizeChat,
|
|
275
|
+
payload: {
|
|
276
|
+
height: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.widgetSize) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.height,
|
|
277
|
+
width: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai3 = persistedState.domainStates) === null || _persistedState$domai3 === void 0 ? void 0 : (_persistedState$domai4 = _persistedState$domai3.widgetSize) === null || _persistedState$domai4 === void 0 ? void 0 : _persistedState$domai4.width
|
|
278
|
+
}
|
|
279
|
+
});
|
|
236
280
|
}
|
|
237
|
-
}); //
|
|
281
|
+
}); // End chat
|
|
282
|
+
|
|
238
283
|
|
|
284
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async msg => {
|
|
285
|
+
var _msg$payload4, _msg$payload5;
|
|
286
|
+
|
|
287
|
+
const isChatUnloading = ((_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.chatUnloading) ?? false;
|
|
288
|
+
const isSdkCall = ((_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.isSdkCall) ?? false;
|
|
289
|
+
const eventDescription = isChatUnloading ? "End chat event received from unload." : "End chat event received.";
|
|
239
290
|
|
|
240
|
-
_omnichannelChatComponents.BroadcastService.getMessageByEventName("EndChat").subscribe(async () => {
|
|
241
291
|
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
242
292
|
Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
|
|
243
|
-
Description:
|
|
293
|
+
Description: eventDescription
|
|
244
294
|
});
|
|
245
295
|
|
|
246
|
-
if (
|
|
296
|
+
if (isChatUnloading) {
|
|
297
|
+
var _DataStoreManager$cli2;
|
|
298
|
+
|
|
299
|
+
//Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
|
|
300
|
+
(0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false); // Clean local storage
|
|
301
|
+
|
|
302
|
+
(_DataStoreManager$cli2 = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.removeData(widgetStateEventName, "localStorage");
|
|
303
|
+
} else if (canEndChat.current) {
|
|
247
304
|
(0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
248
305
|
} else {
|
|
249
306
|
const skipEndChatSDK = true;
|
|
250
307
|
const skipCloseChat = false;
|
|
251
308
|
(0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
309
|
+
} // Raise chatClose for SDK events
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if (isSdkCall) {
|
|
313
|
+
_omnichannelChatComponents.BroadcastService.postMessage({
|
|
314
|
+
eventName: _TelemetryConstants.BroadcastEvent.CloseChat
|
|
315
|
+
});
|
|
252
316
|
}
|
|
253
|
-
});
|
|
317
|
+
}); // reset proactive chat params
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.ResetProactiveChatParams).subscribe(async () => {
|
|
321
|
+
dispatch({
|
|
322
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
323
|
+
payload: {
|
|
324
|
+
proactiveChatBodyTitle: "",
|
|
325
|
+
proactiveChatEnablePrechat: false,
|
|
326
|
+
proactiveChatInNewWindow: false
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}); // Listen to end chat event from other tabs
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
const endChatEventName = (0, _utils.getWidgetEndChatEventName)(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);
|
|
333
|
+
|
|
334
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
335
|
+
(0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
336
|
+
}); // Close popout window
|
|
337
|
+
|
|
254
338
|
|
|
255
339
|
window.addEventListener("beforeunload", () => {
|
|
340
|
+
_TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
341
|
+
Event: _TelemetryConstants.TelemetryEvent.WindowClosed,
|
|
342
|
+
Description: "Closed window."
|
|
343
|
+
});
|
|
344
|
+
|
|
256
345
|
(0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
|
|
257
346
|
});
|
|
258
347
|
|
|
259
348
|
if (state.appStates.conversationEndedByAgent) {
|
|
260
349
|
(0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
261
|
-
}
|
|
350
|
+
} //Listen to WidgetSize
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
_omnichannelChatComponents.BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
|
|
354
|
+
dispatch({
|
|
355
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_SIZE,
|
|
356
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
357
|
+
});
|
|
358
|
+
});
|
|
262
359
|
}, []);
|
|
263
360
|
(0, _react2.useEffect)(() => {
|
|
264
|
-
canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed;
|
|
265
361
|
canEndChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Active;
|
|
266
362
|
|
|
267
363
|
if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
|
|
@@ -282,7 +378,10 @@ const LiveChatWidgetStateful = props => {
|
|
|
282
378
|
});
|
|
283
379
|
});
|
|
284
380
|
}
|
|
285
|
-
}, [state.appStates.conversationState]);
|
|
381
|
+
}, [state.appStates.conversationState]);
|
|
382
|
+
(0, _react2.useEffect)(() => {
|
|
383
|
+
canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
|
|
384
|
+
}, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
|
|
286
385
|
|
|
287
386
|
(0, _react2.useEffect)(() => {
|
|
288
387
|
currentMessageCountRef.current = -1;
|
|
@@ -316,7 +415,20 @@ const LiveChatWidgetStateful = props => {
|
|
|
316
415
|
setWebChatStyles({ ...webChatStyles,
|
|
317
416
|
...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
|
|
318
417
|
});
|
|
319
|
-
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
|
|
418
|
+
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
|
|
419
|
+
|
|
420
|
+
(0, _react2.useEffect)(() => {
|
|
421
|
+
var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
|
|
422
|
+
|
|
423
|
+
widgetStateEventName = (0, _utils.getWidgetCacheId)(props === null || props === void 0 ? void 0 : (_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, props === null || props === void 0 ? void 0 : (_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);
|
|
424
|
+
const chatWidgetStateChangeEvent = {
|
|
425
|
+
eventName: widgetStateEventName,
|
|
426
|
+
payload: { ...state
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
_omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
431
|
+
}, [state]);
|
|
320
432
|
const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
321
433
|
|
|
322
434
|
const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -332,17 +444,7 @@ const LiveChatWidgetStateful = props => {
|
|
|
332
444
|
|
|
333
445
|
const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
334
446
|
|
|
335
|
-
const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
|
|
336
|
-
|
|
337
|
-
(0, _react2.useEffect)(() => {
|
|
338
|
-
const chatWidgetStateChangeEvent = {
|
|
339
|
-
eventName: _TelemetryConstants.BroadcastEvent.ChatWidgetStateChanged,
|
|
340
|
-
payload: { ...state
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
_omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
345
|
-
}, [state]);
|
|
447
|
+
const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
|
|
346
448
|
return /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
|
|
347
449
|
styleOptions: webChatStyles,
|
|
348
450
|
directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.directLine
|
|
@@ -93,9 +93,10 @@ const PreChatSurveyPaneStateful = props => {
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
try {
|
|
96
|
-
var _DataStoreManager$cli, _persistedState$domai;
|
|
96
|
+
var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _DataStoreManager$cli, _persistedState$domai;
|
|
97
97
|
|
|
98
|
-
const
|
|
98
|
+
const widgetStateCacheId = (0, _utils.getWidgetCacheId)(((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$t = _state$domainStates.telemetryInternalData) === null || _state$domainStates$t === void 0 ? void 0 : _state$domainStates$t.orgId) ?? "", ((_state$domainStates$t2 = state.domainStates.telemetryInternalData) === null || _state$domainStates$t2 === void 0 ? void 0 : _state$domainStates$t2.widgetId) ?? "");
|
|
99
|
+
const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateCacheId, "localStorage");
|
|
99
100
|
const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
|
|
100
101
|
let optionalParams = {};
|
|
101
102
|
|
|
@@ -109,9 +110,7 @@ const PreChatSurveyPaneStateful = props => {
|
|
|
109
110
|
} else {
|
|
110
111
|
const prechatResponseValues = (0, _utils.extractPreChatSurveyResponseValues)(state.domainStates.preChatSurveyResponse, values);
|
|
111
112
|
optionalParams = {
|
|
112
|
-
|
|
113
|
-
preChatResponse: prechatResponseValues
|
|
114
|
-
}
|
|
113
|
+
preChatResponse: prechatResponseValues
|
|
115
114
|
};
|
|
116
115
|
setPreChatResponseEmail(values);
|
|
117
116
|
await initStartChat(optionalParams);
|
|
@@ -46,6 +46,14 @@ const ProactiveChatPaneStateful = props => {
|
|
|
46
46
|
const handleProactiveChatInviteTimeout = () => {
|
|
47
47
|
if (!timeoutRemoved) {
|
|
48
48
|
setTimeoutRemoved(true);
|
|
49
|
+
dispatch({
|
|
50
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
51
|
+
payload: {
|
|
52
|
+
proactiveChatBodyTitle: "",
|
|
53
|
+
proactiveChatEnablePrechat: false,
|
|
54
|
+
proactiveChatInNewWindow: false
|
|
55
|
+
}
|
|
56
|
+
});
|
|
49
57
|
dispatch({
|
|
50
58
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
51
59
|
payload: _ConversationState.ConversationState.Closed
|
|
@@ -111,6 +119,14 @@ const ProactiveChatPaneStateful = props => {
|
|
|
111
119
|
Description: "Proactive chat closed."
|
|
112
120
|
});
|
|
113
121
|
|
|
122
|
+
dispatch({
|
|
123
|
+
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
124
|
+
payload: {
|
|
125
|
+
proactiveChatBodyTitle: "",
|
|
126
|
+
proactiveChatEnablePrechat: false,
|
|
127
|
+
proactiveChatInNewWindow: false
|
|
128
|
+
}
|
|
129
|
+
});
|
|
114
130
|
dispatch({
|
|
115
131
|
type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
116
132
|
payload: _ConversationState.ConversationState.Closed
|
|
@@ -25,15 +25,53 @@ var _utils = require("../../common/utils");
|
|
|
25
25
|
|
|
26
26
|
var _ = require("../..");
|
|
27
27
|
|
|
28
|
+
var _WebChatActionType = require("./webchatcontroller/enums/WebChatActionType");
|
|
29
|
+
|
|
30
|
+
var _WebChatStoreLoader = require("./webchatcontroller/WebChatStoreLoader");
|
|
31
|
+
|
|
32
|
+
var _Constants = require("../../common/Constants");
|
|
33
|
+
|
|
34
|
+
var _BotMagicCodeStore = require("./webchatcontroller/BotMagicCodeStore");
|
|
35
|
+
|
|
28
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
37
|
|
|
30
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
39
|
|
|
40
|
+
const broadcastChannelMessageEvent = "message";
|
|
41
|
+
|
|
42
|
+
const postActivity = activity => {
|
|
43
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
44
|
+
return {
|
|
45
|
+
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_POST_ACTIVITY,
|
|
46
|
+
meta: {
|
|
47
|
+
method: "keyboard"
|
|
48
|
+
},
|
|
49
|
+
payload: {
|
|
50
|
+
activity: {
|
|
51
|
+
channelData: undefined,
|
|
52
|
+
text: "",
|
|
53
|
+
textFormat: "plain",
|
|
54
|
+
type: _Constants.Constants.message,
|
|
55
|
+
...activity
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const createMagicCodeSuccessResponse = signin => {
|
|
62
|
+
return {
|
|
63
|
+
signin,
|
|
64
|
+
result: "Success"
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
32
68
|
const WebChatContainerStateful = props => {
|
|
33
69
|
const {
|
|
34
70
|
BasicWebChat
|
|
35
71
|
} = _botframeworkWebchat.Components;
|
|
36
72
|
const [state, dispatch] = (0, _.useChatContextStore)();
|
|
73
|
+
const magicCodeBroadcastChannel = new BroadcastChannel(_Constants.Constants.magicCodeBroadcastChannel);
|
|
74
|
+
const magicCodeResponseBroadcastChannel = new BroadcastChannel(_Constants.Constants.magicCodeResponseBroadcastChannel);
|
|
37
75
|
const containerStyles = {
|
|
38
76
|
root: Object.assign({}, _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.containerStyles, props === null || props === void 0 ? void 0 : props.containerStyles, {
|
|
39
77
|
display: state.appStates.isMinimized ? "none" : ""
|
|
@@ -58,6 +96,48 @@ const WebChatContainerStateful = props => {
|
|
|
58
96
|
Event: _TelemetryConstants.TelemetryEvent.WebChatLoaded
|
|
59
97
|
});
|
|
60
98
|
}, []);
|
|
99
|
+
(0, _react2.useEffect)(() => {
|
|
100
|
+
const eventListener = event => {
|
|
101
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-function
|
|
102
|
+
const {
|
|
103
|
+
data
|
|
104
|
+
} = event;
|
|
105
|
+
|
|
106
|
+
if (_BotMagicCodeStore.BotMagicCodeStore.botOAuthSignInId === data.signin) {
|
|
107
|
+
const {
|
|
108
|
+
signin,
|
|
109
|
+
code
|
|
110
|
+
} = data;
|
|
111
|
+
const text = `${code}`;
|
|
112
|
+
const action = postActivity({
|
|
113
|
+
text,
|
|
114
|
+
channelData: {
|
|
115
|
+
tags: [_Constants.Constants.hiddenTag]
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
_WebChatStoreLoader.WebChatStoreLoader.store.dispatch(action);
|
|
120
|
+
|
|
121
|
+
const response = createMagicCodeSuccessResponse(signin);
|
|
122
|
+
magicCodeResponseBroadcastChannel.postMessage(response);
|
|
123
|
+
|
|
124
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
|
|
125
|
+
Event: _TelemetryConstants.TelemetryEvent.SuppressBotMagicCodeSucceeded
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
_BotMagicCodeStore.BotMagicCodeStore.botOAuthSignInId = "";
|
|
129
|
+
magicCodeBroadcastChannel.close();
|
|
130
|
+
magicCodeResponseBroadcastChannel.close();
|
|
131
|
+
} else {
|
|
132
|
+
_TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
|
|
133
|
+
Event: _TelemetryConstants.TelemetryEvent.SuppressBotMagicCodeFailed,
|
|
134
|
+
Description: "Signin does not match"
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
magicCodeBroadcastChannel.addEventListener(broadcastChannelMessageEvent, eventListener);
|
|
140
|
+
}, []);
|
|
61
141
|
return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, /*#__PURE__*/_react2.default.createElement("style", null, `
|
|
62
142
|
.ms_lcw_webchat_received_message img.webchat__markdown__external-link-icon {
|
|
63
143
|
background-image : url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIzIDMgMTggMTgiICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik03LjI1MDEgNC41MDAxN0gxMC43NDk1QzExLjE2MzcgNC41MDAxNyAxMS40OTk1IDQuODM1OTYgMTEuNDk5NSA1LjI1MDE3QzExLjQ5OTUgNS42Mjk4NiAxMS4yMTczIDUuOTQzNjYgMTAuODUxMyA1Ljk5MzMyTDEwLjc0OTUgNi4wMDAxN0g3LjI0OTc0QzYuMDcwNzkgNS45OTk2MSA1LjEwMzQ5IDYuOTA2NTYgNS4wMDc4NiA4LjA2MTEyTDUuMDAwMjggOC4yMjAwM0w1LjAwMzEyIDE2Ljc1MDdDNS4wMDM0MyAxNy45NDE1IDUuOTI4ODUgMTguOTE2MSA3LjA5OTY2IDE4Ljk5NDlMNy4yNTM3MSAxOS4wMDAxTDE1Ljc1MTggMTguOTg4NEMxNi45NDE1IDE4Ljk4NjggMTcuOTE0NSAxOC4wNjIgMTcuOTkzNSAxNi44OTIzTDE3Ljk5ODcgMTYuNzM4NFYxMy4yMzIxQzE3Ljk5ODcgMTIuODE3OSAxOC4zMzQ1IDEyLjQ4MjEgMTguNzQ4NyAxMi40ODIxQzE5LjEyODQgMTIuNDgyMSAxOS40NDIyIDEyLjc2NDMgMTkuNDkxOCAxMy4xMzAzTDE5LjQ5ODcgMTMuMjMyMVYxNi43Mzg0QzE5LjQ5ODcgMTguNzQwNyAxNy45MjkzIDIwLjM3NjkgMTUuOTUyOCAyMC40ODI5TDE1Ljc1MzggMjAuNDg4NEw3LjI1ODI3IDIwLjUwMDFMNy4wNTQ5NSAyMC40OTQ5QzUuMTQyMzkgMjAuMzk1NCAzLjYwODk1IDE4Ljg2MjcgMy41MDgzNyAxNi45NTAyTDMuNTAzMTIgMTYuNzUxMUwzLjUwMDg5IDguMjUyN0wzLjUwNTI5IDguMDUwMkMzLjYwNTM5IDYuMTM3NDkgNS4xMzg2NyA0LjYwNDQ5IDcuMDUwOTYgNC41MDUyN0w3LjI1MDEgNC41MDAxN0gxMC43NDk1SDcuMjUwMVpNMTMuNzQ4MSAzLjAwMTQ2TDIwLjMwMTggMy4wMDE5N0wyMC40MDE0IDMuMDE1NzVMMjAuNTAyMiAzLjA0MzkzTDIwLjU1OSAzLjA2ODAzQzIwLjYxMjIgMy4wOTEyMiAyMC42NjM0IDMuMTIxNjMgMjAuNzExMSAzLjE1ODg1TDIwLjc4MDQgMy4yMjE1NkwyMC44NjQxIDMuMzIwMTRMMjAuOTE4MyAzLjQxMDI1TDIwLjk1NyAzLjUwMDU3TDIwLjk3NjIgMy41NjQ3NkwyMC45ODk4IDMuNjI4NjJMMjAuOTk5MiAzLjcyMjgyTDIwLjk5OTcgMTAuMjU1NEMyMC45OTk3IDEwLjY2OTYgMjAuNjYzOSAxMS4wMDU0IDIwLjI0OTcgMTEuMDA1NEMxOS44NyAxMS4wMDU0IDE5LjU1NjIgMTAuNzIzMiAxOS41MDY1IDEwLjM1NzFMMTkuNDk5NyAxMC4yNTU0TDE5LjQ5ODkgNS41NjE0N0wxMi4yNzk3IDEyLjc4NDdDMTIuMDEzNCAxMy4wNTEgMTEuNTk2OCAxMy4wNzUzIDExLjMwMzEgMTIuODU3NUwxMS4yMTkgMTIuNzg0OUMxMC45NTI3IDEyLjUxODcgMTAuOTI4NCAxMi4xMDIxIDExLjE0NjIgMTEuODA4NEwxMS4yMTg4IDExLjcyNDNMMTguNDM2OSA0LjUwMTQ2SDEzLjc0ODFDMTMuMzY4NCA0LjUwMTQ2IDEzLjA1NDYgNC4yMTkzMSAxMy4wMDUgMy44NTMyNEwxMi45OTgxIDMuNzUxNDZDMTIuOTk4MSAzLjM3MTc3IDEzLjI4MDMgMy4wNTc5NyAxMy42NDY0IDMuMDA4MzFMMTMuNzQ4MSAzLjAwMTQ2WiIgZmlsbD0iI0ZGRkZGRiIgLz48L3N2Zz4) !important;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BotMagicCodeStore = void 0;
|
|
7
|
+
|
|
8
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
|
|
10
|
+
class BotMagicCodeStore {}
|
|
11
|
+
|
|
12
|
+
exports.BotMagicCodeStore = BotMagicCodeStore;
|
|
13
|
+
|
|
14
|
+
_defineProperty(BotMagicCodeStore, "botOAuthSignInId", "");
|
|
@@ -75,6 +75,16 @@ const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
|
|
|
75
75
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
const isTagIncluded = (card, tag) => {
|
|
79
|
+
return isDataTagsPresent(card) && card.activity.channelData.tags.includes(tag);
|
|
80
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const isDataTagsPresent = card => {
|
|
84
|
+
return card && card.activity && card.activity.channelData && card.activity.channelData.tags && card.activity.channelData.tags.length > 0;
|
|
85
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
|
|
87
|
+
|
|
78
88
|
const createActivityMiddleware = (systemMessageStyleProps, userMessageStyleProps) => () => next => function () {
|
|
79
89
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
80
90
|
args[_key] = arguments[_key];
|
|
@@ -83,7 +93,7 @@ const createActivityMiddleware = (systemMessageStyleProps, userMessageStyleProps
|
|
|
83
93
|
const [card] = args;
|
|
84
94
|
|
|
85
95
|
if (card.activity) {
|
|
86
|
-
var _card$activity$from
|
|
96
|
+
var _card$activity$from;
|
|
87
97
|
|
|
88
98
|
if (((_card$activity$from = card.activity.from) === null || _card$activity$from === void 0 ? void 0 : _card$activity$from.role) === _DirectLineSenderRole.DirectLineSenderRole.Channel) {
|
|
89
99
|
var _card$activity$channe3;
|
|
@@ -98,7 +108,11 @@ const createActivityMiddleware = (systemMessageStyleProps, userMessageStyleProps
|
|
|
98
108
|
return () => false;
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
if ((
|
|
111
|
+
if (isTagIncluded(card, _Constants.Constants.hiddenTag)) {
|
|
112
|
+
return () => false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (isTagIncluded(card, _Constants.Constants.systemMessageTag)) {
|
|
102
116
|
return handleSystemMessage(next, args, card, systemMessageStyleProps);
|
|
103
117
|
} else if (card.activity.text && card.activity.type === _DirectLineActivityType.DirectLineActivityType.Message) {
|
|
104
118
|
if (!card.activity.channelData.isHtmlEncoded && card.activity.channelId === _Constants.Constants.webchatChannelId) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createCardActionMiddleware = void 0;
|
|
7
|
+
|
|
8
|
+
var _BotMagicCodeStore = require("../../BotMagicCodeStore");
|
|
9
|
+
|
|
10
|
+
var CardActionType;
|
|
11
|
+
|
|
12
|
+
(function (CardActionType) {
|
|
13
|
+
CardActionType["OpenUrl"] = "openUrl";
|
|
14
|
+
CardActionType["SignIn"] = "signin";
|
|
15
|
+
})(CardActionType || (CardActionType = {}));
|
|
16
|
+
|
|
17
|
+
const validCardActionTypes = [CardActionType.OpenUrl, CardActionType.SignIn];
|
|
18
|
+
const botOauthUrlRegex = /[\S]+.botframework.com\/api\/oauth\/signin\?signin=([\S]+)/;
|
|
19
|
+
|
|
20
|
+
const createCardActionMiddleware = botMagicCodeConfig => {
|
|
21
|
+
const cardActionMiddleware = () => next => function () {
|
|
22
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23
|
+
args[_key] = arguments[_key];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const [card] = args;
|
|
28
|
+
|
|
29
|
+
if (card.cardAction && validCardActionTypes.indexOf(card.cardAction.type) >= 0 && card.cardAction.value) {
|
|
30
|
+
// Override signin url only if fwdUrl is valid & feature is enabled
|
|
31
|
+
if ((botMagicCodeConfig === null || botMagicCodeConfig === void 0 ? void 0 : botMagicCodeConfig.disabled) === true && botMagicCodeConfig !== null && botMagicCodeConfig !== void 0 && botMagicCodeConfig.fwdUrl) {
|
|
32
|
+
const baseUrl = window.location.origin;
|
|
33
|
+
const result = botOauthUrlRegex.exec(card.cardAction.value);
|
|
34
|
+
|
|
35
|
+
if (result) {
|
|
36
|
+
_BotMagicCodeStore.BotMagicCodeStore.botOAuthSignInId = `${result[1]}`;
|
|
37
|
+
} // fwdUrl must be on the same domain as the chat widget
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (botMagicCodeConfig !== null && botMagicCodeConfig !== void 0 && botMagicCodeConfig.fwdUrl.startsWith(baseUrl)) {
|
|
41
|
+
card.cardAction.value += `&fwdUrl=${botMagicCodeConfig.fwdUrl}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return next(...args);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return cardActionMiddleware;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.createCardActionMiddleware = createCardActionMiddleware;
|