@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.cda7a31

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 (179) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +50 -6
  3. package/lib/cjs/common/storage/default/defaultCacheManager.js +34 -0
  4. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +114 -0
  5. package/lib/cjs/common/storage/default/defaultInMemoryDataStore.js +86 -0
  6. package/lib/cjs/common/telemetry/TelemetryConstants.js +51 -3
  7. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  8. package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
  9. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  10. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  11. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +54 -21
  12. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  13. package/lib/cjs/common/utils.js +89 -2
  14. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  15. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  16. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -44
  17. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
  18. package/lib/cjs/components/footerstateful/FooterStateful.js +6 -15
  19. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  20. package/lib/cjs/components/headerstateful/HeaderStateful.js +15 -14
  21. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  22. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  23. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  24. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  25. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  26. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  27. package/lib/cjs/components/livechatwidget/common/authHelper.js +65 -0
  28. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  29. package/lib/cjs/components/livechatwidget/common/createFooter.js +7 -16
  30. package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
  31. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  32. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +36 -20
  33. package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
  34. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  35. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -3
  36. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +144 -39
  37. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  38. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  39. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  40. package/lib/cjs/components/livechatwidget/common/startChat.js +166 -50
  41. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +310 -73
  42. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  43. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +6 -4
  44. package/lib/cjs/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
  45. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  46. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  47. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +98 -2
  48. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
  49. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
  50. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  51. package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  52. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  53. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  54. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  55. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
  56. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  57. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  58. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +10 -0
  59. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  60. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  61. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  62. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +11 -8
  63. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +15 -6
  64. package/lib/cjs/contexts/createReducer.js +26 -12
  65. package/lib/cjs/controller/componentController.js +3 -3
  66. package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
  67. package/lib/esm/common/Constants.js +46 -5
  68. package/lib/esm/common/storage/default/defaultCacheManager.js +19 -0
  69. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +102 -0
  70. package/lib/esm/common/storage/default/defaultInMemoryDataStore.js +71 -0
  71. package/lib/esm/common/telemetry/TelemetryConstants.js +51 -3
  72. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  73. package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
  74. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  75. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  76. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +55 -17
  77. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  78. package/lib/esm/common/utils.js +64 -1
  79. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  80. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  81. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -42
  82. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
  83. package/lib/esm/components/footerstateful/FooterStateful.js +6 -15
  84. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  85. package/lib/esm/components/headerstateful/HeaderStateful.js +15 -14
  86. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  87. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  88. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  89. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  90. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  91. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  92. package/lib/esm/components/livechatwidget/common/authHelper.js +50 -0
  93. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  94. package/lib/esm/components/livechatwidget/common/createFooter.js +4 -15
  95. package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
  96. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  97. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +36 -21
  98. package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
  99. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  100. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +25 -5
  101. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +134 -41
  102. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  103. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  104. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  105. package/lib/esm/components/livechatwidget/common/startChat.js +161 -53
  106. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +298 -78
  107. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  108. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +5 -4
  109. package/lib/esm/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
  110. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  111. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  112. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +87 -2
  113. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
  114. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
  115. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  116. package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  117. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  118. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  119. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  120. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
  121. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  122. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  123. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +3 -0
  124. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  125. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  126. package/lib/esm/contexts/common/ConversationState.js +3 -2
  127. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +11 -8
  128. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +13 -6
  129. package/lib/esm/contexts/createReducer.js +26 -11
  130. package/lib/esm/controller/componentController.js +3 -3
  131. package/lib/esm/plugins/newMessageEventHandler.js +10 -12
  132. package/lib/types/common/Constants.d.ts +25 -2
  133. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  134. package/lib/types/common/storage/default/defaultCacheManager.d.ts +4 -0
  135. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -0
  136. package/lib/types/common/storage/default/defaultInMemoryDataStore.d.ts +6 -0
  137. package/lib/types/common/telemetry/TelemetryConstants.d.ts +36 -5
  138. package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
  139. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  140. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  141. package/lib/types/common/utils.d.ts +8 -1
  142. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  143. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  144. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  145. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  146. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  147. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  148. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  149. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  150. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  151. package/lib/types/components/livechatwidget/common/authHelper.d.ts +5 -0
  152. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  153. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  154. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  155. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  156. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  157. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  158. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +4 -3
  159. package/lib/types/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.d.ts +2 -2
  160. package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +4 -0
  161. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  162. package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
  163. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  164. package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
  165. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  166. package/lib/types/components/webchatcontainerstateful/interfaces/IRenderingMiddlewareProps.d.ts +2 -1
  167. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
  168. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  169. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
  170. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  171. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  172. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.d.ts +2 -0
  173. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  174. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  175. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  176. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +4 -2
  177. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +12 -9
  178. package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +1 -2
  179. package/package.json +9 -9
@@ -1,9 +1,8 @@
1
- import { Constants, HtmlAttributeNames, Regex } from "../../common/Constants";
1
+ import { HtmlAttributeNames, Regex } from "../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
3
3
  import React, { useEffect } from "react";
4
- import { extractPreChatSurveyResponseValues, findAllFocusableElement, parseAdaptiveCardPayload } from "../../common/utils";
4
+ import { extractPreChatSurveyResponseValues, findAllFocusableElement, getStateFromCache, isUndefinedOrEmpty, parseAdaptiveCardPayload } from "../../common/utils";
5
5
  import { ConversationState } from "../../contexts/common/ConversationState";
6
- import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
7
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
8
7
  import { PreChatSurveyPane } from "@microsoft/omnichannel-chat-components";
9
8
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
@@ -67,13 +66,12 @@ export const PreChatSurveyPaneStateful = props => {
67
66
  });
68
67
 
69
68
  try {
70
- var _DataStoreManager$cli, _persistedState$domai;
69
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
71
70
 
72
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
73
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
74
- let optionalParams = {};
71
+ const persistedState = getStateFromCache(((_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) ?? "", state.domainStates.widgetInstanceId ?? "");
72
+ let optionalParams = {}; //Connect to Active chats and chat is not popout
75
73
 
76
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
74
+ if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : _persistedState$domai.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active && !state.appStates.skipChatButtonRendering) {
77
75
  var _persistedState$domai2;
78
76
 
79
77
  optionalParams = {
@@ -83,9 +81,7 @@ export const PreChatSurveyPaneStateful = props => {
83
81
  } else {
84
82
  const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
85
83
  optionalParams = {
86
- initContext: {
87
- preChatResponse: prechatResponseValues
88
- }
84
+ preChatResponse: prechatResponseValues
89
85
  };
90
86
  setPreChatResponseEmail(values);
91
87
  await initStartChat(optionalParams);
@@ -24,6 +24,14 @@ 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
@@ -81,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
81
89
  Event: TelemetryEvent.ProactiveChatClosed,
82
90
  Description: "Proactive chat closed."
83
91
  });
92
+ dispatch({
93
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
94
+ payload: {
95
+ proactiveChatBodyTitle: "",
96
+ proactiveChatEnablePrechat: false,
97
+ proactiveChatInNewWindow: false
98
+ }
99
+ });
84
100
  dispatch({
85
101
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
86
102
  payload: ConversationState.Closed
87
103
  });
88
104
  },
89
105
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
90
- 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
91
107
  };
92
108
  useEffect(() => {
93
109
  setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));
@@ -2,17 +2,56 @@ import { Stack } from "@fluentui/react";
2
2
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
3
3
  import React, { useEffect } from "react";
4
4
  import { Components } from "botframework-webchat";
5
+ import { BroadcastChannel } from "broadcast-channel";
5
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
6
7
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
7
8
  import { defaultMiddlewareLocalizedTexts } from "./common/defaultProps/defaultMiddlewareLocalizedTexts";
8
9
  import { defaultWebChatContainerStatefulProps } from "./common/defaultProps/defaultWebChatContainerStatefulProps";
9
10
  import { setFocusOnSendBox } from "../../common/utils";
10
11
  import { useChatContextStore } from "../..";
12
+ import { WebChatActionType } from "./webchatcontroller/enums/WebChatActionType";
13
+ import { WebChatStoreLoader } from "./webchatcontroller/WebChatStoreLoader";
14
+ import { Constants } from "../../common/Constants";
15
+ import { BotMagicCodeStore } from "./webchatcontroller/BotMagicCodeStore";
16
+ import { defaultAdaptiveCardStyles } from "./common/defaultStyles/defaultAdaptiveCardStyles";
17
+ import { defaultReceivedMessageAnchorStyles } from "./webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles";
18
+ const broadcastChannelMessageEvent = "message";
19
+
20
+ const postActivity = activity => {
21
+ // eslint-disable-line @typescript-eslint/no-explicit-any
22
+ return {
23
+ type: WebChatActionType.DIRECT_LINE_POST_ACTIVITY,
24
+ meta: {
25
+ method: "keyboard"
26
+ },
27
+ payload: {
28
+ activity: {
29
+ channelData: undefined,
30
+ text: "",
31
+ textFormat: "plain",
32
+ type: Constants.message,
33
+ ...activity
34
+ }
35
+ }
36
+ };
37
+ };
38
+
39
+ const createMagicCodeSuccessResponse = signin => {
40
+ return {
41
+ signin,
42
+ result: "Success"
43
+ };
44
+ };
45
+
11
46
  export const WebChatContainerStateful = props => {
47
+ var _props$adaptiveCardSt, _props$adaptiveCardSt2, _props$renderingMiddl, _props$renderingMiddl2, _props$renderingMiddl3, _props$renderingMiddl4;
48
+
12
49
  const {
13
50
  BasicWebChat
14
51
  } = Components;
15
52
  const [state, dispatch] = useChatContextStore();
53
+ const magicCodeBroadcastChannel = new BroadcastChannel(Constants.magicCodeBroadcastChannel);
54
+ const magicCodeResponseBroadcastChannel = new BroadcastChannel(Constants.magicCodeResponseBroadcastChannel);
16
55
  const containerStyles = {
17
56
  root: Object.assign({}, defaultWebChatContainerStatefulProps.containerStyles, props === null || props === void 0 ? void 0 : props.containerStyles, {
18
57
  display: state.appStates.isMinimized ? "none" : ""
@@ -36,11 +75,57 @@ export const WebChatContainerStateful = props => {
36
75
  Event: TelemetryEvent.WebChatLoaded
37
76
  });
38
77
  }, []);
78
+ useEffect(() => {
79
+ const eventListener = event => {
80
+ // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-function
81
+ const {
82
+ data
83
+ } = event;
84
+
85
+ if (BotMagicCodeStore.botOAuthSignInId === data.signin) {
86
+ const {
87
+ signin,
88
+ code
89
+ } = data;
90
+ const text = `${code}`;
91
+ const action = postActivity({
92
+ text,
93
+ channelData: {
94
+ tags: [Constants.hiddenTag]
95
+ }
96
+ });
97
+ WebChatStoreLoader.store.dispatch(action);
98
+ const response = createMagicCodeSuccessResponse(signin);
99
+ magicCodeResponseBroadcastChannel.postMessage(response);
100
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
101
+ Event: TelemetryEvent.SuppressBotMagicCodeSucceeded
102
+ });
103
+ BotMagicCodeStore.botOAuthSignInId = "";
104
+ magicCodeBroadcastChannel.close();
105
+ magicCodeResponseBroadcastChannel.close();
106
+ } else {
107
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
108
+ Event: TelemetryEvent.SuppressBotMagicCodeFailed,
109
+ Description: "Signin does not match"
110
+ });
111
+ }
112
+ };
113
+
114
+ magicCodeBroadcastChannel.addEventListener(broadcastChannelMessageEvent, eventListener);
115
+ }, []);
39
116
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
117
+
118
+ .webchat__bubble__content>div#ms_lcw_webchat_adaptive_card {
119
+ background: ${(props === null || props === void 0 ? void 0 : (_props$adaptiveCardSt = props.adaptiveCardStyles) === null || _props$adaptiveCardSt === void 0 ? void 0 : _props$adaptiveCardSt.background) ?? defaultAdaptiveCardStyles.background};
120
+ }
121
+
122
+ div[class="ac-textBlock"]>p{color:${(props === null || props === void 0 ? void 0 : (_props$adaptiveCardSt2 = props.adaptiveCardStyles) === null || _props$adaptiveCardSt2 === void 0 ? void 0 : _props$adaptiveCardSt2.color) ?? defaultAdaptiveCardStyles.color};}
123
+
40
124
  .ms_lcw_webchat_received_message img.webchat__markdown__external-link-icon {
41
125
  background-image : url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIzIDMgMTggMTgiICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik03LjI1MDEgNC41MDAxN0gxMC43NDk1QzExLjE2MzcgNC41MDAxNyAxMS40OTk1IDQuODM1OTYgMTEuNDk5NSA1LjI1MDE3QzExLjQ5OTUgNS42Mjk4NiAxMS4yMTczIDUuOTQzNjYgMTAuODUxMyA1Ljk5MzMyTDEwLjc0OTUgNi4wMDAxN0g3LjI0OTc0QzYuMDcwNzkgNS45OTk2MSA1LjEwMzQ5IDYuOTA2NTYgNS4wMDc4NiA4LjA2MTEyTDUuMDAwMjggOC4yMjAwM0w1LjAwMzEyIDE2Ljc1MDdDNS4wMDM0MyAxNy45NDE1IDUuOTI4ODUgMTguOTE2MSA3LjA5OTY2IDE4Ljk5NDlMNy4yNTM3MSAxOS4wMDAxTDE1Ljc1MTggMTguOTg4NEMxNi45NDE1IDE4Ljk4NjggMTcuOTE0NSAxOC4wNjIgMTcuOTkzNSAxNi44OTIzTDE3Ljk5ODcgMTYuNzM4NFYxMy4yMzIxQzE3Ljk5ODcgMTIuODE3OSAxOC4zMzQ1IDEyLjQ4MjEgMTguNzQ4NyAxMi40ODIxQzE5LjEyODQgMTIuNDgyMSAxOS40NDIyIDEyLjc2NDMgMTkuNDkxOCAxMy4xMzAzTDE5LjQ5ODcgMTMuMjMyMVYxNi43Mzg0QzE5LjQ5ODcgMTguNzQwNyAxNy45MjkzIDIwLjM3NjkgMTUuOTUyOCAyMC40ODI5TDE1Ljc1MzggMjAuNDg4NEw3LjI1ODI3IDIwLjUwMDFMNy4wNTQ5NSAyMC40OTQ5QzUuMTQyMzkgMjAuMzk1NCAzLjYwODk1IDE4Ljg2MjcgMy41MDgzNyAxNi45NTAyTDMuNTAzMTIgMTYuNzUxMUwzLjUwMDg5IDguMjUyN0wzLjUwNTI5IDguMDUwMkMzLjYwNTM5IDYuMTM3NDkgNS4xMzg2NyA0LjYwNDQ5IDcuMDUwOTYgNC41MDUyN0w3LjI1MDEgNC41MDAxN0gxMC43NDk1SDcuMjUwMVpNMTMuNzQ4MSAzLjAwMTQ2TDIwLjMwMTggMy4wMDE5N0wyMC40MDE0IDMuMDE1NzVMMjAuNTAyMiAzLjA0MzkzTDIwLjU1OSAzLjA2ODAzQzIwLjYxMjIgMy4wOTEyMiAyMC42NjM0IDMuMTIxNjMgMjAuNzExMSAzLjE1ODg1TDIwLjc4MDQgMy4yMjE1NkwyMC44NjQxIDMuMzIwMTRMMjAuOTE4MyAzLjQxMDI1TDIwLjk1NyAzLjUwMDU3TDIwLjk3NjIgMy41NjQ3NkwyMC45ODk4IDMuNjI4NjJMMjAuOTk5MiAzLjcyMjgyTDIwLjk5OTcgMTAuMjU1NEMyMC45OTk3IDEwLjY2OTYgMjAuNjYzOSAxMS4wMDU0IDIwLjI0OTcgMTEuMDA1NEMxOS44NyAxMS4wMDU0IDE5LjU1NjIgMTAuNzIzMiAxOS41MDY1IDEwLjM1NzFMMTkuNDk5NyAxMC4yNTU0TDE5LjQ5ODkgNS41NjE0N0wxMi4yNzk3IDEyLjc4NDdDMTIuMDEzNCAxMy4wNTEgMTEuNTk2OCAxMy4wNzUzIDExLjMwMzEgMTIuODU3NUwxMS4yMTkgMTIuNzg0OUMxMC45NTI3IDEyLjUxODcgMTAuOTI4NCAxMi4xMDIxIDExLjE0NjIgMTEuODA4NEwxMS4yMTg4IDExLjcyNDNMMTguNDM2OSA0LjUwMTQ2SDEzLjc0ODFDMTMuMzY4NCA0LjUwMTQ2IDEzLjA1NDYgNC4yMTkzMSAxMy4wMDUgMy44NTMyNEwxMi45OTgxIDMuNzUxNDZDMTIuOTk4MSAzLjM3MTc3IDEzLjI4MDMgMy4wNTc5NyAxMy42NDY0IDMuMDA4MzFMMTMuNzQ4MSAzLjAwMTQ2WiIgZmlsbD0iI0ZGRkZGRiIgLz48L3N2Zz4) !important;
42
126
  height: '.75em';
43
- marginLeft: '.25em';
127
+ marginLeft: '.25em';
128
+ filter:${(props === null || props === void 0 ? void 0 : (_props$renderingMiddl = props.renderingMiddlewareProps) === null || _props$renderingMiddl === void 0 ? void 0 : (_props$renderingMiddl2 = _props$renderingMiddl.receivedMessageAnchorStyles) === null || _props$renderingMiddl2 === void 0 ? void 0 : _props$renderingMiddl2.filter) ?? "none"};
44
129
  }
45
130
  pre {
46
131
  white-space: pre-wrap;
@@ -53,7 +138,7 @@ export const WebChatContainerStateful = props => {
53
138
  .ms_lcw_webchat_received_message a:visited,
54
139
  .ms_lcw_webchat_received_message a:hover,
55
140
  .ms_lcw_webchat_received_message a:active {
56
- color: white;
141
+ color: ${(props === null || props === void 0 ? void 0 : (_props$renderingMiddl3 = props.renderingMiddlewareProps) === null || _props$renderingMiddl3 === void 0 ? void 0 : (_props$renderingMiddl4 = _props$renderingMiddl3.receivedMessageAnchorStyles) === null || _props$renderingMiddl4 === void 0 ? void 0 : _props$renderingMiddl4.color) ?? (defaultReceivedMessageAnchorStyles === null || defaultReceivedMessageAnchorStyles === void 0 ? void 0 : defaultReceivedMessageAnchorStyles.color)};
57
142
  } `), /*#__PURE__*/React.createElement(Stack, {
58
143
  styles: containerStyles
59
144
  }, /*#__PURE__*/React.createElement(BasicWebChat, null)));
@@ -2,11 +2,13 @@ import MockAdapter from "../mockadapter";
2
2
  import { defaultWebChatStatefulContainerStyles } from "../defaultStyles/defaultWebChatStatefulContainerStyles";
3
3
  import { defaultWebChatStatefulProps } from "./defaultWebChatStatefulProps";
4
4
  import { defaultWebChatStatefulStyles } from "../defaultStyles/defaultWebChatContainerStatefulStyles";
5
+ import { defaultAdaptiveCardStyles } from "../defaultStyles/defaultAdaptiveCardStyles";
5
6
  export const defaultWebChatContainerStatefulProps = {
6
7
  webChatStyles: defaultWebChatStatefulStyles,
7
8
  webChatProps: defaultWebChatStatefulProps,
8
9
  containerStyles: defaultWebChatStatefulContainerStyles,
9
10
  disableNewLineMarkdownSupport: false,
10
11
  disableMarkdownMessageFormatting: false,
11
- directLine: new MockAdapter()
12
+ directLine: new MockAdapter(),
13
+ adaptiveCardStyles: defaultAdaptiveCardStyles
12
14
  };
@@ -0,0 +1,4 @@
1
+ export const defaultAdaptiveCardStyles = {
2
+ background: "white",
3
+ color: "black"
4
+ };
@@ -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() {
@@ -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", "");
@@ -54,6 +54,16 @@ const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
54
54
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
55
 
56
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
+
57
67
  export const createActivityMiddleware = (systemMessageStyleProps, userMessageStyleProps) => () => next => function () {
58
68
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
69
  args[_key] = arguments[_key];
@@ -62,7 +72,7 @@ export const createActivityMiddleware = (systemMessageStyleProps, userMessageSty
62
72
  const [card] = args;
63
73
 
64
74
  if (card.activity) {
65
- var _card$activity$from, _card$activity$channe4, _card$activity$channe5;
75
+ var _card$activity$from;
66
76
 
67
77
  if (((_card$activity$from = card.activity.from) === null || _card$activity$from === void 0 ? void 0 : _card$activity$from.role) === DirectLineSenderRole.Channel) {
68
78
  var _card$activity$channe3;
@@ -77,7 +87,11 @@ export const createActivityMiddleware = (systemMessageStyleProps, userMessageSty
77
87
  return () => false;
78
88
  }
79
89
 
80
- 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)) {
81
95
  return handleSystemMessage(next, args, card, systemMessageStyleProps);
82
96
  } else if (card.activity.text && card.activity.type === DirectLineActivityType.Message) {
83
97
  if (!card.activity.channelData.isHtmlEncoded && card.activity.channelId === Constants.webchatChannelId) {
@@ -61,6 +61,7 @@ export const activityStatusMiddleware = () => next => args => {
61
61
  args: args,
62
62
  role: current_role,
63
63
  name: current_name
64
- }));
64
+ })) // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ ;
65
66
  }
66
67
  };
@@ -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;
@@ -0,0 +1,32 @@
1
+ import { LogLevel } from "../../../../common/telemetry/TelemetryConstants";
2
+ import { TelemetryHelper } from "../../../../common/telemetry/TelemetryHelper";
3
+ export function createWebChatTelemetry() {
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ const handleTelemetry = event => {
6
+ const {
7
+ level
8
+ } = event;
9
+ const loglevel = level ? level.toUpperCase() : "";
10
+
11
+ switch (loglevel) {
12
+ case LogLevel.DEBUG:
13
+ TelemetryHelper.logWebChatEvent(LogLevel.DEBUG, event);
14
+ break;
15
+
16
+ case LogLevel.WARN:
17
+ TelemetryHelper.logWebChatEvent(LogLevel.WARN, event);
18
+ break;
19
+
20
+ case LogLevel.ERROR:
21
+ TelemetryHelper.logWebChatEvent(LogLevel.ERROR, event);
22
+ break;
23
+
24
+ case LogLevel.INFO:
25
+ default:
26
+ TelemetryHelper.logWebChatEvent(LogLevel.INFO, event);
27
+ break;
28
+ }
29
+ };
30
+
31
+ return handleTelemetry;
32
+ }
@@ -8,6 +8,7 @@ export let ConversationState;
8
8
  ConversationState[ConversationState["ProactiveChat"] = 4] = "ProactiveChat";
9
9
  ConversationState[ConversationState["Active"] = 5] = "Active";
10
10
  ConversationState[ConversationState["InActive"] = 6] = "InActive";
11
- ConversationState[ConversationState["Postchat"] = 7] = "Postchat";
12
- ConversationState[ConversationState["Closed"] = 8] = "Closed";
11
+ ConversationState[ConversationState["PostchatLoading"] = 7] = "PostchatLoading";
12
+ ConversationState[ConversationState["Postchat"] = 8] = "Postchat";
13
+ ConversationState[ConversationState["Closed"] = 9] = "Closed";
13
14
  })(ConversationState || (ConversationState = {}));
@@ -7,16 +7,16 @@ export let LiveChatWidgetActionType;
7
7
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_GLOBAL_DIR"] = 3] = "SET_GLOBAL_DIR";
8
8
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_MINIMIZED"] = 4] = "SET_MINIMIZED";
9
9
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_STATE"] = 5] = "SET_CONVERSATION_STATE";
10
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PREVIOUS_FOCUSED_ELEMENT"] = 6] = "SET_PREVIOUS_FOCUSED_ELEMENT";
10
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PREVIOUS_FOCUSED_ELEMENT_ID"] = 6] = "SET_PREVIOUS_FOCUSED_ELEMENT_ID";
11
11
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_OUTSIDE_OPERATING_HOURS"] = 7] = "SET_OUTSIDE_OPERATING_HOURS";
12
12
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRE_CHAT_SURVEY_RESPONSE"] = 8] = "SET_PRE_CHAT_SURVEY_RESPONSE";
13
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_CONFIRMATION"] = 9] = "SET_SHOW_CONFIRMATION";
14
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_EMAIL_TRANSCRIPT_PANE"] = 10] = "SET_SHOW_EMAIL_TRANSCRIPT_PANE";
15
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRECHAT_RESPONSE_EMAIL"] = 11] = "SET_PRECHAT_RESPONSE_EMAIL";
16
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_AUDIO_NOTIFICATION"] = 12] = "SET_AUDIO_NOTIFICATION";
17
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_E2VV_ENABLED"] = 13] = "SET_E2VV_ENABLED";
18
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_POST_CHAT_CONTEXT"] = 14] = "SET_POST_CHAT_CONTEXT";
19
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOULD_SHOW_POST_CHAT"] = 15] = "SET_SHOULD_SHOW_POST_CHAT";
13
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CUSTOM_CONTEXT"] = 9] = "SET_CUSTOM_CONTEXT";
14
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_CONFIRMATION"] = 10] = "SET_SHOW_CONFIRMATION";
15
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_EMAIL_TRANSCRIPT_PANE"] = 11] = "SET_SHOW_EMAIL_TRANSCRIPT_PANE";
16
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRECHAT_RESPONSE_EMAIL"] = 12] = "SET_PRECHAT_RESPONSE_EMAIL";
17
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_AUDIO_NOTIFICATION"] = 13] = "SET_AUDIO_NOTIFICATION";
18
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_E2VV_ENABLED"] = 14] = "SET_E2VV_ENABLED";
19
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_POST_CHAT_CONTEXT"] = 15] = "SET_POST_CHAT_CONTEXT";
20
20
  LiveChatWidgetActionType[LiveChatWidgetActionType["SHOW_CALLING_CONTAINER"] = 16] = "SHOW_CALLING_CONTAINER";
21
21
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_INCOMING_CALL"] = 17] = "SET_INCOMING_CALL";
22
22
  LiveChatWidgetActionType[LiveChatWidgetActionType["DISABLE_VIDEO_CALL"] = 18] = "DISABLE_VIDEO_CALL";
@@ -32,4 +32,7 @@ export let LiveChatWidgetActionType;
32
32
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_ENDED_BY_AGENT"] = 28] = "SET_CONVERSATION_ENDED_BY_AGENT";
33
33
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_STATE"] = 29] = "SET_WIDGET_STATE";
34
34
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
35
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
36
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_SIZE"] = 32] = "SET_WIDGET_SIZE";
37
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_INSTANCE_ID"] = 33] = "SET_WIDGET_INSTANCE_ID";
35
38
  })(LiveChatWidgetActionType || (LiveChatWidgetActionType = {}));