@microsoft/omnichannel-chat-widget 1.2.3-main.fc07b68 → 1.2.4-main.6b298de

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.
Files changed (31) hide show
  1. package/lib/cjs/common/Constants.js +3 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +1 -0
  3. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -1
  4. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +2 -1
  5. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  6. package/lib/cjs/components/livechatwidget/common/startChat.js +6 -5
  7. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  8. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +6 -3
  9. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +190 -0
  10. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +65 -0
  11. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +342 -0
  12. package/lib/cjs/plugins/createChatTranscript.js +28 -4
  13. package/lib/esm/common/Constants.js +3 -0
  14. package/lib/esm/common/telemetry/TelemetryConstants.js +1 -0
  15. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -1
  16. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -1
  17. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  18. package/lib/esm/components/livechatwidget/common/startChat.js +6 -5
  19. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  20. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +6 -3
  21. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +188 -0
  22. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +58 -0
  23. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +338 -0
  24. package/lib/esm/plugins/createChatTranscript.js +28 -4
  25. package/lib/types/common/Constants.d.ts +3 -0
  26. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  27. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
  28. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +1 -0
  29. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.d.ts +5 -0
  30. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +1 -0
  31. package/package.json +1 -1
@@ -117,6 +117,9 @@ _defineProperty(Constants, "LWICheckOnVisibilityTimeout", 3 * 60 * 1000);
117
117
  // Popup mode custom context response event message name
118
118
  _defineProperty(Constants, "InitContextParamsRequest", "initContextParamsRequest");
119
119
  _defineProperty(Constants, "InitContextParamsResponse", "initContextParamsResponse");
120
+ _defineProperty(Constants, "OCOriginalMessageId", "OriginalMessageId");
121
+ _defineProperty(Constants, "WebchatSequenceIdAttribute", "webchat:sequence-id");
122
+ _defineProperty(Constants, "MessageSequenceIdOverride", "MessageSequenceIdOverride");
120
123
  const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
121
124
  exports.Regex = Regex;
122
125
  class HtmlIdNames {}
@@ -164,6 +164,7 @@ exports.TelemetryEvent = TelemetryEvent;
164
164
  TelemetryEvent["SetBotAuthProviderHideCard"] = "SetBotAuthProviderHideCard";
165
165
  TelemetryEvent["SetBotAuthProviderDisplayCard"] = "SetBotAuthProviderDisplayCard";
166
166
  TelemetryEvent["SetBotAuthProviderNotFound"] = "SetBotAuthProviderNotFound";
167
+ TelemetryEvent["BotAuthActivityUndefinedSignInId"] = "BotAuthActivityUndefinedSignInId";
167
168
  TelemetryEvent["ThirdPartyCookiesBlocked"] = "ThirdPartyCookiesBlocked";
168
169
  TelemetryEvent["ProcessingHTMLTextMiddlewareFailed"] = "ProcessingHTMLTextMiddlewareFailed";
169
170
  TelemetryEvent["ProcessingSanitizationMiddlewareFailed"] = "ProcessingSanitizationMiddlewareFailed";
@@ -83,7 +83,10 @@ class BotAuthActivitySubscriber {
83
83
  const signInUrl = attachment.content.buttons[0].value;
84
84
  const signInId = extractSignInId(signInUrl);
85
85
  if (!signInId) {
86
- return;
86
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
87
+ Event: _TelemetryConstants.TelemetryEvent.BotAuthActivityUndefinedSignInId
88
+ });
89
+ return activity;
87
90
  }
88
91
  if (this.signInCardSeen.has(signInId)) {
89
92
  // Prevents duplicate auth
@@ -35,6 +35,7 @@ var _htmlTextMiddleware = _interopRequireDefault(require("../../webchatcontainer
35
35
  var _preProcessingMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware"));
36
36
  var _sanitizationMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"));
37
37
  var _dompurify = _interopRequireDefault(require("dompurify"));
38
+ var _messageSequenceIdOverrideMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware"));
38
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
41
  const initWebChatComposer = (props, state, dispatch, chatSDK) => {
@@ -74,7 +75,7 @@ const initWebChatComposer = (props, state, dispatch, chatSDK) => {
74
75
  };
75
76
  webChatStore = (0, _botframeworkWebchat.createStore)({},
76
77
  //initial state
77
- _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), _channelDataMiddleware.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), _messageTimestampMiddleware.default, _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default,
78
+ _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), _channelDataMiddleware.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), _messageTimestampMiddleware.default, _messageSequenceIdOverrideMiddleware.default, _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default,
78
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
80
  ...(((_props$webChatContain5 = props.webChatContainerProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.storeMiddlewares) ?? []));
80
81
  _WebChatStoreLoader.WebChatStoreLoader.store = webChatStore;
@@ -13,10 +13,11 @@ var _Constants = require("../../../common/Constants");
13
13
  var _ConversationState = require("../../../contexts/common/ConversationState");
14
14
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
15
15
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
16
+ // Return value: should start normal chat flow when reconnect is enabled
16
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
18
  const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
18
19
  var _props$chatConfig, _props$chatConfig$Liv;
19
- if (!isReconnectEnabled(props.chatConfig) || isPersistentEnabled(props.chatConfig)) return;
20
+ if (!isReconnectEnabled(props.chatConfig) || isPersistentEnabled(props.chatConfig)) return false;
20
21
 
21
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
23
  const isAuthenticatedChat = (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
@@ -28,14 +29,14 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
28
29
  if (reconnectChatContext !== null && reconnectChatContext !== void 0 && reconnectChatContext.redirectURL) {
29
30
  var _props$reconnectChatP;
30
31
  redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
31
- return;
32
+ return false;
32
33
  }
33
34
  if (hasReconnectId(reconnectChatContext)) {
34
35
  var _props$reconnectChatP2, _props$reconnectChatP3;
35
36
  //if reconnect id is provided in props, don't show reconnect pane
36
37
  if ((_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.reconnectId && !(0, _utils.isNullOrEmptyString)((_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId)) {
37
- await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
38
- return;
38
+ await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, state, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
39
+ return false;
39
40
  }
40
41
 
41
42
  //show reconnect pane
@@ -48,8 +49,12 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
48
49
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
49
50
  payload: _ConversationState.ConversationState.ReconnectChat
50
51
  });
51
- return;
52
+ return false;
52
53
  }
54
+
55
+ // If we have reached this point, it means there is no valid reconnect id or redirectUrl
56
+ // This is a unauth reconnect refresh scenario - returns true so that we can start normal hydration process
57
+ return true;
53
58
  };
54
59
 
55
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -88,7 +93,7 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
88
93
 
89
94
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
95
  exports.getChatReconnectContext = getChatReconnectContext;
91
- const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectId, initStartChat) => {
96
+ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, state, props, dispatch, setAdapter, reconnectId, initStartChat) => {
92
97
  if (!isAuthenticatedChat) {
93
98
  const startUnauthenticatedReconnectChat = {
94
99
  eventName: _TelemetryConstants.BroadcastEvent.StartUnauthenticatedReconnectChat
@@ -106,7 +111,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, d
106
111
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
107
112
  payload: _ConversationState.ConversationState.Loading
108
113
  });
109
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
114
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
110
115
  };
111
116
  const redirectPage = (redirectURL, redirectInSameWindow) => {
112
117
  const redirectPageRequest = {
@@ -303,16 +303,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
303
303
 
304
304
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
305
  const setCustomContextParams = async (state, props) => {
306
- var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
306
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates, _persistedState$domai8;
307
307
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
308
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
309
309
  //Should not set custom context for auth chat
310
310
  if (isAuthenticatedChat) {
311
311
  return;
312
312
  }
313
- if (state !== null && state !== void 0 && state.domainStates.customContext) {
313
+ if (state !== null && state !== void 0 && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
314
+ var _state$domainStates2;
314
315
  optionalParams = Object.assign({}, optionalParams, {
315
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : state.domainStates.customContext))
316
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.customContext))
316
317
  });
317
318
  return;
318
319
  }
@@ -360,8 +361,8 @@ const canStartPopoutChat = async props => {
360
361
 
361
362
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
362
363
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
363
- var _state$domainStates, _state$domainStates$l;
364
- const requestIdFromCache = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
364
+ var _state$domainStates3, _state$domainStates3$;
365
+ const requestIdFromCache = (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.liveChatContext) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.requestId;
365
366
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
366
367
  let conversationDetails = undefined;
367
368
 
@@ -116,6 +116,16 @@ const LiveChatWidgetStateful = props => {
116
116
 
117
117
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
118
  const startChat = async (props, localState) => {
119
+ const isReconnectTriggered = async () => {
120
+ if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
121
+ const noValidReconnectId = await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
122
+ // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
123
+ if (!noValidReconnectId && (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat)) {
124
+ return true;
125
+ }
126
+ }
127
+ return false;
128
+ };
119
129
  let isChatValid = false;
120
130
  //Start a chat from cache/reconnectid
121
131
  if (activeCachedChatExist === true) {
@@ -130,29 +140,20 @@ const LiveChatWidgetStateful = props => {
130
140
  //Check if conversation state is not in wrapup or closed state
131
141
  isChatValid = await (0, _startChat.checkIfConversationStillValid)(chatSDK, dispatch, state);
132
142
  if (isChatValid === true) {
133
- //Check if reconnect enabled
134
- if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
135
- await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
136
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
137
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
138
- return;
139
- }
143
+ const reconnectTriggered = await isReconnectTriggered();
144
+ if (!reconnectTriggered) {
145
+ await (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, state, props, optionalParams);
140
146
  }
141
- await (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, state, props, optionalParams);
142
147
  return;
143
148
  }
144
149
  }
145
150
  if (isChatValid === false) {
146
151
  if (localState) {
147
152
  // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
148
- if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
149
- await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
150
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
151
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
152
- return;
153
- }
153
+ const reconnectTriggered = await isReconnectTriggered();
154
+ if (!reconnectTriggered) {
155
+ await (0, _startChat.setPreChatAndInitiateChat)(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
154
156
  }
155
- await (0, _startChat.setPreChatAndInitiateChat)(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
156
157
  return;
157
158
  } else {
158
159
  var _state$appStates4;
@@ -51,12 +51,15 @@ const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
51
51
  return () => false;
52
52
  }
53
53
 
54
- // eslint-disable-next-line react/display-name, @typescript-eslint/no-explicit-any
54
+ // eslint-disable-next-line react/display-name
55
55
  return () => /*#__PURE__*/_react.default.createElement("div", {
56
56
  key: card.activity.id,
57
57
  style: systemMessageStyles,
58
- "aria-hidden": "true"
59
- }, card.activity.text);
58
+ "aria-hidden": "true",
59
+ dangerouslySetInnerHTML: {
60
+ __html: (0, _utils.escapeHtml)(card.activity.text)
61
+ }
62
+ });
60
63
  };
61
64
 
62
65
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ var _Constants = require("../../../../../common/Constants");
4
+ var _DirectLineActivityType = require("../../enums/DirectLineActivityType");
5
+ var _DirectLineSenderRole = require("../../enums/DirectLineSenderRole");
6
+ var _MessageType = require("../../enums/MessageType");
7
+ var _TelemetryHelper = require("../../../../../common/telemetry/TelemetryHelper");
8
+ var _activityMiddleware = require("./activityMiddleware");
9
+ describe("activityMiddleware test", () => {
10
+ it("createActivityMiddleware() with Channel role sender should returns nothing", () => {
11
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
12
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
13
+ const args = {
14
+ activity: {
15
+ channelData: {
16
+ type: _MessageType.MessageTypes.Thread
17
+ },
18
+ from: {
19
+ role: _DirectLineSenderRole.DirectLineSenderRole.Channel
20
+ }
21
+ }
22
+ };
23
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
24
+ expect(results()).toEqual(false);
25
+ expect(_TelemetryHelper.TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(1);
26
+ });
27
+ it("createActivityMiddleware() with Hidden tag should return nothing", () => {
28
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
29
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
30
+ const args = {
31
+ activity: {
32
+ channelData: {
33
+ tags: [_Constants.Constants.hiddenTag]
34
+ },
35
+ from: {
36
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
37
+ }
38
+ }
39
+ };
40
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
41
+ expect(results()).toEqual(false);
42
+ expect(_TelemetryHelper.TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
43
+ });
44
+ it("createActivityMiddleware() with System tag should return system message", () => {
45
+ var _results$props, _results$props$danger;
46
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
47
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
48
+ const systemMessage = "system message";
49
+ const args = {
50
+ activity: {
51
+ text: systemMessage,
52
+ channelData: {
53
+ tags: [_Constants.Constants.systemMessageTag]
54
+ },
55
+ from: {
56
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
57
+ }
58
+ }
59
+ };
60
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
61
+ expect(_TelemetryHelper.TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
62
+ expect((_results$props = results().props) === null || _results$props === void 0 ? void 0 : (_results$props$danger = _results$props.dangerouslySetInnerHTML) === null || _results$props$danger === void 0 ? void 0 : _results$props$danger.__html).toEqual(systemMessage);
63
+ });
64
+ it("createActivityMiddleware() should escape html texts to prevent XSS attacks", () => {
65
+ var _results$props2, _results$props2$dange;
66
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
67
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
68
+ const systemMessage = "<img src='' onerror=\"alert('XSS attack')\"/>";
69
+ const args = {
70
+ activity: {
71
+ text: systemMessage,
72
+ channelData: {
73
+ tags: [_Constants.Constants.systemMessageTag]
74
+ },
75
+ from: {
76
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
77
+ }
78
+ }
79
+ };
80
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
81
+ expect(_TelemetryHelper.TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
82
+ expect((_results$props2 = results().props) === null || _results$props2 === void 0 ? void 0 : (_results$props2$dange = _results$props2.dangerouslySetInnerHTML) === null || _results$props2$dange === void 0 ? void 0 : _results$props2$dange.__html).toEqual("&lt;img src=&#39;&#39; onerror=&quot;alert(&#39;XSS attack&#39;)&quot;&#x2F;&gt;");
83
+ });
84
+ it("createActivityMiddleware() with QueuePosition tag should log QueuePosition message", () => {
85
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
86
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
87
+ const systemMessage = "system message";
88
+ const args = {
89
+ activity: {
90
+ text: systemMessage,
91
+ channelData: {
92
+ tags: [_Constants.Constants.systemMessageTag, _Constants.Constants.queuePositionMessageTag]
93
+ },
94
+ from: {
95
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
96
+ }
97
+ }
98
+ };
99
+ (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
100
+ expect(_TelemetryHelper.TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(1);
101
+ });
102
+ it("createActivityMiddleware() with same clientmessageid with next activity should return nothing", () => {
103
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
104
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
105
+ const systemMessage = "system message";
106
+ const args = {
107
+ activity: {
108
+ text: systemMessage,
109
+ channelData: {
110
+ tags: [_Constants.Constants.systemMessageTag],
111
+ clientmessageid: "1234"
112
+ },
113
+ from: {
114
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
115
+ }
116
+ },
117
+ nextVisibleActivity: {
118
+ channelData: {
119
+ clientmessageid: "1234"
120
+ }
121
+ }
122
+ };
123
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
124
+ expect(results()).toEqual(false);
125
+ });
126
+ it("createActivityMiddleware() with same messageid with next activity should return nothing", () => {
127
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
128
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
129
+ const systemMessage = "system message";
130
+ const args = {
131
+ activity: {
132
+ text: systemMessage,
133
+ channelData: {
134
+ tags: [_Constants.Constants.systemMessageTag]
135
+ },
136
+ from: {
137
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
138
+ },
139
+ messageid: "1234"
140
+ },
141
+ nextVisibleActivity: {
142
+ messageid: "1234"
143
+ }
144
+ };
145
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
146
+ expect(results()).toEqual(false);
147
+ });
148
+ it("createActivityMiddleware() should render normal user messages", () => {
149
+ var _results$props3, _results$props3$child, _results$props3$child2;
150
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
151
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
152
+ const userMessage = "Hello World";
153
+ const args = {
154
+ activity: {
155
+ text: userMessage,
156
+ channelId: "webchat",
157
+ channelData: {
158
+ isHtmlEncoded: false
159
+ },
160
+ from: {
161
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
162
+ },
163
+ type: _DirectLineActivityType.DirectLineActivityType.Message
164
+ }
165
+ };
166
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
167
+ expect((_results$props3 = results().props) === null || _results$props3 === void 0 ? void 0 : (_results$props3$child = _results$props3.children) === null || _results$props3$child === void 0 ? void 0 : (_results$props3$child2 = _results$props3$child.activity) === null || _results$props3$child2 === void 0 ? void 0 : _results$props3$child2.text).toEqual(userMessage);
168
+ });
169
+ it("createActivityMiddleware() should not render typing messages", () => {
170
+ var _results$activity;
171
+ spyOn(_TelemetryHelper.TelemetryHelper, "logActionEvent").and.callFake(() => false);
172
+ const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
173
+ const userMessage = "Hello World";
174
+ const args = {
175
+ activity: {
176
+ text: userMessage,
177
+ channelId: "webchat",
178
+ channelData: {
179
+ isHtmlEncoded: false
180
+ },
181
+ from: {
182
+ role: _DirectLineSenderRole.DirectLineSenderRole.User
183
+ },
184
+ type: _DirectLineActivityType.DirectLineActivityType.Typing
185
+ }
186
+ };
187
+ const results = (0, _activityMiddleware.createActivityMiddleware)()()(next)(args);
188
+ expect((_results$activity = results().activity) === null || _results$activity === void 0 ? void 0 : _results$activity.text).toEqual(userMessage);
189
+ });
190
+ });
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _WebChatActionType = require("../../enums/WebChatActionType");
8
+ var _Constants = require("../../../../../common/Constants");
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
10
+ const createMessageSequenceIdOverrideMiddleware = _ref => {
11
+ let {
12
+ dispatch
13
+ } = _ref;
14
+ return next => action => {
15
+ if (isApplicable(action)) {
16
+ return next(overrideSequenceIdWithOriginalMessageId(action));
17
+ }
18
+ return next(action);
19
+ };
20
+ };
21
+ const isApplicable = action => {
22
+ return action.type === _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY && isValidChannel(action) && isWebSequenceIdPresent(action) && lookupOriginalMessageId(action) !== undefined;
23
+ };
24
+ const isValidChannel = action => {
25
+ var _action$payload, _action$payload$activ;
26
+ return (action === null || action === void 0 ? void 0 : (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : (_action$payload$activ = _action$payload.activity) === null || _action$payload$activ === void 0 ? void 0 : _action$payload$activ.channelId) === _Constants.Constants.acsChannel;
27
+ };
28
+ const isChannelDataPresent = action => {
29
+ var _action$payload2, _action$payload2$acti, _action$payload3, _action$payload3$acti;
30
+ return (action === null || action === void 0 ? void 0 : (_action$payload2 = action.payload) === null || _action$payload2 === void 0 ? void 0 : (_action$payload2$acti = _action$payload2.activity) === null || _action$payload2$acti === void 0 ? void 0 : _action$payload2$acti.channelData) !== undefined && (action === null || action === void 0 ? void 0 : (_action$payload3 = action.payload) === null || _action$payload3 === void 0 ? void 0 : (_action$payload3$acti = _action$payload3.activity) === null || _action$payload3$acti === void 0 ? void 0 : _action$payload3$acti.channelData) !== null;
31
+ };
32
+ const isWebSequenceIdPresent = action => {
33
+ if (!isChannelDataPresent(action)) return false;
34
+ const channelData = action.payload.activity.channelData;
35
+ return Object.keys(channelData).some(key => {
36
+ return key === _Constants.Constants.WebchatSequenceIdAttribute;
37
+ });
38
+ };
39
+ const overrideSequenceIdWithOriginalMessageId = action => {
40
+ const originalMessageId = extractOriginalMessageId(action);
41
+ const channelData = action.payload.activity.channelData;
42
+ if (originalMessageId === undefined) return action;
43
+ Object.keys(channelData).forEach(function (key) {
44
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute && action.payload.activity.channelData[key] !== originalMessageId) {
45
+ action.payload.activity.channelData[key] = originalMessageId;
46
+ }
47
+ });
48
+ return action;
49
+ };
50
+
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
52
+ const extractOriginalMessageId = action => {
53
+ const originalMessageId = lookupOriginalMessageId(action);
54
+ if (typeof originalMessageId !== "string" || originalMessageId === "") {
55
+ return undefined;
56
+ }
57
+ const originalMessageIdResult = parseInt(originalMessageId);
58
+ return isNaN(originalMessageIdResult) ? undefined : originalMessageIdResult;
59
+ };
60
+ const lookupOriginalMessageId = action => {
61
+ var _action$payload4, _action$payload4$acti, _action$payload4$acti2, _action$payload4$acti3;
62
+ return action === null || action === void 0 ? void 0 : (_action$payload4 = action.payload) === null || _action$payload4 === void 0 ? void 0 : (_action$payload4$acti = _action$payload4.activity) === null || _action$payload4$acti === void 0 ? void 0 : (_action$payload4$acti2 = _action$payload4$acti.channelData) === null || _action$payload4$acti2 === void 0 ? void 0 : (_action$payload4$acti3 = _action$payload4$acti2.metadata) === null || _action$payload4$acti3 === void 0 ? void 0 : _action$payload4$acti3.OriginalMessageId;
63
+ };
64
+ var _default = createMessageSequenceIdOverrideMiddleware;
65
+ exports.default = _default;