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

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 (136) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +48 -6
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +36 -3
  4. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
  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 +4 -40
  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 +16 -16
  23. package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
  24. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  25. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +23 -3
  26. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +107 -22
  27. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  28. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  29. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  30. package/lib/cjs/components/livechatwidget/common/startChat.js +138 -50
  31. package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  32. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +223 -68
  33. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  34. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  35. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  36. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  37. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  38. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  39. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  40. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  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/webchattelemetry/WebChatLogger.js +45 -0
  45. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  46. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
  47. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  48. package/lib/cjs/contexts/createReducer.js +16 -10
  49. package/lib/cjs/controller/componentController.js +3 -3
  50. package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
  51. package/lib/esm/common/Constants.js +44 -5
  52. package/lib/esm/common/telemetry/TelemetryConstants.js +36 -3
  53. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  54. package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
  55. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  56. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  57. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  58. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  59. package/lib/esm/common/utils.js +55 -1
  60. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  61. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  62. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -38
  63. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  64. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  65. package/lib/esm/components/headerstateful/HeaderStateful.js +3 -9
  66. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  67. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  68. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  69. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  70. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  71. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +16 -17
  72. package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
  73. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  74. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +21 -5
  75. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +98 -23
  76. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  77. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  78. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  79. package/lib/esm/components/livechatwidget/common/startChat.js +138 -53
  80. package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  81. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +213 -72
  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 +17 -1
  85. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  86. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -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 +16 -2
  90. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  91. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  92. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  93. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  94. package/lib/esm/contexts/common/ConversationState.js +3 -2
  95. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
  96. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -2
  97. package/lib/esm/contexts/createReducer.js +16 -9
  98. package/lib/esm/controller/componentController.js +3 -3
  99. package/lib/esm/plugins/newMessageEventHandler.js +10 -12
  100. package/lib/types/common/Constants.d.ts +24 -2
  101. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  102. package/lib/types/common/telemetry/TelemetryConstants.d.ts +30 -5
  103. package/lib/types/common/telemetry/TelemetryHelper.d.ts +3 -1
  104. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  105. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  106. package/lib/types/common/utils.d.ts +6 -0
  107. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  108. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  109. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  110. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  111. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  112. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  113. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  114. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  115. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  116. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  117. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  118. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  119. package/lib/types/components/livechatwidget/interfaces/IAuthProps.d.ts +4 -0
  120. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  121. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  122. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  123. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  124. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  125. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  126. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  127. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  128. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  129. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  130. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  131. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  132. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  133. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  134. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -1
  135. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
  136. package/package.json +6 -7
@@ -1,12 +1,12 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
4
4
  import { BroadcastService, decodeComponentString } from "@microsoft/omnichannel-chat-components";
5
5
  import { Stack } from "@fluentui/react";
6
6
  import React, { useEffect, useRef, useState } from "react";
7
- import { createTimer, getLocaleDirection } from "../../../common/utils";
8
- import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
9
- import { initStartChat, prepareStartChat } from "../common/startChat";
7
+ import { createTimer, getLocaleDirection, getStateFromCache, getWidgetCacheId, getWidgetEndChatEventName, isUndefinedOrEmpty } from "../../../common/utils";
8
+ import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
9
+ import { initStartChat, prepareStartChat, setPreChatAndInitiateChat } from "../common/startChat";
10
10
  import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
11
11
  import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
12
12
  import ChatButtonStateful from "../../chatbuttonstateful/ChatButtonStateful";
@@ -32,7 +32,7 @@ import { createFooter } from "../common/createFooter";
32
32
  import { createInternetConnectionChangeHandler } from "../common/createInternetConnectionChangeHandler";
33
33
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
34
34
  import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
35
- import { endChat } from "../common/endChat";
35
+ import { endChat, prepareEndChat } from "../common/endChat";
36
36
  import { getGeneralStylesForButton } from "../common/getGeneralStylesForButton";
37
37
  import { initCallingSdk } from "../common/initCallingSdk";
38
38
  import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
@@ -44,7 +44,7 @@ import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
44
44
  import useChatContextStore from "../../../hooks/useChatContextStore";
45
45
  import useChatSDKStore from "../../../hooks/useChatSDKStore";
46
46
  export const LiveChatWidgetStateful = props => {
47
- var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$componentOverr, _props$controlProps6, _props$componentOverr2, _props$controlProps7, _props$componentOverr3, _props$controlProps8, _props$componentOverr4, _props$controlProps9, _props$componentOverr5, _props$controlProps10, _props$componentOverr6, _props$controlProps11, _props$controlProps12, _props$controlProps13, _props$componentOverr7, _props$controlProps14, _props$componentOverr8, _props$controlProps15, _props$componentOverr9, _props$componentOverr10, _props$componentOverr11;
47
+ var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$controlProps6, _props$componentOverr, _props$controlProps7, _props$componentOverr2, _props$controlProps8, _props$componentOverr3, _props$controlProps9, _props$componentOverr4, _props$controlProps10, _props$componentOverr5, _props$controlProps11, _props$componentOverr6, _props$controlProps12, _props$componentOverr7, _props$controlProps13, _props$controlProps14, _props$componentOverr8, _props$controlProps15, _props$componentOverr9, _props$controlProps16, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
48
48
 
49
49
  const [state, dispatch] = useChatContextStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
50
 
@@ -53,7 +53,8 @@ export const LiveChatWidgetStateful = props => {
53
53
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
54
54
  }); // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
55
 
56
- const chatSDK = useChatSDKStore();
56
+ const chatSDK = useChatSDKStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+
57
58
  const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
58
59
  const {
59
60
  Composer
@@ -66,8 +67,37 @@ export const LiveChatWidgetStateful = props => {
66
67
  TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
67
68
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
68
69
  const currentMessageCountRef = useRef(0);
70
+ let widgetStateEventName = "";
71
+
72
+ const initiateEndChatOnBrowserUnload = () => {
73
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli;
74
+
75
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
76
+ Event: TelemetryEvent.BrowserUnloadEventStarted,
77
+ Description: "Browser unload event received."
78
+ });
79
+ const persistedState = getStateFromCache(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); // End chat if the chat is still active and browser closed
80
+
81
+ if (persistedState.appStates.conversationState === ConversationState.Active) {
82
+ //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
83
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
84
+ } // Clean local storage
85
+
86
+
87
+ (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
88
+
89
+ if (voiceVideoCallingSDK) {
90
+ voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
91
+ } //Message for clearing window[popouTab]
92
+
93
+
94
+ BroadcastService.postMessage({
95
+ eventName: BroadcastEvent.ClosePopoutWindow
96
+ });
97
+ };
98
+
69
99
  useEffect(() => {
70
- var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
100
+ var _props$controlProps2, _props$controlProps3, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps4, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
71
101
 
72
102
  registerTelemetryLoggers(props, dispatch);
73
103
  createInternetConnectionChangeHandler();
@@ -80,45 +110,67 @@ export const LiveChatWidgetStateful = props => {
80
110
  type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
81
111
  payload: ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.skipChatButtonRendering) || false
82
112
  });
113
+ dispatch({
114
+ type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
115
+ payload: false
116
+ });
83
117
  initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
84
118
  sdkCreated && dispatch({
85
119
  type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
86
120
  payload: true
87
121
  });
122
+ }); // Initialize global dir
123
+
124
+ const globalDir = ((_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.dir) ?? getLocaleDirection((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Cha = _props$chatConfig.ChatWidgetLanguage) === null || _props$chatConfig$Cha === void 0 ? void 0 : _props$chatConfig$Cha.msdyn_localeid);
125
+ dispatch({
126
+ type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
127
+ payload: globalDir
88
128
  });
89
129
 
90
- if (!((_props$controlProps3 = props.controlProps) !== null && _props$controlProps3 !== void 0 && _props$controlProps3.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
130
+ if (!((_props$controlProps4 = props.controlProps) !== null && _props$controlProps4 !== void 0 && _props$controlProps4.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
91
131
  var _props$reconnectChatP2;
92
132
 
93
- handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
94
- } // Initialize global dir
133
+ startUnauthenticatedReconnectChat(chatSDK, props.authProps, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
134
+ return;
135
+ } // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
136
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
+
138
+
139
+ const isAuthenticationSettingsEnabled = (_props$chatConfig2 = props.chatConfig) !== null && _props$chatConfig2 !== void 0 && (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) !== null && _props$chatConfig2$Li !== void 0 && _props$chatConfig2$Li.msdyn_javascriptclientfunction ? true : false;
140
+
141
+ if (!isAuthenticationSettingsEnabled) {
142
+ var _state$domainStates;
143
+
144
+ if (!isUndefinedOrEmpty((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === ConversationState.Active) {
145
+ var _state$domainStates2;
146
+
147
+ const optionalParams = {
148
+ liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
149
+ };
150
+ initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams);
151
+ return;
152
+ }
153
+ } // All other case should show start chat button, skipChatButtonRendering will take care of it own
95
154
 
96
155
 
97
- const globalDir = ((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.dir) ?? getLocaleDirection((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Cha = _props$chatConfig.ChatWidgetLanguage) === null || _props$chatConfig$Cha === void 0 ? void 0 : _props$chatConfig$Cha.msdyn_localeid);
98
156
  dispatch({
99
- type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
100
- payload: globalDir
157
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
158
+ payload: ConversationState.Closed
101
159
  });
160
+ }, []); // useEffect for when skip chat button rendering
102
161
 
103
- if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.chatToken) {
104
- var _state$domainStates2;
105
-
106
- const optionalParams = {
107
- liveChatContext: {
108
- chatToken: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.chatToken
109
- }
110
- };
111
- initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
112
- }
113
- }, []);
114
162
  useEffect(() => {
115
163
  if (state.appStates.skipChatButtonRendering) {
116
164
  var _props$reconnectChatP3;
117
165
 
166
+ BroadcastService.postMessage({
167
+ eventName: BroadcastEvent.ChatInitiated
168
+ });
169
+
118
170
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
119
- var _props$reconnectChatP4;
171
+ var _props$reconnectChatP4, _props$reconnectChatP5;
120
172
 
121
- handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, initStartChat);
173
+ handleUnauthenticatedReconnectChat(chatSDK, props.authProps, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
122
174
  } else {
123
175
  getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
124
176
  if (authReconnectId && !state.appStates.reconnectId) {
@@ -131,18 +183,32 @@ export const LiveChatWidgetStateful = props => {
131
183
  payload: ConversationState.ReconnectChat
132
184
  });
133
185
  } else {
134
- dispatch({
135
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
136
- payload: ConversationState.Loading
137
- });
138
- initStartChat(chatSDK, dispatch, setAdapter);
186
+ const chatStartedSkippingChatButtonRendering = {
187
+ eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
188
+ };
189
+ BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
190
+ setPreChatAndInitiateChat(chatSDK, props.authProps, dispatch, setAdapter);
139
191
  }
140
192
  });
141
193
  }
142
194
  }
143
- }, [state.appStates.skipChatButtonRendering]);
195
+ }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
196
+
144
197
  useEffect(() => {
145
- BroadcastService.getMessageByEventName("StartProactiveChat").subscribe(msg => {
198
+ var _chatSDK$omnichannelC7, _chatSDK$omnichannelC8;
199
+
200
+ // Add the custom context on receiving the SetCustomContext event
201
+ BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
202
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
203
+ Event: TelemetryEvent.CustomContextReceived,
204
+ Description: "CustomContext received."
205
+ });
206
+ dispatch({
207
+ type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
208
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
209
+ });
210
+ });
211
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
146
212
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
147
213
  Event: TelemetryEvent.StartProactiveChatEventReceived,
148
214
  Description: "Start proactive chat event received."
@@ -158,37 +224,106 @@ export const LiveChatWidgetStateful = props => {
158
224
  Description: "Start proactive chat method called, when chat was already triggered."
159
225
  });
160
226
  }
161
- });
162
- window.addEventListener("beforeunload", () => {
163
- disposeTelemetryLoggers();
164
- });
227
+ }); // Start chat from SDK Event
165
228
 
166
- if (state.appStates.conversationEndedByAgent) {
167
- endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
168
- }
169
- }, []);
170
- useEffect(() => {
171
- canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
229
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
230
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
172
231
 
173
- if (state.appStates.conversationState === ConversationState.Active) {
174
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
232
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
233
+ Event: TelemetryEvent.StartChatEventRecevied,
234
+ Description: "Start chat event received."
235
+ });
236
+ const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId);
237
+
238
+ if (persistedState && (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat)) {
239
+ // Embedded mode
175
240
  BroadcastService.postMessage({
176
- eventName: BroadcastEvent.NewMessageNotification
241
+ eventName: BroadcastEvent.ChatInitiated
242
+ });
243
+ prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
244
+ } else {
245
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
246
+
247
+ // Minimize to Maximize
248
+ dispatch({
249
+ type: LiveChatWidgetActionType.SET_MINIMIZED,
250
+ payload: false
251
+ });
252
+ BroadcastService.postMessage({
253
+ eventName: BroadcastEvent.MaximizeChat,
254
+ payload: {
255
+ height: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.widgetSize) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.height,
256
+ width: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai3 = persistedState.domainStates) === null || _persistedState$domai3 === void 0 ? void 0 : (_persistedState$domai4 = _persistedState$domai3.widgetSize) === null || _persistedState$domai4 === void 0 ? void 0 : _persistedState$domai4.width
257
+ }
177
258
  });
259
+ }
260
+ }); // End chat
261
+
262
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
263
+ if (state.appStates.skipChatButtonRendering !== true) {
264
+ var _chatSDK$omnichannelC5, _chatSDK$omnichannelC6;
265
+
266
+ // This is to ensure to get latest state from cache in multitab
267
+ const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC5 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC5 === void 0 ? void 0 : _chatSDK$omnichannelC5.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC6 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC6 === void 0 ? void 0 : _chatSDK$omnichannelC6.widgetId);
268
+
269
+ if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
270
+ prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
271
+ } else {
272
+ const skipEndChatSDK = true;
273
+ const skipCloseChat = false;
274
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
275
+ }
276
+ }
277
+
278
+ BroadcastService.postMessage({
279
+ eventName: BroadcastEvent.CloseChat
178
280
  });
179
- } // Track the message count
281
+ }); // End chat on browser unload
180
282
 
283
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
284
+ initiateEndChatOnBrowserUnload();
285
+ }); // Listen to end chat event from other tabs
181
286
 
287
+ const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC7 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC7 === void 0 ? void 0 : _chatSDK$omnichannelC7.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC8 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC8 === void 0 ? void 0 : _chatSDK$omnichannelC8.widgetId);
288
+ BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
289
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
290
+ }); // When conversation ended by agent
291
+
292
+ if (state.appStates.conversationEndedByAgent) {
293
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
294
+ } //Listen to WidgetSize, used for minimize to maximize
295
+
296
+
297
+ BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
298
+ dispatch({
299
+ type: LiveChatWidgetActionType.SET_WIDGET_SIZE,
300
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
301
+ });
302
+ });
303
+ return () => {
304
+ disposeTelemetryLoggers();
305
+ };
306
+ }, []);
307
+ useEffect(() => {
308
+ // On new message
182
309
  if (state.appStates.conversationState === ConversationState.Active) {
183
310
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
311
+ // Track the message count
184
312
  currentMessageCountRef.current++;
185
313
  dispatch({
186
314
  type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
187
315
  payload: currentMessageCountRef.current + 1
316
+ }); // New message notification
317
+
318
+ BroadcastService.postMessage({
319
+ eventName: BroadcastEvent.NewMessageNotification
188
320
  });
189
321
  });
190
322
  }
191
- }, [state.appStates.conversationState]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
323
+ }, [state.appStates.conversationState]);
324
+ useEffect(() => {
325
+ canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
326
+ }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
192
327
 
193
328
  useEffect(() => {
194
329
  currentMessageCountRef.current = -1;
@@ -205,7 +340,7 @@ export const LiveChatWidgetStateful = props => {
205
340
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
206
341
 
207
342
  useEffect(() => {
208
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
343
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
209
344
  const customEvent = {
210
345
  elementType: ElementType.Custom,
211
346
  eventName: BroadcastEvent.UnreadMessageCount,
@@ -220,29 +355,35 @@ export const LiveChatWidgetStateful = props => {
220
355
  setWebChatStyles({ ...webChatStyles,
221
356
  ...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
222
357
  });
223
- }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
358
+ }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
359
+
360
+ useEffect(() => {
361
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
362
+
363
+ widgetStateEventName = getWidgetCacheId(props === null || props === void 0 ? void 0 : (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId);
364
+ const chatWidgetStateChangeEvent = {
365
+ eventName: widgetStateEventName,
366
+ payload: { ...state
367
+ }
368
+ };
369
+ BroadcastService.postMessage(chatWidgetStateChangeEvent);
370
+ }, [state]);
224
371
  const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
225
372
 
226
373
  const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
374
 
228
375
 
229
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
376
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
377
 
231
- const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
378
 
379
+ const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
233
380
 
234
- const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
381
+ const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
235
382
 
236
- const confirmationPaneProps = initConfirmationPropsComposer(props); // publish chat widget state
237
383
 
238
- useEffect(() => {
239
- const chatWidgetStateChangeEvent = {
240
- eventName: BroadcastEvent.ChatWidgetStateChanged,
241
- payload: { ...state
242
- }
243
- };
244
- BroadcastService.postMessage(chatWidgetStateChangeEvent);
245
- }, [state]);
384
+ const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
385
+
386
+ const confirmationPaneProps = initConfirmationPropsComposer(props);
246
387
  return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
247
388
  styleOptions: webChatStyles,
248
389
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
@@ -250,28 +391,28 @@ export const LiveChatWidgetStateful = props => {
250
391
  id: widgetElementId,
251
392
  styles: generalStyles,
252
393
  className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
253
- }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
394
+ }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.skipChatButtonRendering) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
254
395
  buttonProps: props.chatButtonProps,
255
396
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
256
397
  startChat: prepareStartChatRelay
257
- })), !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
398
+ })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
258
399
  proactiveChatProps: props.proactiveChatPaneProps,
259
400
  startChat: prepareStartChatRelay
260
- })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
401
+ })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
261
402
  headerProps: props.headerProps,
262
403
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
263
404
  endChat: endChatRelay
264
- })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideLoadingPane) && shouldShowLoadingPane(state) && (decodeComponentString((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/React.createElement(LoadingPaneStateful, props.loadingPaneProps)), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideOutOfOfficeHoursPane) && shouldShowOutOfOfficeHoursPane(state) && (decodeComponentString((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/React.createElement(OutOfOfficeHoursPaneStateful, props.outOfOfficeHoursPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
405
+ })), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideLoadingPane) && shouldShowLoadingPane(state) && (decodeComponentString((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/React.createElement(LoadingPaneStateful, props.loadingPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideOutOfOfficeHoursPane) && shouldShowOutOfOfficeHoursPane(state) && (decodeComponentString((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/React.createElement(OutOfOfficeHoursPaneStateful, props.outOfOfficeHoursPaneProps)), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
265
406
  reconnectChatProps: props.reconnectChatPaneProps,
266
407
  initStartChat: initStartChatRelay
267
- })), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
408
+ })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
268
409
  surveyProps: props.preChatSurveyPaneProps,
269
410
  initStartChat: initStartChatRelay
270
- }), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
411
+ })), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
271
412
  voiceVideoCallingSdk: voiceVideoCallingSDK
272
- }, props.callingContainerProps)), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, props.webChatContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
413
+ }, props.callingContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, props.webChatContainerProps)), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
273
414
  setPostChatContext: setPostChatContextRelay,
274
- endChat: endChatRelay
275
- }))), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
415
+ prepareEndChat: prepareEndChatRelay
416
+ }))), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
276
417
  };
277
418
  export default LiveChatWidgetStateful;
@@ -3,6 +3,8 @@ import { LoadingPane } from "@microsoft/omnichannel-chat-components";
3
3
  import { defaultGeneralPostChatLoadingPaneStyleProps } from "./common/defaultgeneralPostChatLoadingPaneStyleProps";
4
4
  import { findAllFocusableElement } from "../../common/utils";
5
5
  import useChatContextStore from "../../hooks/useChatContextStore";
6
+ import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
7
+ import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
6
8
  export const PostChatLoadingPaneStateful = props => {
7
9
  var _props$styleProps;
8
10
 
@@ -28,6 +30,10 @@ export const PostChatLoadingPaneStateful = props => {
28
30
  if (firstElement && firstElement[0]) {
29
31
  firstElement[0].focus();
30
32
  }
33
+
34
+ TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
35
+ Event: TelemetryEvent.PostChatSurveyLoadingPaneLoaded
36
+ });
31
37
  }, []);
32
38
  return /*#__PURE__*/React.createElement(LoadingPane, {
33
39
  componentOverrides: props.componentOverrides,
@@ -1,9 +1,8 @@
1
- import { Constants, HtmlAttributeNames, Regex } from "../../common/Constants";
1
+ import { HtmlAttributeNames, Regex } from "../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
3
3
  import React, { useEffect } from "react";
4
- import { extractPreChatSurveyResponseValues, findAllFocusableElement, parseAdaptiveCardPayload } from "../../common/utils";
4
+ import { extractPreChatSurveyResponseValues, findAllFocusableElement, getStateFromCache, isUndefinedOrEmpty, parseAdaptiveCardPayload } from "../../common/utils";
5
5
  import { ConversationState } from "../../contexts/common/ConversationState";
6
- import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
7
6
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
8
7
  import { PreChatSurveyPane } from "@microsoft/omnichannel-chat-components";
9
8
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
@@ -67,13 +66,12 @@ export const PreChatSurveyPaneStateful = props => {
67
66
  });
68
67
 
69
68
  try {
70
- var _DataStoreManager$cli, _persistedState$domai;
69
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
71
70
 
72
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
73
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
74
- let optionalParams = {};
71
+ const persistedState = getStateFromCache(((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$t = _state$domainStates.telemetryInternalData) === null || _state$domainStates$t === void 0 ? void 0 : _state$domainStates$t.orgId) ?? "", ((_state$domainStates$t2 = state.domainStates.telemetryInternalData) === null || _state$domainStates$t2 === void 0 ? void 0 : _state$domainStates$t2.widgetId) ?? "");
72
+ let optionalParams = {}; //Connect to Active chats and chat is not popout
75
73
 
76
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
74
+ if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : _persistedState$domai.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active && !state.appStates.skipChatButtonRendering) {
77
75
  var _persistedState$domai2;
78
76
 
79
77
  optionalParams = {
@@ -83,9 +81,7 @@ export const PreChatSurveyPaneStateful = props => {
83
81
  } else {
84
82
  const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
85
83
  optionalParams = {
86
- initContext: {
87
- preChatResponse: prechatResponseValues
88
- }
84
+ preChatResponse: prechatResponseValues
89
85
  };
90
86
  setPreChatResponseEmail(values);
91
87
  await initStartChat(optionalParams);
@@ -24,6 +24,14 @@ export const ProactiveChatPaneStateful = props => {
24
24
  const handleProactiveChatInviteTimeout = () => {
25
25
  if (!timeoutRemoved) {
26
26
  setTimeoutRemoved(true);
27
+ dispatch({
28
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
29
+ payload: {
30
+ proactiveChatBodyTitle: "",
31
+ proactiveChatEnablePrechat: false,
32
+ proactiveChatInNewWindow: false
33
+ }
34
+ });
27
35
  dispatch({
28
36
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
29
37
  payload: ConversationState.Closed
@@ -81,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
81
89
  Event: TelemetryEvent.ProactiveChatClosed,
82
90
  Description: "Proactive chat closed."
83
91
  });
92
+ dispatch({
93
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
94
+ payload: {
95
+ proactiveChatBodyTitle: "",
96
+ proactiveChatEnablePrechat: false,
97
+ proactiveChatInNewWindow: false
98
+ }
99
+ });
84
100
  dispatch({
85
101
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
86
102
  payload: ConversationState.Closed
87
103
  });
88
104
  },
89
105
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
90
- bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ?? (proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText)
106
+ bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ? state.appStates.proactiveChatStates.proactiveChatBodyTitle : proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText
91
107
  };
92
108
  useEffect(() => {
93
109
  setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));