@microsoft/omnichannel-chat-widget 0.1.0-main.cf54410 → 0.1.0-main.d48dae2

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 (184) hide show
  1. package/README.md +259 -0
  2. package/lib/cjs/assets/Audios.js +8 -0
  3. package/lib/cjs/assets/Icons.js +28 -0
  4. package/lib/cjs/common/Constants.js +52 -6
  5. package/lib/cjs/common/telemetry/TelemetryConstants.js +61 -5
  6. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  7. package/lib/cjs/common/telemetry/TelemetryManager.js +17 -6
  8. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  9. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  10. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
  11. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  12. package/lib/cjs/common/utils.js +76 -2
  13. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  14. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  15. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -42
  16. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +2 -2
  17. package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
  18. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  19. package/lib/cjs/components/headerstateful/HeaderStateful.js +13 -10
  20. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  21. package/lib/cjs/{assets/assets.d.js → components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js} +0 -0
  22. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  23. package/lib/cjs/components/livechatwidget/common/createAdapter.js +10 -1
  24. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +32 -32
  25. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +25 -24
  26. package/lib/cjs/components/livechatwidget/common/endChat.js +142 -51
  27. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +5 -0
  28. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +47 -9
  29. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +115 -22
  30. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  31. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -9
  32. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  33. package/lib/cjs/components/livechatwidget/common/startChat.js +176 -57
  34. package/lib/cjs/components/livechatwidget/common/startProactiveChat.js +3 -3
  35. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +246 -78
  36. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  37. package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +8 -0
  38. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  39. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +8 -13
  40. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +27 -5
  41. package/lib/cjs/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.js +1 -0
  42. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  43. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -0
  44. package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +51 -73
  45. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  46. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  47. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +25 -48
  48. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +3 -1
  49. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  50. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  51. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  52. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  53. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  54. package/lib/cjs/contexts/common/ConversationState.js +4 -2
  55. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
  56. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
  57. package/lib/cjs/contexts/createReducer.js +16 -10
  58. package/lib/cjs/controller/componentController.js +5 -5
  59. package/lib/cjs/plugins/newMessageEventHandler.js +99 -0
  60. package/lib/esm/assets/Audios.js +1 -0
  61. package/lib/esm/assets/Icons.js +11 -0
  62. package/lib/esm/common/Constants.js +48 -5
  63. package/lib/esm/common/telemetry/TelemetryConstants.js +57 -4
  64. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  65. package/lib/esm/common/telemetry/TelemetryManager.js +15 -6
  66. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  67. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  68. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  69. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  70. package/lib/esm/common/utils.js +55 -1
  71. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  72. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  73. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -38
  74. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +2 -2
  75. package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
  76. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  77. package/lib/esm/components/headerstateful/HeaderStateful.js +14 -11
  78. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  79. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  80. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  81. package/lib/esm/components/livechatwidget/common/createAdapter.js +10 -2
  82. package/lib/esm/components/livechatwidget/common/createMarkdown.js +32 -31
  83. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +23 -25
  84. package/lib/esm/components/livechatwidget/common/endChat.js +139 -50
  85. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -0
  86. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +42 -11
  87. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +104 -22
  88. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  89. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -9
  90. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  91. package/lib/esm/components/livechatwidget/common/startChat.js +170 -56
  92. package/lib/esm/components/livechatwidget/common/startProactiveChat.js +5 -5
  93. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +232 -79
  94. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  95. package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +6 -0
  96. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  97. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +9 -13
  98. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +26 -6
  99. package/lib/esm/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.js +1 -0
  100. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  101. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -0
  102. package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +2 -12
  103. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  104. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  105. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +23 -46
  106. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  107. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  108. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  109. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  110. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  111. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  112. package/lib/esm/contexts/common/ConversationState.js +4 -2
  113. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
  114. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
  115. package/lib/esm/contexts/createReducer.js +16 -9
  116. package/lib/esm/controller/componentController.js +5 -5
  117. package/lib/esm/plugins/newMessageEventHandler.js +82 -0
  118. package/lib/types/assets/Audios.d.ts +1 -0
  119. package/lib/types/assets/Icons.d.ts +11 -0
  120. package/lib/types/common/Constants.d.ts +26 -2
  121. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  122. package/lib/types/common/telemetry/TelemetryConstants.d.ts +44 -2
  123. package/lib/types/common/telemetry/TelemetryHelper.d.ts +3 -1
  124. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  125. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  126. package/lib/types/common/utils.d.ts +7 -1
  127. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +5 -2
  128. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  129. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  130. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +4 -1
  131. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  132. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  133. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  134. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  135. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  136. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  137. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  138. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  139. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +2 -1
  140. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  141. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -1
  142. package/lib/types/components/proactivechatpanestateful/interfaces/IProactiveChatNotificationConfig.d.ts +3 -0
  143. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  144. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -0
  145. package/lib/types/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.d.ts +1 -1
  146. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  147. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  148. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  149. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -2
  150. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  151. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  152. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  153. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  154. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  155. package/lib/types/contexts/common/ConversationState.d.ts +4 -2
  156. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  157. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
  158. package/lib/types/plugins/newMessageEventHandler.d.ts +2 -0
  159. package/package.json +9 -11
  160. package/lib/cjs/assets/audios/newMessageNotification.mp3 +0 -0
  161. package/lib/cjs/assets/icons/archiveIcon.svg +0 -3
  162. package/lib/cjs/assets/icons/audioIcon.svg +0 -6
  163. package/lib/cjs/assets/icons/blankIcon.svg +0 -6
  164. package/lib/cjs/assets/icons/excelIcon.svg +0 -6
  165. package/lib/cjs/assets/icons/imageIcon.svg +0 -6
  166. package/lib/cjs/assets/icons/oneNoteIcon.svg +0 -6
  167. package/lib/cjs/assets/icons/pdfIcon.svg +0 -6
  168. package/lib/cjs/assets/icons/powerpointIcon.svg +0 -6
  169. package/lib/cjs/assets/icons/videoIcon.svg +0 -6
  170. package/lib/cjs/assets/icons/visioIcon.svg +0 -6
  171. package/lib/cjs/assets/icons/wordIcon.svg +0 -6
  172. package/lib/esm/assets/assets.d.js +0 -0
  173. package/lib/esm/assets/audios/newMessageNotification.mp3 +0 -0
  174. package/lib/esm/assets/icons/archiveIcon.svg +0 -3
  175. package/lib/esm/assets/icons/audioIcon.svg +0 -6
  176. package/lib/esm/assets/icons/blankIcon.svg +0 -6
  177. package/lib/esm/assets/icons/excelIcon.svg +0 -6
  178. package/lib/esm/assets/icons/imageIcon.svg +0 -6
  179. package/lib/esm/assets/icons/oneNoteIcon.svg +0 -6
  180. package/lib/esm/assets/icons/pdfIcon.svg +0 -6
  181. package/lib/esm/assets/icons/powerpointIcon.svg +0 -6
  182. package/lib/esm/assets/icons/videoIcon.svg +0 -6
  183. package/lib/esm/assets/icons/visioIcon.svg +0 -6
  184. package/lib/esm/assets/icons/wordIcon.svg +0 -6
@@ -1,4 +1,4 @@
1
- import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
2
  import React, { useEffect, useState } from "react";
3
3
  import { createTimer, setFocusOnElement } from "../../common/utils";
4
4
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
@@ -24,11 +24,19 @@ export const ProactiveChatPaneStateful = props => {
24
24
  const handleProactiveChatInviteTimeout = () => {
25
25
  if (!timeoutRemoved) {
26
26
  setTimeoutRemoved(true);
27
+ dispatch({
28
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
29
+ payload: {
30
+ proactiveChatBodyTitle: "",
31
+ proactiveChatEnablePrechat: false,
32
+ proactiveChatInNewWindow: false
33
+ }
34
+ });
27
35
  dispatch({
28
36
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
29
37
  payload: ConversationState.Closed
30
38
  });
31
- TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
39
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
32
40
  Event: TelemetryEvent.ProactiveChatRejected,
33
41
  ElapsedTimeInMilliseconds: TelemetryTimers.LcwLoadToChatButtonTimer.milliSecondsElapsed,
34
42
  Description: "Proactive chat invitation timed out."
@@ -51,12 +59,12 @@ export const ProactiveChatPaneStateful = props => {
51
59
  if (state.appStates.proactiveChatStates.proactiveChatInNewWindow) {
52
60
  // TODO: BroadcastService: replace with the sdk broadcast service, when in place
53
61
  const startPopoutChatEvent = {
54
- eventName: "StartPopoutChat"
62
+ eventName: BroadcastEvent.ProactiveChatStartPopoutChat
55
63
  };
56
64
  BroadcastService.postMessage(startPopoutChatEvent);
57
65
  dispatch({
58
- type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
59
- payload: true
66
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
67
+ payload: ConversationState.Closed
60
68
  });
61
69
  } else if (((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.OutOfOperatingHours) === "True") {
62
70
  dispatch({
@@ -68,6 +76,10 @@ export const ProactiveChatPaneStateful = props => {
68
76
  payload: ConversationState.OutOfOffice
69
77
  });
70
78
  } else {
79
+ const proactiveChatStarted = {
80
+ eventName: BroadcastEvent.ProactiveChatStartChat
81
+ };
82
+ BroadcastService.postMessage(proactiveChatStarted);
71
83
  await startChat();
72
84
  }
73
85
  },
@@ -77,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
77
89
  Event: TelemetryEvent.ProactiveChatClosed,
78
90
  Description: "Proactive chat closed."
79
91
  });
92
+ dispatch({
93
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
94
+ payload: {
95
+ proactiveChatBodyTitle: "",
96
+ proactiveChatEnablePrechat: false,
97
+ proactiveChatInNewWindow: false
98
+ }
99
+ });
80
100
  dispatch({
81
101
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
82
102
  payload: ConversationState.Closed
83
103
  });
84
104
  },
85
105
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
86
- bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ?? (proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText)
106
+ bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ? state.appStates.proactiveChatStates.proactiveChatBodyTitle : proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText
87
107
  };
88
108
  useEffect(() => {
89
109
  setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));
@@ -8,11 +8,45 @@ import { defaultMiddlewareLocalizedTexts } from "./common/defaultProps/defaultMi
8
8
  import { defaultWebChatContainerStatefulProps } from "./common/defaultProps/defaultWebChatContainerStatefulProps";
9
9
  import { setFocusOnSendBox } from "../../common/utils";
10
10
  import { useChatContextStore } from "../..";
11
+ import { WebChatActionType } from "./webchatcontroller/enums/WebChatActionType";
12
+ import { WebChatStoreLoader } from "./webchatcontroller/WebChatStoreLoader";
13
+ import { Constants } from "../../common/Constants";
14
+ import { BotMagicCodeStore } from "./webchatcontroller/BotMagicCodeStore";
15
+ const broadcastChannelMessageEvent = "message";
16
+
17
+ const postActivity = activity => {
18
+ // eslint-disable-line @typescript-eslint/no-explicit-any
19
+ return {
20
+ type: WebChatActionType.DIRECT_LINE_POST_ACTIVITY,
21
+ meta: {
22
+ method: "keyboard"
23
+ },
24
+ payload: {
25
+ activity: {
26
+ channelData: undefined,
27
+ text: "",
28
+ textFormat: "plain",
29
+ type: Constants.message,
30
+ ...activity
31
+ }
32
+ }
33
+ };
34
+ };
35
+
36
+ const createMagicCodeSuccessResponse = signin => {
37
+ return {
38
+ signin,
39
+ result: "Success"
40
+ };
41
+ };
42
+
11
43
  export const WebChatContainerStateful = props => {
12
44
  const {
13
45
  BasicWebChat
14
46
  } = Components;
15
47
  const [state, dispatch] = useChatContextStore();
48
+ const magicCodeBroadcastChannel = new BroadcastChannel(Constants.magicCodeBroadcastChannel);
49
+ const magicCodeResponseBroadcastChannel = new BroadcastChannel(Constants.magicCodeResponseBroadcastChannel);
16
50
  const containerStyles = {
17
51
  root: Object.assign({}, defaultWebChatContainerStatefulProps.containerStyles, props === null || props === void 0 ? void 0 : props.containerStyles, {
18
52
  display: state.appStates.isMinimized ? "none" : ""
@@ -36,6 +70,44 @@ export const WebChatContainerStateful = props => {
36
70
  Event: TelemetryEvent.WebChatLoaded
37
71
  });
38
72
  }, []);
73
+ useEffect(() => {
74
+ const eventListener = event => {
75
+ // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-function
76
+ const {
77
+ data
78
+ } = event;
79
+
80
+ if (BotMagicCodeStore.botOAuthSignInId === data.signin) {
81
+ const {
82
+ signin,
83
+ code
84
+ } = data;
85
+ const text = `${code}`;
86
+ const action = postActivity({
87
+ text,
88
+ channelData: {
89
+ tags: [Constants.hiddenTag]
90
+ }
91
+ });
92
+ WebChatStoreLoader.store.dispatch(action);
93
+ const response = createMagicCodeSuccessResponse(signin);
94
+ magicCodeResponseBroadcastChannel.postMessage(response);
95
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
96
+ Event: TelemetryEvent.SuppressBotMagicCodeSucceeded
97
+ });
98
+ BotMagicCodeStore.botOAuthSignInId = "";
99
+ magicCodeBroadcastChannel.close();
100
+ magicCodeResponseBroadcastChannel.close();
101
+ } else {
102
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
103
+ Event: TelemetryEvent.SuppressBotMagicCodeFailed,
104
+ Description: "Signin does not match"
105
+ });
106
+ }
107
+ };
108
+
109
+ magicCodeBroadcastChannel.addEventListener(broadcastChannelMessageEvent, eventListener);
110
+ }, []);
39
111
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
40
112
  .ms_lcw_webchat_received_message img.webchat__markdown__external-link-icon {
41
113
  background-image : url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIzIDMgMTggMTgiICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik03LjI1MDEgNC41MDAxN0gxMC43NDk1QzExLjE2MzcgNC41MDAxNyAxMS40OTk1IDQuODM1OTYgMTEuNDk5NSA1LjI1MDE3QzExLjQ5OTUgNS42Mjk4NiAxMS4yMTczIDUuOTQzNjYgMTAuODUxMyA1Ljk5MzMyTDEwLjc0OTUgNi4wMDAxN0g3LjI0OTc0QzYuMDcwNzkgNS45OTk2MSA1LjEwMzQ5IDYuOTA2NTYgNS4wMDc4NiA4LjA2MTEyTDUuMDAwMjggOC4yMjAwM0w1LjAwMzEyIDE2Ljc1MDdDNS4wMDM0MyAxNy45NDE1IDUuOTI4ODUgMTguOTE2MSA3LjA5OTY2IDE4Ljk5NDlMNy4yNTM3MSAxOS4wMDAxTDE1Ljc1MTggMTguOTg4NEMxNi45NDE1IDE4Ljk4NjggMTcuOTE0NSAxOC4wNjIgMTcuOTkzNSAxNi44OTIzTDE3Ljk5ODcgMTYuNzM4NFYxMy4yMzIxQzE3Ljk5ODcgMTIuODE3OSAxOC4zMzQ1IDEyLjQ4MjEgMTguNzQ4NyAxMi40ODIxQzE5LjEyODQgMTIuNDgyMSAxOS40NDIyIDEyLjc2NDMgMTkuNDkxOCAxMy4xMzAzTDE5LjQ5ODcgMTMuMjMyMVYxNi43Mzg0QzE5LjQ5ODcgMTguNzQwNyAxNy45MjkzIDIwLjM3NjkgMTUuOTUyOCAyMC40ODI5TDE1Ljc1MzggMjAuNDg4NEw3LjI1ODI3IDIwLjUwMDFMNy4wNTQ5NSAyMC40OTQ5QzUuMTQyMzkgMjAuMzk1NCAzLjYwODk1IDE4Ljg2MjcgMy41MDgzNyAxNi45NTAyTDMuNTAzMTIgMTYuNzUxMUwzLjUwMDg5IDguMjUyN0wzLjUwNTI5IDguMDUwMkMzLjYwNTM5IDYuMTM3NDkgNS4xMzg2NyA0LjYwNDQ5IDcuMDUwOTYgNC41MDUyN0w3LjI1MDEgNC41MDAxN0gxMC43NDk1SDcuMjUwMVpNMTMuNzQ4MSAzLjAwMTQ2TDIwLjMwMTggMy4wMDE5N0wyMC40MDE0IDMuMDE1NzVMMjAuNTAyMiAzLjA0MzkzTDIwLjU1OSAzLjA2ODAzQzIwLjYxMjIgMy4wOTEyMiAyMC42NjM0IDMuMTIxNjMgMjAuNzExMSAzLjE1ODg1TDIwLjc4MDQgMy4yMjE1NkwyMC44NjQxIDMuMzIwMTRMMjAuOTE4MyAzLjQxMDI1TDIwLjk1NyAzLjUwMDU3TDIwLjk3NjIgMy41NjQ3NkwyMC45ODk4IDMuNjI4NjJMMjAuOTk5MiAzLjcyMjgyTDIwLjk5OTcgMTAuMjU1NEMyMC45OTk3IDEwLjY2OTYgMjAuNjYzOSAxMS4wMDU0IDIwLjI0OTcgMTEuMDA1NEMxOS44NyAxMS4wMDU0IDE5LjU1NjIgMTAuNzIzMiAxOS41MDY1IDEwLjM1NzFMMTkuNDk5NyAxMC4yNTU0TDE5LjQ5ODkgNS41NjE0N0wxMi4yNzk3IDEyLjc4NDdDMTIuMDEzNCAxMy4wNTEgMTEuNTk2OCAxMy4wNzUzIDExLjMwMzEgMTIuODU3NUwxMS4yMTkgMTIuNzg0OUMxMC45NTI3IDEyLjUxODcgMTAuOTI4NCAxMi4xMDIxIDExLjE0NjIgMTEuODA4NEwxMS4yMTg4IDExLjcyNDNMMTguNDM2OSA0LjUwMTQ2SDEzLjc0ODFDMTMuMzY4NCA0LjUwMTQ2IDEzLjA1NDYgNC4yMTkzMSAxMy4wMDUgMy44NTMyNEwxMi45OTgxIDMuNzUxNDZDMTIuOTk4MSAzLjM3MTc3IDEzLjI4MDMgMy4wNTc5NyAxMy42NDY0IDMuMDA4MzFMMTMuNzQ4MSAzLjAwMTQ2WiIgZmlsbD0iI0ZGRkZGRiIgLz48L3N2Zz4) !important;
@@ -4,6 +4,8 @@ import MockAdapter from "./mockadapter";
4
4
  export class MockChatSDK {
5
5
  constructor() {
6
6
  _defineProperty(this, "sleep", ms => new Promise(r => setTimeout(r, ms)));
7
+
8
+ _defineProperty(this, "isMockModeOn", true);
7
9
  }
8
10
 
9
11
  async startChat() {
@@ -14,6 +16,10 @@ export class MockChatSDK {
14
16
  return null;
15
17
  }
16
18
 
19
+ getChatToken() {
20
+ return null;
21
+ }
22
+
17
23
  createChatAdapter() {
18
24
  return new MockAdapter();
19
25
  } // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1,16 +1,6 @@
1
- import { BrowserVendor } from "../../webchatcontroller/enums/BrowserVendor";
1
+ import { ArchiveIcon, AudioIcon, BlankIcon, ExcelIcon, ImageIcon, OneNoteIcon, PDFIcon, PowerpointIcon, VideoIcon, VisioIcon, WordIcon } from "../../../../assets/Icons";
2
2
  import { getBrowserName, isChromiumEdge } from "./BrowserInfo";
3
- import ArchiveIcon from "../../../../assets/icons/archiveIcon.svg";
4
- import AudioIcon from "../../../../assets/icons/audioIcon.svg";
5
- import BlankIcon from "../../../../assets/icons/blankIcon.svg";
6
- import VideoIcon from "../../../../assets/icons/videoIcon.svg";
7
- import ImageIcon from "../../../../assets/icons/imageIcon.svg";
8
- import WordIcon from "../../../../assets/icons/wordIcon.svg";
9
- import OneNoteIcon from "../../../../assets/icons/oneNoteIcon.svg";
10
- import PowerpointIcon from "../../../../assets/icons/powerpointIcon.svg";
11
- import VisioIcon from "../../../../assets/icons/visioIcon.svg";
12
- import PDFIcon from "../../../../assets/icons/pdfIcon.svg";
13
- import ExcelIcon from "../../../../assets/icons/excelIcon.svg";
3
+ import { BrowserVendor } from "../../webchatcontroller/enums/BrowserVendor";
14
4
  import { Constants } from "../../../../common/Constants";
15
5
  const FileAttachmentIconMap = {
16
6
  "aac": AudioIcon,
@@ -0,0 +1,5 @@
1
+ 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; }
2
+
3
+ export class BotMagicCodeStore {}
4
+
5
+ _defineProperty(BotMagicCodeStore, "botOAuthSignInId", "");
@@ -5,59 +5,19 @@
5
5
  * 1. Renders system messages differently, according to Microsoft LiveChatWidget styles
6
6
  * 2. Changes the font size of user messages
7
7
  * 3. Decodes certain html characters that came through from chat services
8
- * 4. Triggers end conversation sequence when the chat thread is deleted
9
8
  ******/
10
- import React from "react";
9
+ import { LogLevel, TelemetryEvent } from "../../../../../common/telemetry/TelemetryConstants";
11
10
  import { Constants } from "../../../../../common/Constants";
12
11
  import { DirectLineActivityType } from "../../enums/DirectLineActivityType";
13
12
  import { DirectLineSenderRole } from "../../enums/DirectLineSenderRole";
14
13
  import { MessageTypes } from "../../enums/MessageType";
14
+ import React from "react";
15
+ import { TelemetryHelper } from "../../../../../common/telemetry/TelemetryHelper";
15
16
  import { defaultSystemMessageStyles } from "./defaultStyles/defaultSystemMessageStyles";
16
17
  import { defaultUserMessageStyles } from "./defaultStyles/defaultUserMessageStyles";
17
18
  import { escapeHtml } from "../../../../../common/utils";
18
- import { TelemetryHelper } from "../../../../../common/telemetry/TelemetryHelper";
19
- import { LogLevel, TelemetryEvent } from "../../../../../common/telemetry/TelemetryConstants";
20
19
  const loggedSystemMessages = new Array(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
20
 
22
- const handleThreadUpdate = channelData => {
23
- var _channelData$properti, _channelData$properti2;
24
-
25
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
26
- Event: TelemetryEvent.IC3ThreadUpdateEventReceived,
27
- Description: "IC3 ThreadUpdateEvent Received"
28
- });
29
-
30
- const postConversationEndedAction = () => {
31
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
32
- Event: TelemetryEvent.ConversationEndedThreadEventReceived,
33
- Description: "Conversation is ended by agent side or by timeout."
34
- });
35
- }; // If the Thread is deleted, then display post conversation survey if enabled.
36
-
37
-
38
- const isThreadDeleted = (channelData === null || channelData === void 0 ? void 0 : (_channelData$properti = channelData.properties) === null || _channelData$properti === void 0 ? void 0 : (_channelData$properti2 = _channelData$properti.isdeleted) === null || _channelData$properti2 === void 0 ? void 0 : _channelData$properti2.toLowerCase()) === Constants.true;
39
-
40
- if (isThreadDeleted) {
41
- postConversationEndedAction();
42
- return;
43
- } //check if customer is still in the thread
44
-
45
-
46
- if (channelData.members && channelData.members.length > 0) {
47
- for (let i = 0; i < channelData.members.length; i++) {
48
- const id = channelData.members[i].id;
49
- const tag = channelData.members[i].tag; // In case of ACS customer is not removed from thread and has "left" tag
50
-
51
- if (id.startsWith(Constants.visitorIdPrefix) && tag !== Constants.left) {
52
- return;
53
- }
54
- }
55
- }
56
-
57
- postConversationEndedAction();
58
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
-
60
-
61
21
  const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
62
22
  var _card$activity, _card$activity$channe, _card$activity$channe2, _card$activity2, _card$activity2$chann, _card$activity3, _card$activity3$chann, _card$activity3$chann2, _card$activity4, _card$activity4$chann, _card$activity5, _card$activity5$chann, _card$nextVisibleActi, _card$nextVisibleActi2, _card$activity6, _card$activity6$chann, _card$activity7, _card$nextVisibleActi3, _card$activity8;
63
23
 
@@ -94,6 +54,16 @@ const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
94
54
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
55
 
96
56
 
57
+ const isTagIncluded = (card, tag) => {
58
+ return isDataTagsPresent(card) && card.activity.channelData.tags.includes(tag);
59
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+
61
+
62
+ const isDataTagsPresent = card => {
63
+ return card && card.activity && card.activity.channelData && card.activity.channelData.tags && card.activity.channelData.tags.length > 0;
64
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+
66
+
97
67
  export const createActivityMiddleware = (systemMessageStyleProps, userMessageStyleProps) => () => next => function () {
98
68
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
99
69
  args[_key] = arguments[_key];
@@ -102,19 +72,26 @@ export const createActivityMiddleware = (systemMessageStyleProps, userMessageSty
102
72
  const [card] = args;
103
73
 
104
74
  if (card.activity) {
105
- var _card$activity$from, _card$activity$channe4, _card$activity$channe5;
75
+ var _card$activity$from;
106
76
 
107
77
  if (((_card$activity$from = card.activity.from) === null || _card$activity$from === void 0 ? void 0 : _card$activity$from.role) === DirectLineSenderRole.Channel) {
108
78
  var _card$activity$channe3;
109
79
 
110
80
  if (((_card$activity$channe3 = card.activity.channelData) === null || _card$activity$channe3 === void 0 ? void 0 : _card$activity$channe3.type) === MessageTypes.Thread) {
111
- handleThreadUpdate(card.activity.channelData);
81
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
82
+ Event: TelemetryEvent.IC3ThreadUpdateEventReceived,
83
+ Description: "IC3 ThreadUpdateEvent Received"
84
+ });
112
85
  }
113
86
 
114
87
  return () => false;
115
88
  }
116
89
 
117
- if ((_card$activity$channe4 = card.activity.channelData) !== null && _card$activity$channe4 !== void 0 && (_card$activity$channe5 = _card$activity$channe4.tags) !== null && _card$activity$channe5 !== void 0 && _card$activity$channe5.includes(Constants.systemMessageTag)) {
90
+ if (isTagIncluded(card, Constants.hiddenTag)) {
91
+ return () => false;
92
+ }
93
+
94
+ if (isTagIncluded(card, Constants.systemMessageTag)) {
118
95
  return handleSystemMessage(next, args, card, systemMessageStyleProps);
119
96
  } else if (card.activity.text && card.activity.type === DirectLineActivityType.Message) {
120
97
  if (!card.activity.channelData.isHtmlEncoded && card.activity.channelId === Constants.webchatChannelId) {
@@ -8,6 +8,7 @@
8
8
  import { Constants, MimeTypes, WebChatMiddlewareConstants } from "../../../../../common/Constants";
9
9
  import React from "react";
10
10
  import { getFileAttachmentIconData, isInlineMediaSupported } from "../../../common/utils/FileAttachmentIconManager";
11
+ import { BroadcastEvent } from "../../../../../common/telemetry/TelemetryConstants";
11
12
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
12
13
  import { WebChatActionType } from "../../enums/WebChatActionType";
13
14
  import { defaultAttachmentAdaptiveCardStyles } from "./defaultStyles/defaultAtttachmentAdaptiveCardStyles";
@@ -187,7 +188,7 @@ const createAttachmentMiddleware = enableInlinePlaying => {
187
188
  } catch (e) {
188
189
  const errorData = "Unable to parse the adaptive card format";
189
190
  BroadcastService.postMessage({
190
- eventName: "InvalidAdaptiveCardFormat",
191
+ eventName: BroadcastEvent.InvalidAdaptiveCardFormat,
191
192
  payload: {
192
193
  Message: errorData,
193
194
  ExceptionDetails: e
@@ -0,0 +1,41 @@
1
+ import { BotMagicCodeStore } from "../../BotMagicCodeStore";
2
+ var CardActionType;
3
+
4
+ (function (CardActionType) {
5
+ CardActionType["OpenUrl"] = "openUrl";
6
+ CardActionType["SignIn"] = "signin";
7
+ })(CardActionType || (CardActionType = {}));
8
+
9
+ const validCardActionTypes = [CardActionType.OpenUrl, CardActionType.SignIn];
10
+ const botOauthUrlRegex = /[\S]+.botframework.com\/api\/oauth\/signin\?signin=([\S]+)/;
11
+ export const createCardActionMiddleware = botMagicCodeConfig => {
12
+ const cardActionMiddleware = () => next => function () {
13
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14
+ args[_key] = arguments[_key];
15
+ }
16
+
17
+ // eslint-disable-line @typescript-eslint/no-explicit-any
18
+ const [card] = args;
19
+
20
+ if (card.cardAction && validCardActionTypes.indexOf(card.cardAction.type) >= 0 && card.cardAction.value) {
21
+ // Override signin url only if fwdUrl is valid & feature is enabled
22
+ if ((botMagicCodeConfig === null || botMagicCodeConfig === void 0 ? void 0 : botMagicCodeConfig.disabled) === true && botMagicCodeConfig !== null && botMagicCodeConfig !== void 0 && botMagicCodeConfig.fwdUrl) {
23
+ const baseUrl = window.location.origin;
24
+ const result = botOauthUrlRegex.exec(card.cardAction.value);
25
+
26
+ if (result) {
27
+ BotMagicCodeStore.botOAuthSignInId = `${result[1]}`;
28
+ } // fwdUrl must be on the same domain as the chat widget
29
+
30
+
31
+ if (botMagicCodeConfig !== null && botMagicCodeConfig !== void 0 && botMagicCodeConfig.fwdUrl.startsWith(baseUrl)) {
32
+ card.cardAction.value += `&fwdUrl=${botMagicCodeConfig.fwdUrl}`;
33
+ }
34
+ }
35
+ }
36
+
37
+ return next(...args);
38
+ };
39
+
40
+ return cardActionMiddleware;
41
+ };
@@ -0,0 +1,94 @@
1
+ import "@testing-library/jest-dom/extend-expect";
2
+ import { createCardActionMiddleware } from "./cardActionMiddleware";
3
+ describe("cardActionMiddleware test", () => {
4
+ it("createCardActionMiddleware() with undefined botMagicCodeConfig should not change the sign in card url", () => {
5
+ const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
6
+
7
+
8
+ const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
9
+ const args = {
10
+ cardAction: {
11
+ type: "signin",
12
+ value: signInUrl
13
+ }
14
+ };
15
+ const results = createCardActionMiddleware(undefined)()(next)(args);
16
+ expect(signInUrl).toEqual(results.cardAction.value);
17
+ });
18
+ it("createCardActionMiddleware() with botMagicCode enabled should not change the sign in card url", () => {
19
+ const botMagicCodeConfig = {
20
+ disabled: false
21
+ };
22
+
23
+ const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
24
+
25
+
26
+ const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
27
+ const args = {
28
+ cardAction: {
29
+ type: "signin",
30
+ value: signInUrl
31
+ }
32
+ };
33
+ const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
34
+ expect(args.cardAction.value).toEqual(results.cardAction.value);
35
+ });
36
+ it("createCardActionMiddleware() with botMagicCode disabled & no fwdUrl should not change the sign in card url", () => {
37
+ const botMagicCodeConfig = {
38
+ disabled: true
39
+ };
40
+
41
+ const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
42
+
43
+
44
+ const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
45
+ const args = {
46
+ cardAction: {
47
+ type: "signin",
48
+ value: signInUrl
49
+ }
50
+ };
51
+ const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
52
+ expect(args.cardAction.value).toEqual(results.cardAction.value);
53
+ });
54
+ it("createCardActionMiddleware() with botMagicCode disabled & fwdUrl should append the fwdUrl in the sign in card url", () => {
55
+ const botMagicCodeConfig = {
56
+ disabled: true,
57
+ fwdUrl: "http://localhost/forwarder.html"
58
+ };
59
+
60
+ const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
61
+
62
+
63
+ const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
64
+ const args = {
65
+ cardAction: {
66
+ type: "signin",
67
+ value: signInUrl
68
+ }
69
+ };
70
+ const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
71
+ expect(signInUrl === results.cardAction.value).toBe(false);
72
+ expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(true);
73
+ });
74
+ it("createCardActionMiddleware() should not append fwdUrl if fwdUrl & sign in card url are not in the same domain", () => {
75
+ const botMagicCodeConfig = {
76
+ disabled: true,
77
+ fwdUrl: "https://localhost/forwarder.html"
78
+ };
79
+
80
+ const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
81
+
82
+
83
+ const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
84
+ const args = {
85
+ cardAction: {
86
+ type: "signin",
87
+ value: signInUrl
88
+ }
89
+ };
90
+ const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
91
+ expect(signInUrl === results.cardAction.value).toBe(true);
92
+ expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(false);
93
+ });
94
+ });
@@ -0,0 +1,107 @@
1
+ import { WebChatActionType } from "../../enums/WebChatActionType";
2
+ import { Constants } from "../../../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
3
+
4
+ const createMessageTimeStampMiddleware = _ref => {
5
+ let {
6
+ dispatch
7
+ } = _ref;
8
+ return next => action => {
9
+ if (isApplicable(action)) {
10
+ return next(evaluateTagsAndOverrideTimeStamp(action));
11
+ }
12
+
13
+ return next(action);
14
+ };
15
+ };
16
+
17
+ const isApplicable = action => {
18
+ return action.type === WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY && isPVAConversation(action) && isPayloadValid(action) && isValidChannel(action);
19
+ };
20
+
21
+ const isPayloadValid = action => {
22
+ var _action$payload;
23
+
24
+ return action === null || action === void 0 ? void 0 : (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.activity;
25
+ };
26
+
27
+ const isValidChannel = action => {
28
+ var _action$payload2, _action$payload2$acti;
29
+
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.channelId) === Constants.acsChannel;
31
+ };
32
+
33
+ const isPVAConversation = action => {
34
+ return !isTagIncluded(action, Constants.systemMessageTag) && !isTagIncluded(action, Constants.publicMessageTag) && !isRoleUserOn(action);
35
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+
37
+
38
+ const isTagIncluded = (action, tag) => {
39
+ return isDataTagsPresent(action) && action.payload.activity.channelData.tags.includes(tag);
40
+ };
41
+
42
+ const isRoleUserOn = action => {
43
+ var _action$payload3, _action$payload3$acti, _action$payload3$acti2;
44
+
45
+ return (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$acti2 = _action$payload3$acti.from) === null || _action$payload3$acti2 === void 0 ? void 0 : _action$payload3$acti2.role) === Constants.userMessageTag;
46
+ };
47
+
48
+ const overrideTimeStamp = (timestampOriginal, timeStampNew) => {
49
+ return isTimestampValid(timeStampNew) ? timeStampNew : timestampOriginal;
50
+ };
51
+
52
+ const isTimestampValid = timeStamp => {
53
+ const regex = /(\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])(T)(\d{2})(:{1})(\d{2})(:{1})(\d{2})(.\d+)([Z]{1}))/;
54
+ return regex.test(timeStamp);
55
+ };
56
+
57
+ const isDataTagsPresent = action => {
58
+ var _action$payload4, _action$payload4$acti, _action$payload4$acti2;
59
+
60
+ 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$acti2.tags) && action.payload.activity.channelData.tags.length > 0;
61
+ };
62
+
63
+ const evaluateTagsAndOverrideTimeStamp = action => {
64
+ const tagValue = tagLookup(action, Constants.prefixTimestampTag);
65
+
66
+ if (tagValue) {
67
+ const newTimestamp = extractTimeStamp(tagValue);
68
+ action.payload.activity.timestamp = overrideTimeStamp(action.payload.activity.timestamp, newTimestamp);
69
+ }
70
+
71
+ return action;
72
+ };
73
+
74
+ const extractTimeStamp = timeStamp => {
75
+ if (timeStamp && timeStamp.length > 0) {
76
+ const ts = timeStamp.split(Constants.prefixTimestampTag);
77
+
78
+ if (ts && ts.length > 1) {
79
+ return ts[1];
80
+ }
81
+ }
82
+
83
+ return timeStamp;
84
+ };
85
+
86
+ const tagLookup = (action, tag) => {
87
+ if (!isDataTagsPresent(action)) {
88
+ return null;
89
+ }
90
+
91
+ const tags = action.payload.activity.channelData.tags;
92
+ let value;
93
+
94
+ if (tags && tags.length > 0) {
95
+ for (let i = 0; i < tags.length; i++) {
96
+ value = tags[i];
97
+
98
+ if (value && value.indexOf(tag) > -1) {
99
+ return value;
100
+ }
101
+ }
102
+ }
103
+
104
+ return null;
105
+ };
106
+
107
+ export default createMessageTimeStampMiddleware;
@@ -17,22 +17,22 @@ const createConversationEndMiddleware = conversationEndCallback => _ref => {
17
17
  var _action$payload;
18
18
 
19
19
  if ((action === null || action === void 0 ? void 0 : action.type) == WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY && (_action$payload = action.payload) !== null && _action$payload !== void 0 && _action$payload.activity) {
20
- var _activity$from, _activity$from2, _activity$channelData5, _activity$channelData6;
20
+ var _activity$from, _activity$from2, _activity$channelData7, _activity$channelData8;
21
21
 
22
22
  const activity = action.payload.activity;
23
23
 
24
24
  if (((_activity$from = activity.from) === null || _activity$from === void 0 ? void 0 : _activity$from.role) === DirectLineSenderRole.Bot && activity.channelId === "ACS_CHANNEL") {
25
- var _activity$channelData, _activity$channelData2, _activity$channelData3, _activity$channelData4;
25
+ var _activity$channelData, _activity$channelData2, _activity$channelData3, _activity$channelData4, _activity$channelData5, _activity$channelData6;
26
26
 
27
27
  // ACS
28
- if ((_activity$channelData = activity.channelData) !== null && _activity$channelData !== void 0 && (_activity$channelData2 = _activity$channelData.tags) !== null && _activity$channelData2 !== void 0 && _activity$channelData2.includes(Constants.systemMessageTag) && (_activity$channelData3 = activity.channelData) !== null && _activity$channelData3 !== void 0 && (_activity$channelData4 = _activity$channelData3.tags) !== null && _activity$channelData4 !== void 0 && _activity$channelData4.includes(Constants.agentEndConversationMessageTag)) {
28
+ if ((_activity$channelData = activity.channelData) !== null && _activity$channelData !== void 0 && (_activity$channelData2 = _activity$channelData.tags) !== null && _activity$channelData2 !== void 0 && _activity$channelData2.includes(Constants.systemMessageTag) && ((_activity$channelData3 = activity.channelData) !== null && _activity$channelData3 !== void 0 && (_activity$channelData4 = _activity$channelData3.tags) !== null && _activity$channelData4 !== void 0 && _activity$channelData4.includes(Constants.agentEndConversationMessageTag) || (_activity$channelData5 = activity.channelData) !== null && _activity$channelData5 !== void 0 && (_activity$channelData6 = _activity$channelData5.tags) !== null && _activity$channelData6 !== void 0 && _activity$channelData6.includes(Constants.supervisorForceCloseMessageTag))) {
29
29
  conversationEndCallback();
30
30
  }
31
- } else if (((_activity$from2 = activity.from) === null || _activity$from2 === void 0 ? void 0 : _activity$from2.role) === DirectLineSenderRole.Channel && ((_activity$channelData5 = activity.channelData) === null || _activity$channelData5 === void 0 ? void 0 : _activity$channelData5.type) === MessageTypes.Thread && (_activity$channelData6 = activity.channelData) !== null && _activity$channelData6 !== void 0 && _activity$channelData6.properties) {
32
- var _activity$channelData7, _activity$channelData8, _activity$channelData9, _activity$channelData10;
31
+ } else if (((_activity$from2 = activity.from) === null || _activity$from2 === void 0 ? void 0 : _activity$from2.role) === DirectLineSenderRole.Channel && ((_activity$channelData7 = activity.channelData) === null || _activity$channelData7 === void 0 ? void 0 : _activity$channelData7.type) === MessageTypes.Thread && (_activity$channelData8 = activity.channelData) !== null && _activity$channelData8 !== void 0 && _activity$channelData8.properties) {
32
+ var _activity$channelData9, _activity$channelData10, _activity$channelData11, _activity$channelData12;
33
33
 
34
34
  // IC3
35
- if (((_activity$channelData7 = activity.channelData) === null || _activity$channelData7 === void 0 ? void 0 : (_activity$channelData8 = _activity$channelData7.properties) === null || _activity$channelData8 === void 0 ? void 0 : _activity$channelData8.isdeleted) === Constants.truePascal || !((_activity$channelData9 = activity.channelData) !== null && _activity$channelData9 !== void 0 && (_activity$channelData10 = _activity$channelData9.properties) !== null && _activity$channelData10 !== void 0 && _activity$channelData10.containsExternalEntitiesListeningAll)) {
35
+ if (((_activity$channelData9 = activity.channelData) === null || _activity$channelData9 === void 0 ? void 0 : (_activity$channelData10 = _activity$channelData9.properties) === null || _activity$channelData10 === void 0 ? void 0 : _activity$channelData10.isdeleted) === Constants.truePascal || !((_activity$channelData11 = activity.channelData) !== null && _activity$channelData11 !== void 0 && (_activity$channelData12 = _activity$channelData11.properties) !== null && _activity$channelData12 !== void 0 && _activity$channelData12.containsExternalEntitiesListeningAll)) {
36
36
  conversationEndCallback();
37
37
  }
38
38
  }