@microsoft/omnichannel-chat-widget 0.1.0-main.488d6f1 → 0.1.0-main.4eb4d1f

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 (138) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +52 -6
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +58 -6
  4. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +17 -6
  6. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  7. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  8. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
  9. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  10. package/lib/cjs/common/utils.js +76 -2
  11. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  12. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  13. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +6 -42
  14. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
  15. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  16. package/lib/cjs/components/headerstateful/HeaderStateful.js +3 -9
  17. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  18. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  19. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  20. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -1
  21. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  22. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -17
  23. package/lib/cjs/components/livechatwidget/common/endChat.js +94 -11
  24. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  25. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +35 -6
  26. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +115 -22
  27. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  28. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -9
  29. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  30. package/lib/cjs/components/livechatwidget/common/startChat.js +169 -50
  31. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +233 -78
  32. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  33. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  34. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +19 -3
  35. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  36. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -0
  37. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  38. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  39. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +25 -48
  40. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +3 -1
  41. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  42. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  43. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  44. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  45. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  46. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  47. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
  48. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
  49. package/lib/cjs/contexts/createReducer.js +16 -10
  50. package/lib/cjs/controller/componentController.js +3 -3
  51. package/lib/cjs/plugins/newMessageEventHandler.js +99 -0
  52. package/lib/esm/common/Constants.js +48 -5
  53. package/lib/esm/common/telemetry/TelemetryConstants.js +54 -5
  54. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  55. package/lib/esm/common/telemetry/TelemetryManager.js +15 -6
  56. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  57. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  58. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  59. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  60. package/lib/esm/common/utils.js +55 -1
  61. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  62. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  63. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +6 -37
  64. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  65. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  66. package/lib/esm/components/headerstateful/HeaderStateful.js +3 -9
  67. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  68. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  69. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  70. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  71. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  72. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -18
  73. package/lib/esm/components/livechatwidget/common/endChat.js +91 -13
  74. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  75. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +30 -7
  76. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +104 -22
  77. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  78. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -9
  79. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  80. package/lib/esm/components/livechatwidget/common/startChat.js +166 -52
  81. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +219 -78
  82. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  83. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  84. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +20 -4
  85. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  86. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -0
  87. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  88. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  89. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +23 -46
  90. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  91. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  92. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  93. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  94. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  95. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  96. package/lib/esm/contexts/common/ConversationState.js +3 -2
  97. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
  98. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +8 -3
  99. package/lib/esm/contexts/createReducer.js +16 -9
  100. package/lib/esm/controller/componentController.js +3 -3
  101. package/lib/esm/plugins/newMessageEventHandler.js +82 -0
  102. package/lib/types/common/Constants.d.ts +26 -2
  103. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  104. package/lib/types/common/telemetry/TelemetryConstants.d.ts +42 -4
  105. package/lib/types/common/telemetry/TelemetryHelper.d.ts +3 -1
  106. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  107. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  108. package/lib/types/common/utils.d.ts +7 -1
  109. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  110. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  111. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  112. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  113. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  114. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  115. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  116. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  117. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  118. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  119. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  120. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  121. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  122. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -1
  123. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  124. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -0
  125. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  126. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  127. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  128. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -2
  129. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  130. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  131. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  132. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  133. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  134. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  135. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  136. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
  137. package/lib/types/plugins/newMessageEventHandler.d.ts +2 -0
  138. package/package.json +9 -11
@@ -1,9 +1,9 @@
1
- import { isNullOrEmptyString, isNullOrUndefined } from "../../utils";
1
+ import { getDomain, isNullOrEmptyString, isNullOrUndefined } from "../../utils";
2
2
  import AWTEventProperties from "@microsoft/omnichannel-chat-sdk/lib/external/aria/webjs/AWTEventProperties";
3
3
  import AWTLogManager from "@microsoft/omnichannel-chat-sdk/lib/external/aria/webjs/AWTLogManager";
4
4
  import { AWTPiiKind } from "@microsoft/omnichannel-chat-sdk/lib/external/aria/common/Enums";
5
- import { Constants } from "../../Constants";
6
- import { TelemetryHelper } from "../TelemetryHelper";
5
+ import { Constants, AriaTelemetryConstants, EnvironmentVersion } from "../../Constants";
6
+ import { TelemetryManager } from "../TelemetryManager";
7
7
  export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, collectiorUriForTelemetry, ariaTelemetryApplicationName) => {
8
8
  let _logger;
9
9
 
@@ -15,6 +15,21 @@ export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, colle
15
15
 
16
16
  if (!isNullOrEmptyString(collectiorUriForTelemetry)) {
17
17
  configuration.collectorUri = collectiorUriForTelemetry;
18
+ } else {
19
+ if (TelemetryManager.InternalTelemetryData.environmentVersion == EnvironmentVersion.prod) {
20
+ var _TelemetryManager$Int;
21
+
22
+ const orgUrl = (_TelemetryManager$Int = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int === void 0 ? void 0 : _TelemetryManager$Int.orgUrl;
23
+
24
+ if (!isNullOrUndefined(orgUrl)) {
25
+ // If the given org is a Production EU org, modify the Aria collector uri
26
+ const region = getDomain(orgUrl);
27
+
28
+ if (region === AriaTelemetryConstants.EU) {
29
+ configuration.collectorUri = AriaTelemetryConstants.EUROPE_ENDPOINT;
30
+ }
31
+ }
32
+ }
18
33
  }
19
34
 
20
35
  try {
@@ -33,18 +48,25 @@ export const ariaTelemetryLogger = (ariaTelemetryKey, disabledCookieUsage, colle
33
48
 
34
49
  const ariaLogger = {
35
50
  log: (logLevel, telemetryInput) => {
36
- let property;
37
- const eventProperties = new AWTEventProperties();
38
- const event = TelemetryHelper.buildTelemetryEvent(logLevel, telemetryInput);
39
- eventProperties.setName(telemetryInput.scenarioType);
40
-
41
- for (const key of Object.keys(event)) {
42
- property = typeof event[key] === "object" ? JSON.stringify(event[key]) : event[key];
43
- eventProperties.setProperty(key, property);
44
- }
51
+ try {
52
+ let property;
53
+ const telemetryInfo = telemetryInput === null || telemetryInput === void 0 ? void 0 : telemetryInput.telemetryInfo;
54
+ const eventProperties = new AWTEventProperties();
55
+ eventProperties.setName(telemetryInput.scenarioType);
45
56
 
46
- eventProperties.setPropertyWithPii(ariaTelemetryApplicationName, Constants.LiveChatWidget, AWTPiiKind.GenericData);
47
- logger() ? logger().logEvent(eventProperties) : console.log("Unable to initialize aria logger");
57
+ if (telemetryInfo) {
58
+ for (const key of Object.keys(telemetryInfo)) {
59
+ property = typeof telemetryInfo[key] === "object" ? JSON.stringify(telemetryInfo[key]) : telemetryInfo[key];
60
+ eventProperties.setProperty(key, property);
61
+ }
62
+
63
+ eventProperties.setPropertyWithPii(ariaTelemetryApplicationName, Constants.LiveChatWidget, AWTPiiKind.GenericData);
64
+ }
65
+
66
+ logger() ? logger().logEvent(eventProperties) : console.log("Unable to initialize aria logger");
67
+ } catch (error) {
68
+ console.error("Error in logging telemetry to Aria logger:" + error);
69
+ }
48
70
  },
49
71
  dispose: () => {
50
72
  AWTLogManager.flush(function () {
@@ -4,27 +4,28 @@ export const consoleLogger = () => {
4
4
  const consoleLogger = {
5
5
  log: (logLevel, telemetryInput) => {
6
6
  const payload = telemetryInput !== null && telemetryInput !== void 0 && telemetryInput.payload && Object.keys(telemetryInput === null || telemetryInput === void 0 ? void 0 : telemetryInput.payload).length > 0 ? telemetryInput === null || telemetryInput === void 0 ? void 0 : telemetryInput.payload : "";
7
+ const telemetryInfo = telemetryInput !== null && telemetryInput !== void 0 && telemetryInput.telemetryInfo && Object.keys(telemetryInput === null || telemetryInput === void 0 ? void 0 : telemetryInput.telemetryInfo).length > 0 ? telemetryInput === null || telemetryInput === void 0 ? void 0 : telemetryInput.telemetryInfo : "";
7
8
 
8
9
  try {
9
10
  switch (logLevel) {
10
11
  case LogLevel.INFO:
11
- console.info(Constants.LiveChatWidget, payload);
12
+ console.info(Constants.LiveChatWidget, payload, telemetryInfo);
12
13
  break;
13
14
 
14
15
  case LogLevel.DEBUG:
15
- console.debug(Constants.LiveChatWidget, payload);
16
+ console.debug(Constants.LiveChatWidget, payload, telemetryInfo);
16
17
  break;
17
18
 
18
19
  case LogLevel.WARN:
19
- console.warn(Constants.LiveChatWidget, payload);
20
+ console.warn(Constants.LiveChatWidget, payload, telemetryInfo);
20
21
  break;
21
22
 
22
23
  case LogLevel.ERROR:
23
- console.error(Constants.LiveChatWidget, payload);
24
+ console.error(Constants.LiveChatWidget, payload, telemetryInfo);
24
25
  break;
25
26
 
26
27
  default:
27
- console.debug(Constants.LiveChatWidget, payload);
28
+ console.debug(Constants.LiveChatWidget, payload, telemetryInfo);
28
29
  break;
29
30
  }
30
31
  } catch (ex) {
@@ -1,5 +1,7 @@
1
- import { Constants, LocaleConstants } from "./Constants";
1
+ import { AriaTelemetryConstants, Constants, LocaleConstants } from "./Constants";
2
+ import { DataStoreManager } from "./contextDataStore/DataStoreManager";
2
3
  import { KeyCodes } from "./KeyCodes";
4
+ import { BroadcastEvent } from "./telemetry/TelemetryConstants";
3
5
 
4
6
  const getElementBySelector = selector => {
5
7
  let element;
@@ -276,4 +278,56 @@ export const createTimer = () => {
276
278
  }
277
279
 
278
280
  };
281
+ }; // Returns the domain of the org
282
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
+
284
+ export const getDomain = hostValue => {
285
+ for (let i = 0; i < AriaTelemetryConstants.lcwEUDomainNames.length; i++) {
286
+ if (hostValue.endsWith(AriaTelemetryConstants.lcwEUDomainNames[i])) {
287
+ return AriaTelemetryConstants.EU;
288
+ }
289
+ }
290
+
291
+ return AriaTelemetryConstants.Public;
292
+ };
293
+ export const getWidgetCacheId = (orgId, widgetId) => {
294
+ return `${Constants.ChatWidgetStateChangedPrefix}_${orgId}_${widgetId}`;
295
+ };
296
+ export const getWidgetEndChatEventName = (orgId, widgetId) => {
297
+ return `${BroadcastEvent.ChatEnded}_${orgId}_${widgetId}`;
298
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
+
300
+ export const getStateFromCache = (orgId, widgetId) => {
301
+ // Getting updated state from cache
302
+ try {
303
+ if (DataStoreManager.clientDataStore) {
304
+ var _DataStoreManager$cli;
305
+
306
+ const widgetStateEventName = getWidgetCacheId(orgId, widgetId);
307
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
308
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
309
+ return persistedState;
310
+ } else {
311
+ return null;
312
+ }
313
+ } catch (error) {
314
+ console.log(error);
315
+ return null;
316
+ }
317
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
318
+
319
+ export const isUndefinedOrEmpty = object => {
320
+ if (object) {
321
+ if (Object.keys(object).length === 0) {
322
+ return true;
323
+ }
324
+
325
+ return false;
326
+ } else {
327
+ return true;
328
+ }
329
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
330
+
331
+ export const addDelayInMs = ms => {
332
+ return new Promise(resolve => setTimeout(resolve, ms));
279
333
  };
@@ -177,6 +177,20 @@ export const CallingContainerStateful = props => {
177
177
  });
178
178
  }
179
179
  });
180
+ window.addEventListener("beforeunload", () => {
181
+ if (state.uiStates.isIncomingCall) {
182
+ voiceVideoCallingSdk === null || voiceVideoCallingSdk === void 0 ? void 0 : voiceVideoCallingSdk.rejectCall();
183
+ } else {
184
+ voiceVideoCallingSdk === null || voiceVideoCallingSdk === void 0 ? void 0 : voiceVideoCallingSdk.stopCall();
185
+ }
186
+
187
+ voiceVideoCallingSdk === null || voiceVideoCallingSdk === void 0 ? void 0 : voiceVideoCallingSdk.close();
188
+ dispatch({
189
+ type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
190
+ payload: false
191
+ });
192
+ resetCallingStates(true);
193
+ });
180
194
  }, []);
181
195
  const controlProps = {
182
196
  id: "oc-lcw-callingcontainer",
@@ -1,6 +1,6 @@
1
- import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
- import React, { useEffect, useState } from "react";
3
- import { ChatButton } from "@microsoft/omnichannel-chat-components";
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
+ import React, { useEffect, useRef, useState } from "react";
3
+ import { BroadcastService, ChatButton } from "@microsoft/omnichannel-chat-components";
4
4
  import { Constants } from "../../common/Constants";
5
5
  import { setFocusOnElement } from "../../common/utils";
6
6
  import { ConversationState } from "../../contexts/common/ConversationState";
@@ -10,7 +10,7 @@ import { TelemetryTimers } from "../../common/telemetry/TelemetryManager";
10
10
  import { defaultOutOfOfficeChatButtonStyleProps } from "./common/styleProps/defaultOutOfOfficeChatButtonStyleProps";
11
11
  import useChatContextStore from "../../hooks/useChatContextStore";
12
12
  export const ChatButtonStateful = props => {
13
- var _state$domainStates$l, _state$domainStates$l2, _buttonProps$controlP;
13
+ var _state$domainStates$l, _state$domainStates$l2, _buttonProps$controlP, _props$buttonProps, _props$buttonProps$co, _props$buttonProps2, _props$buttonProps2$c, _props$buttonProps3, _props$buttonProps3$c;
14
14
 
15
15
  const [state, dispatch] = useChatContextStore();
16
16
  const {
@@ -20,20 +20,26 @@ export const ChatButtonStateful = props => {
20
20
  } = props; //Setting OutOfOperatingHours Flag
21
21
 
22
22
  const [outOfOperatingHours, setOutOfOperatingHours] = useState(((_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");
23
+ const proactiveChatInNewWindow = useRef(state.appStates.proactiveChatStates.proactiveChatInNewWindow);
23
24
  const outOfOfficeStyleProps = Object.assign({}, defaultOutOfOfficeChatButtonStyleProps, outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.styleProps);
24
25
  const controlProps = {
25
26
  id: "oc-lcw-chat-button",
26
27
  dir: state.domainStates.globalDir,
27
28
  titleText: "Let's Chat!",
28
29
  subtitleText: "We're online.",
29
- hideNotificationBubble: !(state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) || (buttonProps === null || buttonProps === void 0 ? void 0 : (_buttonProps$controlP = buttonProps.controlProps) === null || _buttonProps$controlP === void 0 ? void 0 : _buttonProps$controlP.hideNotificationBubble) === true,
30
- unreadMessageCount: state.appStates.unreadMessageCount ? state.appStates.unreadMessageCount > Constants.maximumUnreadMessageCount ? Constants.maximumUnreadMessageCount.toString() + "+" : state.appStates.unreadMessageCount.toString() : "0",
30
+ hideNotificationBubble: (buttonProps === null || buttonProps === void 0 ? void 0 : (_buttonProps$controlP = buttonProps.controlProps) === null || _buttonProps$controlP === void 0 ? void 0 : _buttonProps$controlP.hideNotificationBubble) === true || state.appStates.isMinimized === false,
31
+ unreadMessageCount: state.appStates.unreadMessageCount ? state.appStates.unreadMessageCount > Constants.maximumUnreadMessageCount ? (_props$buttonProps = props.buttonProps) === null || _props$buttonProps === void 0 ? void 0 : (_props$buttonProps$co = _props$buttonProps.controlProps) === null || _props$buttonProps$co === void 0 ? void 0 : _props$buttonProps$co.largeUnreadMessageString : state.appStates.unreadMessageCount.toString() : "0",
31
32
  onClick: async () => {
32
33
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
33
34
  Event: TelemetryEvent.LCWChatButtonClicked
34
35
  });
35
36
 
36
- if (state.appStates.isMinimized) {
37
+ if (proactiveChatInNewWindow.current) {
38
+ const proactiveChatIsInPopoutModeEvent = {
39
+ eventName: BroadcastEvent.ProactiveChatIsInPopoutMode
40
+ };
41
+ BroadcastService.postMessage(proactiveChatIsInPopoutModeEvent);
42
+ } else if (state.appStates.isMinimized) {
37
43
  dispatch({
38
44
  type: LiveChatWidgetActionType.SET_MINIMIZED,
39
45
  payload: false
@@ -42,6 +48,7 @@ export const ChatButtonStateful = props => {
42
48
  await startChat();
43
49
  }
44
50
  },
51
+ unreadMessageString: (_props$buttonProps2 = props.buttonProps) === null || _props$buttonProps2 === void 0 ? void 0 : (_props$buttonProps2$c = _props$buttonProps2.controlProps) === null || _props$buttonProps2$c === void 0 ? void 0 : _props$buttonProps2$c.unreadMessageString,
45
52
  ...(buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.controlProps)
46
53
  };
47
54
  const outOfOfficeControlProps = {
@@ -50,6 +57,10 @@ export const ChatButtonStateful = props => {
50
57
  titleText: "We're Offline",
51
58
  subtitleText: "No agents available",
52
59
  onClick: async () => {
60
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
61
+ Event: TelemetryEvent.LCWChatButtonClicked
62
+ });
63
+
53
64
  if (state.appStates.isMinimized) {
54
65
  dispatch({
55
66
  type: LiveChatWidgetActionType.SET_MINIMIZED,
@@ -62,6 +73,7 @@ export const ChatButtonStateful = props => {
62
73
  });
63
74
  }
64
75
  },
76
+ unreadMessageString: (_props$buttonProps3 = props.buttonProps) === null || _props$buttonProps3 === void 0 ? void 0 : (_props$buttonProps3$c = _props$buttonProps3.controlProps) === null || _props$buttonProps3$c === void 0 ? void 0 : _props$buttonProps3$c.unreadMessageString,
65
77
  ...(outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.controlProps)
66
78
  };
67
79
  useEffect(() => {
@@ -83,6 +95,9 @@ export const ChatButtonStateful = props => {
83
95
  });
84
96
  }
85
97
  }, []);
98
+ useEffect(() => {
99
+ proactiveChatInNewWindow.current = state.appStates.proactiveChatStates.proactiveChatInNewWindow;
100
+ }, [state.appStates.proactiveChatStates.proactiveChatInNewWindow]);
86
101
  return /*#__PURE__*/React.createElement(ChatButton, {
87
102
  componentOverrides: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.componentOverrides,
88
103
  controlProps: outOfOperatingHours ? outOfOfficeControlProps : controlProps,
@@ -1,35 +1,24 @@
1
1
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
+ import { ConfirmationPane } from "@microsoft/omnichannel-chat-components";
2
3
  import React, { useEffect } from "react";
3
4
  import { findAllFocusableElement, findParentFocusableElementsWithoutChildContainer, preventFocusToMoveOutOfElement, setFocusOnElement, setFocusOnSendBox, setTabIndices } from "../../common/utils";
4
- import { BroadcastService, ConfirmationPane } from "@microsoft/omnichannel-chat-components";
5
5
  import { DimLayer } from "../dimlayer/DimLayer";
6
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
7
7
  import { NotificationHandler } from "../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
8
8
  import { NotificationScenarios } from "../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
9
- import { PostChatSurveyMode } from "../postchatsurveypanestateful/enums/PostChatSurveyMode";
10
9
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
11
10
  import useChatAdapterStore from "../../hooks/useChatAdapterStore";
12
- import useChatContextStore from "../../hooks/useChatContextStore";
13
- import useChatSDKStore from "../../hooks/useChatSDKStore";
14
- import { Constants } from "../../common/Constants";
15
- import { ConversationState } from "../../contexts/common/ConversationState"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ import useChatContextStore from "../../hooks/useChatContextStore"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
12
 
17
13
  export const ConfirmationPaneStateful = props => {
18
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
19
-
20
14
  const initialTabIndexMap = new Map();
21
- let elements = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
-
23
- const chatSDK = useChatSDKStore();
15
+ let elements = [];
24
16
  const [state, dispatch] = useChatContextStore();
25
17
  const {
26
- endChat
18
+ prepareEndChat
27
19
  } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
20
 
30
21
  const [adapter] = useChatAdapterStore();
31
- const isPostChatEnabled = (_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.msdyn_postconversationsurveyenable;
32
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
33
22
  const controlProps = {
34
23
  id: "oc-lcw-confirmation-pane",
35
24
  dir: state.domainStates.globalDir,
@@ -44,28 +33,8 @@ export const ConfirmationPaneStateful = props => {
44
33
  });
45
34
 
46
35
  try {
47
- // check agent has joined conversation
48
- const conversationDetails = await chatSDK.getConversationDetails();
49
-
50
- if (isPostChatEnabled === "true" && conversationDetails.canRenderPostChat === Constants.truePascal) {
51
- if (postChatSurveyMode === PostChatSurveyMode.Embed) {
52
- const loadPostChatEvent = {
53
- eventName: "LoadPostChatSurvey"
54
- };
55
- BroadcastService.postMessage(loadPostChatEvent);
56
- } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
57
- const skipEndChatSDK = false;
58
- const skipCloseChat = true;
59
- await endChat(adapter, skipEndChatSDK, skipCloseChat);
60
- dispatch({
61
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
62
- payload: ConversationState.InActive
63
- });
64
- }
65
- } else {
66
- setTabIndices(elements, initialTabIndexMap, true);
67
- await endChat(adapter);
68
- }
36
+ setTabIndices(elements, initialTabIndexMap, true);
37
+ await prepareEndChat(adapter, state);
69
38
  } catch (ex) {
70
39
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
71
40
  Event: TelemetryEvent.GetConversationDetailsCallFailed,
@@ -97,8 +97,7 @@ export const FooterStateful = props => {
97
97
  styleProps: footerProps === null || footerProps === void 0 ? void 0 : footerProps.styleProps
98
98
  }), /*#__PURE__*/React.createElement(AudioNotificationStateful, {
99
99
  audioSrc: (audioNotificationProps === null || audioNotificationProps === void 0 ? void 0 : audioNotificationProps.audioSrc) ?? NewMessageNotificationSoundBase64,
100
- hideAudioNotificationButton: (footerProps === null || footerProps === void 0 ? void 0 : (_footerProps$controlP4 = footerProps.controlProps) === null || _footerProps$controlP4 === void 0 ? void 0 : _footerProps$controlP4.hideAudioNotificationButton) ?? false,
101
- isAudioMuted: state.appStates.isAudioMuted ?? false
100
+ isAudioMuted: state.appStates.isAudioMuted === null ? (footerProps === null || footerProps === void 0 ? void 0 : (_footerProps$controlP4 = footerProps.controlProps) === null || _footerProps$controlP4 === void 0 ? void 0 : _footerProps$controlP4.hideAudioNotificationButton) ?? false : state.appStates.isAudioMuted ?? false
102
101
  }));
103
102
  };
104
103
  export default FooterStateful;
@@ -105,8 +105,14 @@ const beautifyChatTranscripts = (chatTranscripts, renderMarkDown, attachmentMess
105
105
  let fileAttachmentName = TranscriptConstants.DefaultFileAttachmentName;
106
106
  let dialogColor = TranscriptConstants.CustomerDialogColor;
107
107
  let fontColor = TranscriptConstants.CustomerFontColor;
108
-
109
- if (value.tags && value.tags.toLowerCase().indexOf(Constants.systemMessageTag) !== -1 || value.isControlMessage && value.isControlMessage === true || value.contentType && value.contentType.toLowerCase() === TranscriptConstants.AdaptiveCardType || value.deliveryMode && value.deliveryMode.toLowerCase() === TranscriptConstants.InternalMode) {
108
+ const isSystemMessage = value.tags && value.tags.toLowerCase().indexOf(Constants.systemMessageTag) !== -1;
109
+ const isControlMessage = value.isControlMessage && value.isControlMessage === true;
110
+ const isAdaptiveCard = value.contentType && value.contentType.toLowerCase() === TranscriptConstants.AdaptiveCardType;
111
+ const isInternalMessage = value.deliveryMode && value.deliveryMode.toLowerCase() === TranscriptConstants.InternalMode;
112
+ const isHiddenMessage = value.tags && value.tags.toLowerCase().indexOf(Constants.hiddenTag.toLowerCase()) !== -1;
113
+ const shouldIgnoreMessage = isSystemMessage || isControlMessage || isAdaptiveCard || isInternalMessage || isHiddenMessage;
114
+
115
+ if (shouldIgnoreMessage) {
110
116
  return;
111
117
  } else if (value.from) {
112
118
  if (value.from.application) {
@@ -127,7 +133,7 @@ const beautifyChatTranscripts = (chatTranscripts, renderMarkDown, attachmentMess
127
133
 
128
134
  if (value.attachments && value.attachments.length > 0 && value.attachments[0].name) {
129
135
  fileAttachmentName = value.attachments[0].name;
130
- value.content = attachmentMessage ?? "The following attachment was uploaded during the conversation:" + fileAttachmentName;
136
+ value.content = attachmentMessage ? attachmentMessage + " " + fileAttachmentName : "The following attachment was uploaded during the conversation: " + fileAttachmentName;
131
137
  }
132
138
  }
133
139
 
@@ -46,13 +46,7 @@ export const HeaderStateful = props => {
46
46
  type: LiveChatWidgetActionType.SET_SHOW_CONFIRMATION,
47
47
  payload: true
48
48
  });
49
- } else if (conversationState.current === ConversationState.Postchat) {
50
- dispatch({
51
- type: LiveChatWidgetActionType.SET_SHOULD_SHOW_POST_CHAT,
52
- payload: false
53
- });
54
- await endChat(adapter);
55
- } else if (conversationState.current === ConversationState.InActive) {
49
+ } else {
56
50
  const skipEndChatSDK = true;
57
51
  const skipCloseChat = false;
58
52
  await endChat(adapter, skipEndChatSDK, skipCloseChat);
@@ -64,8 +58,8 @@ export const HeaderStateful = props => {
64
58
  });
65
59
  },
66
60
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
67
- hideTitle: state.appStates.conversationState === ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
68
- hideIcon: state.appStates.conversationState === ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
61
+ hideTitle: state.appStates.conversationState === ConversationState.Loading || state.appStates.conversationState === ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
62
+ hideIcon: state.appStates.conversationState === ConversationState.Loading || state.appStates.conversationState === ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
69
63
  hideCloseButton: state.appStates.conversationState === ConversationState.Loading || state.appStates.conversationState === ConversationState.Prechat || state.appStates.conversationState === ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
70
64
  };
71
65
  const outOfOfficeControlProps = {
@@ -0,0 +1,14 @@
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 DefaultActivitySubscriber {
4
+ constructor() {
5
+ _defineProperty(this, "observer", void 0);
6
+ }
7
+
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ async next(activity) {
10
+ this.observer.next(activity);
11
+ return false;
12
+ }
13
+
14
+ }
@@ -0,0 +1,59 @@
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
+ import { DefaultActivitySubscriber } from "./ActivitySubscriber/DefaultActivitySubscriber";
4
+ import { shareObservable } from "./shareObservable";
5
+ export class ChatAdapterShim {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ constructor(chatAdapter) {
11
+ _defineProperty(this, "chatAdapter", void 0);
12
+
13
+ _defineProperty(this, "activityObserver", void 0);
14
+
15
+ _defineProperty(this, "subscribers", void 0);
16
+
17
+ this.subscribers = [];
18
+ this.chatAdapter = { ...chatAdapter,
19
+ activity$: shareObservable( // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ new window.Observable(observer => {
21
+ this.activityObserver = observer; // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+
23
+ const abortController = new window.AbortController();
24
+
25
+ (async () => {
26
+ try {
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ for await (let activity of chatAdapter.activities({
29
+ signal: abortController.signal
30
+ })) {
31
+ for (const subscriber of [...this.subscribers, new DefaultActivitySubscriber()]) {
32
+ subscriber.observer = this.activityObserver;
33
+ activity = await subscriber.next(activity);
34
+
35
+ if (!activity) {
36
+ break;
37
+ }
38
+ }
39
+ }
40
+
41
+ observer.complete();
42
+ } catch (error) {
43
+ observer.error(error);
44
+ }
45
+ })();
46
+
47
+ return () => {
48
+ abortController.abort();
49
+ };
50
+ }))
51
+ };
52
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+
54
+
55
+ addSubscriber(subscriber) {
56
+ this.subscribers.push(subscriber);
57
+ }
58
+
59
+ }
@@ -1,7 +1,8 @@
1
1
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
2
2
  import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
3
3
  import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
4
- import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
5
+ import { ChatAdapterShim } from "./ChatAdapterShim"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
6
 
6
7
  export const createAdapter = async chatSDK => {
7
8
  const chatAdapterOptionalParams = {
@@ -23,5 +24,11 @@ export const createAdapter = async chatSDK => {
23
24
  }
24
25
  }
25
26
  };
26
- return await chatSDK.createChatAdapter(chatAdapterOptionalParams);
27
+ let adapter = await chatSDK.createChatAdapter(chatAdapterOptionalParams); //so far, there is no need to convert to the shim adapter when using visual tests
28
+
29
+ if (chatSDK.isMockModeOn !== true) {
30
+ adapter = new ChatAdapterShim(adapter);
31
+ }
32
+
33
+ return adapter;
27
34
  };
@@ -13,26 +13,40 @@ export const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineM
13
13
  breaks: !disableNewLineMarkdownSupport
14
14
  }); // ToDo: Commenting below usage of plugin until deferred bug is resolved: https://github.com/mayashavin/markdown-it-slack/issues/1
15
15
  // markdown.use(MarkdownSlack);
16
- // Markdown override for open link in new tab
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, quotes
16
+ } else {
17
+ markdown = new MarkdownIt(Constants.Zero, {
18
+ html: true,
19
+ linkify: true,
20
+ breaks: !disableNewLineMarkdownSupport
21
+ });
22
+ markdown.enable(["entity", // Rule to process html entity - &#123;, &#xAF;, &quot;
23
+ "linkify", // Rule to replace link-like texts with link nodes
24
+ "html_block", // Rule to process html blocks and paragraphs
25
+ "html_inline", // Rule to process html tags
26
+ "newline" // Rule to proceess '\n'
27
+ ]);
28
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
29
 
19
- markdown.use(MarkdownItForInline, "url_new_win", "link_open", function (tokens, idx, env) {
20
- const targetAttrIndex = tokens[idx].attrIndex(Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
21
30
 
22
- const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
31
+ markdown.use(MarkdownItForInline, "url_new_win", "link_open", function (tokens, idx, env) {
32
+ const targetAttrIndex = tokens[idx].attrIndex(Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
23
33
 
24
- if (~targetAttrIndex) {
25
- tokens[idx].attrs[targetAttrIndex][1] = Constants.Blank;
26
- } else {
27
- tokens[idx].attrPush([Constants.Target, Constants.Blank]);
28
- }
34
+ const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
35
+
36
+ if (~targetAttrIndex) {
37
+ tokens[idx].attrs[targetAttrIndex][1] = Constants.Blank;
38
+ } else {
39
+ tokens[idx].attrPush([Constants.Target, Constants.Blank]);
40
+ }
41
+
42
+ const relAttrIndex = tokens[idx].attrIndex(Constants.TargetRelationship);
29
43
 
30
- const relAttrIndex = tokens[idx].attrIndex(Constants.TargetRelationship);
44
+ if (~relAttrIndex) {
45
+ tokens[idx].attrs[relAttrIndex][1] = Constants.TargetRelationshipAttributes;
46
+ } else {
47
+ tokens[idx].attrPush([Constants.TargetRelationship, Constants.TargetRelationshipAttributes]);
31
48
 
32
- if (~relAttrIndex) {
33
- tokens[idx].attrs[relAttrIndex][1] = Constants.TargetRelationshipAttributes;
34
- } else {
35
- tokens[idx].attrPush([Constants.TargetRelationship, Constants.TargetRelationshipAttributes]);
49
+ if (!disableMarkdownMessageFormatting) {
36
50
  tokens[idx].attrPush([Constants.Title, defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT]); // eslint-disable-next-line quotes
37
51
 
38
52
  const iconTokens = markdown.parseInline(`![${defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT}](${TRANSPARENT_GIF})`, env)[0].children;
@@ -42,20 +56,7 @@ export const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineM
42
56
  tokens.splice(idx + 2, 0, ...iconTokens);
43
57
  }
44
58
  }
45
- });
46
- } else {
47
- markdown = new MarkdownIt(Constants.Zero, {
48
- html: true,
49
- linkify: true,
50
- breaks: !disableNewLineMarkdownSupport
51
- });
52
- markdown.enable(["entity", // Rule to process html entity - &#123;, &#xAF;, &quot;
53
- "linkify", // Rule to replace link-like texts with link nodes
54
- "html_block", // Rule to process html blocks and paragraphs
55
- "html_inline", // Rule to process html tags
56
- "newline" // Rule to proceess '\n'
57
- ]);
58
- }
59
-
59
+ }
60
+ });
60
61
  return markdown;
61
62
  };