@microsoft/omnichannel-chat-widget 0.1.0-main.4188c11 → 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 (101) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +16 -2
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +21 -3
  4. package/lib/cjs/common/utils.js +62 -2
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
  9. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  11. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  12. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -1
  13. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +68 -22
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -3
  17. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  18. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  19. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +173 -67
  21. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +179 -84
  22. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  23. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  24. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  25. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  26. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  32. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  33. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  34. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  35. package/lib/cjs/contexts/createReducer.js +8 -0
  36. package/lib/cjs/controller/componentController.js +3 -3
  37. package/lib/esm/common/Constants.js +16 -2
  38. package/lib/esm/common/telemetry/TelemetryConstants.js +21 -3
  39. package/lib/esm/common/utils.js +43 -0
  40. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  41. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  42. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  43. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  44. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  45. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  46. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  47. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  48. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  49. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  50. package/lib/esm/components/livechatwidget/common/endChat.js +65 -22
  51. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -5
  52. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  53. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  54. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  55. package/lib/esm/components/livechatwidget/common/startChat.js +170 -68
  56. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +173 -86
  57. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  58. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  59. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  60. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  61. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  62. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  64. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  65. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  66. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  67. package/lib/esm/contexts/common/ConversationState.js +3 -2
  68. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  69. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  70. package/lib/esm/contexts/createReducer.js +8 -0
  71. package/lib/esm/controller/componentController.js +3 -3
  72. package/lib/types/common/Constants.d.ts +8 -1
  73. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  74. package/lib/types/common/telemetry/TelemetryConstants.d.ts +21 -4
  75. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  76. package/lib/types/common/utils.d.ts +6 -1
  77. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  78. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  79. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  80. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  81. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  82. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  83. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  84. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  85. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  86. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  87. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  88. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  89. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  90. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  91. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  92. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  93. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  94. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  95. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  96. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  97. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  98. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  99. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  100. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  101. package/package.json +2 -2
@@ -17,7 +17,6 @@ export const ConfirmationPaneStateful = props => {
17
17
  const {
18
18
  prepareEndChat
19
19
  } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
20
 
22
21
  const [adapter] = useChatAdapterStore();
23
22
  const controlProps = {
@@ -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) {
@@ -58,8 +58,8 @@ export const HeaderStateful = props => {
58
58
  });
59
59
  },
60
60
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
61
- 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),
62
- 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),
63
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)
64
64
  };
65
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 - {, ¯, "
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 - {, ¯, "
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
  };
@@ -316,7 +316,9 @@ export const dummyDefaultProps = {
316
316
  hideChatTextContainer: false,
317
317
  hideChatSubtitle: false,
318
318
  hideChatTitle: false,
319
- hideNotificationBubble: true
319
+ hideNotificationBubble: true,
320
+ unreadMessageString: "new messages",
321
+ largeUnreadMessageString: "99+"
320
322
  },
321
323
  styleProps: {
322
324
  generalStyleProps: {
@@ -1411,7 +1413,6 @@ export const dummyDefaultProps = {
1411
1413
  startNewChatButtonClassName: undefined
1412
1414
  }
1413
1415
  },
1414
- authClientFunction: undefined,
1415
1416
  isReconnectEnabled: undefined,
1416
1417
  reconnectId: undefined,
1417
1418
  redirectInSameWindow: undefined
@@ -1676,7 +1677,12 @@ export const dummyDefaultProps = {
1676
1677
  MIDDLEWARE_MESSAGE_RETRY: "Retry",
1677
1678
  PRECHAT_REQUIRED_FIELD_MISSING_MESSAGE: "{0} field is required",
1678
1679
  MARKDOWN_EXTERNAL_LINK_ALT: "Opens in a new window; external."
1680
+ },
1681
+ botMagicCode: {
1682
+ disabled: false,
1683
+ fwdUrl: ""
1679
1684
  }
1680
1685
  },
1681
- telemetryConfig: undefined
1686
+ telemetryConfig: undefined,
1687
+ getAuthToken: undefined
1682
1688
  };
@@ -7,21 +7,38 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
7
7
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
8
8
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
9
  import { Constants } from "../../../common/Constants";
10
+ import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
11
 
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
12
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
13
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
13
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
14
14
 
15
15
  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;
16
- 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;
17
- const conversationDetails = await chatSDK.getConversationDetails();
16
+ 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; // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
17
 
19
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
18
+ let conversationDetails = undefined;
19
+
20
+ try {
21
+ conversationDetails = await chatSDK.getConversationDetails();
22
+ } catch (erorr) {
23
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
24
+ Event: TelemetryEvent.GetConversationDetailsException,
25
+ ExceptionDetails: {
26
+ exception: `Failed to get conversation details: ${erorr}`
27
+ }
28
+ });
29
+ }
30
+
31
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
20
32
  const skipEndChatSDK = false;
21
33
  const skipCloseChat = true;
22
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
34
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
23
35
 
24
36
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
37
+ dispatch({
38
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
39
+ payload: ConversationState.PostchatLoading
40
+ });
41
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
25
42
  const loadPostChatEvent = {
26
43
  eventName: BroadcastEvent.LoadPostChatSurvey
27
44
  };
@@ -32,28 +49,21 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
32
49
  payload: ConversationState.InActive
33
50
  });
34
51
  }
35
- } else {
36
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
52
+
53
+ return;
37
54
  }
55
+
56
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
38
57
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
58
 
40
59
 
41
- const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat) => {
60
+ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
42
61
  if (!skipEndChatSDK) {
43
62
  try {
44
63
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
45
64
  Event: TelemetryEvent.EndChatSDKCall
46
65
  });
47
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
48
-
49
- dispatch({
50
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
51
- payload: undefined
52
- });
53
- dispatch({
54
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
55
- payload: undefined
56
- });
66
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
57
67
  } catch (ex) {
58
68
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
59
69
  Event: TelemetryEvent.EndChatSDKCallFailed,
@@ -61,8 +71,23 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
61
71
  exception: ex
62
72
  }
63
73
  });
74
+ postMessageToOtherTab = false;
64
75
  }
65
- }
76
+ } // Need to clear these states immediately when chat ended from OC.
77
+
78
+
79
+ dispatch({
80
+ type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
81
+ payload: undefined
82
+ });
83
+ dispatch({
84
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
85
+ payload: undefined
86
+ });
87
+ dispatch({
88
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
89
+ payload: undefined
90
+ });
66
91
 
67
92
  if (!skipCloseChat) {
68
93
  try {
@@ -90,9 +115,27 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
90
115
  type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
91
116
  payload: null
92
117
  });
93
- BroadcastService.postMessage({
94
- eventName: BroadcastEvent.EndChat
118
+ dispatch({
119
+ type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
120
+ payload: 0
121
+ });
122
+ dispatch({
123
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
124
+ payload: {
125
+ proactiveChatBodyTitle: "",
126
+ proactiveChatEnablePrechat: false,
127
+ proactiveChatInNewWindow: false
128
+ }
95
129
  });
130
+
131
+ if (postMessageToOtherTab) {
132
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
133
+
134
+ const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
135
+ BroadcastService.postMessage({
136
+ eventName: endChatEventName
137
+ });
138
+ }
96
139
  } catch (error) {
97
140
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
98
141
  Event: TelemetryEvent.CloseChatMethodException,
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
7
7
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
8
8
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
9
9
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
10
- import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
10
+ import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
11
11
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
12
12
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
13
13
  import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
@@ -26,10 +26,13 @@ import gifUploadMiddleware from "../../webchatcontainerstateful/webchatcontrolle
26
26
  import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlPlayerMiddleware";
27
27
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
28
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
29
- import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
30
+ import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
31
+ import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
32
+ import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
33
 
31
34
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
32
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21;
35
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
33
36
 
34
37
  const localizedTexts = { ...defaultMiddlewareLocalizedTexts,
35
38
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -63,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
63
66
 
64
67
  if (isPostChatEnabled === "true") {
65
68
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
69
+ WebChatStoreLoader.store = null;
70
+ dispatch({
71
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
+ payload: ConversationState.PostchatLoading
73
+ });
74
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
66
75
  const loadPostChatEvent = {
67
76
  eventName: BroadcastEvent.LoadPostChatSurvey
68
77
  };
@@ -91,7 +100,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
91
100
  };
92
101
 
93
102
  webChatStore = createStore({}, //initial state
94
- preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
+ preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware, // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
104
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
96
105
  WebChatStoreLoader.store = webChatStore;
97
106
  } // Initialize the remaining Web Chat props
@@ -109,7 +118,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
109
118
  groupActivitiesMiddleware: (_props$webChatContain17 = props.webChatContainerProps) !== null && _props$webChatContain17 !== void 0 && (_props$webChatContain18 = _props$webChatContain17.renderingMiddlewareProps) !== null && _props$webChatContain18 !== void 0 && _props$webChatContain18.disableGroupActivitiesMiddleware ? undefined : (_defaultWebChatContai2 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai2 === void 0 ? void 0 : _defaultWebChatContai2.groupActivitiesMiddleware,
110
119
  typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
111
120
  onTelemetry: createWebChatTelemetry(),
112
- ...((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.webChatProps)
121
+ cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
122
+ ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
113
123
  };
114
124
  return webChatProps;
115
125
  };
@@ -29,9 +29,17 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
29
29
 
30
30
 
31
31
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
32
- var _props$reconnectChatP, _props$reconnectChatP2;
32
+ var _props$chatConfig, _props$reconnectChatP;
33
33
 
34
- if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.authClientFunction // TODO: Implement this after storage is in place
34
+ let authClientFunction = undefined;
35
+
36
+ if ((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) {
37
+ var _props$chatConfig2, _props$chatConfig2$Li;
38
+
39
+ authClientFunction = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_javascriptclientfunction) ?? undefined;
40
+ }
41
+
42
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && authClientFunction // TODO: Implement this after storage is in place
35
43
 
36
44
  /* && !isLoadWithState() */
37
45
  ) {
@@ -46,27 +54,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
54
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
55
 
48
56
 
49
- const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
57
+ const handleUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
58
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
59
 
52
60
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
61
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
62
  } else {
55
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
63
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
56
64
  }
57
65
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
66
 
59
67
 
60
- const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
68
+ const startUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
61
69
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
62
70
 
63
71
  if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
72
+ await setReconnectIdAndStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat);
65
73
  }
66
74
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
75
 
68
76
 
69
- const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
77
+ const setReconnectIdAndStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, reconnectId, initStartChat) => {
70
78
  const startUnauthenticatedReconnectChat = {
71
79
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
80
  };
@@ -82,7 +90,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
82
90
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
91
  payload: ConversationState.Loading
84
92
  });
85
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
93
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, optionalParams);
86
94
  };
87
95
 
88
96
  const redirectPage = (redirectURL, redirectInSameWindow) => {
@@ -104,7 +112,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
104
112
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
113
 
106
114
 
107
- const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
115
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat) => {
108
116
  const startUnauthenticatedReconnectChat = {
109
117
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
118
  };
@@ -127,25 +135,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
127
135
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
128
136
  payload: ConversationState.Loading
129
137
  });
130
- await initStartChat(chatSDK, dispatch, setAdapter);
138
+ await initStartChat(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter);
131
139
  }
132
140
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
141
 
134
142
 
135
- const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
143
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
144
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
137
145
 
138
146
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
147
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
148
  }
141
149
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
150
 
143
151
 
144
- const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
152
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
153
  if (reconnectAvailabilityResponse.redirectURL) {
146
154
  redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
155
  } else {
148
- await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
156
+ await startNewChatEmptyRedirectionUrl(chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, initStartChat);
149
157
  }
150
158
  };
151
159
 
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
29
29
 
30
30
 
31
31
  BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
32
- dispatch({
33
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
34
- payload: ConversationState.Loading
35
- });
36
32
  dispatch({
37
33
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
38
34
  payload: ConversationState.Postchat
@@ -0,0 +1,38 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function shareObservable(observable) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+
6
+ let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+
8
+ return new window.Observable(observer => {
9
+ if (!subscription) {
10
+ subscription = observable.subscribe({
11
+ complete() {
12
+ observers.forEach(observer => observer.complete());
13
+ },
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ error(err) {
17
+ observers.forEach(observer => observer.error(err));
18
+ },
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ next(value) {
22
+ observers.forEach(observer => observer.next(value));
23
+ }
24
+
25
+ });
26
+ }
27
+
28
+ observers.push(observer);
29
+ return () => {
30
+ observers = observers.filter(o => o !== observer);
31
+
32
+ if (!observers.length) {
33
+ subscription.unsubscribe();
34
+ subscription = null;
35
+ }
36
+ };
37
+ });
38
+ }