@microsoft/omnichannel-chat-widget 0.1.0-main.488d6f1 → 0.1.0-main.592da7b

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 (115) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +50 -6
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +52 -6
  4. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +17 -6
  6. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  7. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  8. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
  9. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  10. package/lib/cjs/common/utils.js +30 -2
  11. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  12. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  13. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +6 -41
  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 +1 -7
  17. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -15
  18. package/lib/cjs/components/livechatwidget/common/endChat.js +68 -13
  19. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  20. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -6
  21. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +105 -20
  22. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  23. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -5
  24. package/lib/cjs/components/livechatwidget/common/startChat.js +95 -27
  25. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +213 -56
  26. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  27. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -6
  28. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +19 -3
  29. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  30. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -0
  31. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  32. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +25 -48
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +3 -1
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  36. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  37. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  38. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  39. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  40. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +9 -7
  41. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +8 -2
  42. package/lib/cjs/contexts/createReducer.js +16 -10
  43. package/lib/cjs/controller/componentController.js +1 -1
  44. package/lib/cjs/plugins/newMessageEventHandler.js +99 -0
  45. package/lib/esm/common/Constants.js +46 -5
  46. package/lib/esm/common/telemetry/TelemetryConstants.js +48 -5
  47. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  48. package/lib/esm/common/telemetry/TelemetryManager.js +15 -6
  49. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  50. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  51. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
  52. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  53. package/lib/esm/common/utils.js +19 -1
  54. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  55. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  56. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +6 -36
  57. package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
  58. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  59. package/lib/esm/components/headerstateful/HeaderStateful.js +1 -7
  60. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +12 -16
  61. package/lib/esm/components/livechatwidget/common/endChat.js +65 -15
  62. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  63. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +22 -6
  64. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +94 -20
  65. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  66. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +6 -5
  67. package/lib/esm/components/livechatwidget/common/startChat.js +94 -31
  68. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +197 -55
  69. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  70. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -8
  71. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +20 -4
  72. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  73. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -0
  74. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  75. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  76. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +23 -46
  77. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  78. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  79. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  80. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  81. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +6 -6
  82. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  83. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +9 -7
  84. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +8 -2
  85. package/lib/esm/contexts/createReducer.js +16 -9
  86. package/lib/esm/controller/componentController.js +1 -1
  87. package/lib/esm/plugins/newMessageEventHandler.js +82 -0
  88. package/lib/types/common/Constants.d.ts +25 -2
  89. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  90. package/lib/types/common/telemetry/TelemetryConstants.d.ts +37 -4
  91. package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
  92. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  93. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  94. package/lib/types/common/utils.d.ts +3 -0
  95. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  96. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  97. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  98. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -2
  99. package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
  100. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  101. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -1
  102. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -0
  103. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  104. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  105. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  106. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  107. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +0 -1
  108. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  109. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  110. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  111. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  112. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
  113. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -8
  114. package/lib/types/plugins/newMessageEventHandler.d.ts +2 -0
  115. package/package.json +9 -11
@@ -1,17 +1,19 @@
1
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); }
2
2
 
3
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
4
  import { BroadcastService, decodeComponentString } from "@microsoft/omnichannel-chat-components";
4
5
  import { Stack } from "@fluentui/react";
5
6
  import React, { useEffect, useRef, useState } from "react";
6
- import { createTimer, getLocaleDirection } from "../../../common/utils";
7
- import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
8
- import { initStartChat, prepareStartChat } from "../common/startChat";
7
+ import { createTimer, getLocaleDirection, getWidgetCacheId, getWidgetEndChatEventName } from "../../../common/utils";
8
+ import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
9
+ import { initStartChat, prepareStartChat, setupChatState } from "../common/startChat";
9
10
  import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
10
11
  import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
11
12
  import ChatButtonStateful from "../../chatbuttonstateful/ChatButtonStateful";
12
13
  import { Components } from "botframework-webchat";
13
14
  import ConfirmationPaneStateful from "../../confirmationpanestateful/ConfirmationPaneStateful";
14
15
  import { ConversationState } from "../../../contexts/common/ConversationState";
16
+ import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
15
17
  import { ElementType } from "@microsoft/omnichannel-chat-components";
16
18
  import EmailTranscriptPaneStateful from "../../emailtranscriptpanestateful/EmailTranscriptPaneStateful";
17
19
  import HeaderStateful from "../../headerstateful/HeaderStateful";
@@ -23,12 +25,14 @@ import PostChatSurveyPaneStateful from "../../postchatsurveypanestateful/PostCha
23
25
  import PreChatSurveyPaneStateful from "../../prechatsurveypanestateful/PreChatSurveyPaneStateful";
24
26
  import ProactiveChatPaneStateful from "../../proactivechatpanestateful/ProactiveChatPaneStateful";
25
27
  import ReconnectChatPaneStateful from "../../reconnectchatpanestateful/ReconnectChatPaneStateful";
28
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
26
29
  import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
27
30
  import WebChatContainerStateful from "../../webchatcontainerstateful/WebChatContainerStateful";
28
31
  import { createFooter } from "../common/createFooter";
29
32
  import { createInternetConnectionChangeHandler } from "../common/createInternetConnectionChangeHandler";
30
33
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
31
- import { endChat } from "../common/endChat";
34
+ import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
35
+ import { endChat, prepareEndChat } from "../common/endChat";
32
36
  import { getGeneralStylesForButton } from "../common/getGeneralStylesForButton";
33
37
  import { initCallingSdk } from "../common/initCallingSdk";
34
38
  import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
@@ -39,12 +43,8 @@ import { startProactiveChat } from "../common/startProactiveChat";
39
43
  import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
40
44
  import useChatContextStore from "../../../hooks/useChatContextStore";
41
45
  import useChatSDKStore from "../../../hooks/useChatSDKStore";
42
- import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
43
- import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
44
- import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
45
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
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,12 +53,14 @@ 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
60
61
  } = Components;
61
- const canStartProactiveChat = useRef(true); // Process general styles
62
+ const canStartProactiveChat = useRef(true);
63
+ const canEndChat = useRef(true); // Process general styles
62
64
 
63
65
  const generalStyles = {
64
66
  root: Object.assign({}, getGeneralStylesForButton(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
@@ -66,6 +68,33 @@ export const LiveChatWidgetStateful = props => {
66
68
  TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
67
69
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
68
70
  const currentMessageCountRef = useRef(0);
71
+ let widgetStateEventName = "";
72
+
73
+ const initiateEndChatOnBrowserUnload = () => {
74
+ var _DataStoreManager$cli;
75
+
76
+ const persistedState = getStateFromCache(); // End chat if the chat is still active and browser closed
77
+
78
+ if (persistedState.appStates.conversationState === ConversationState.Active) {
79
+ //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
80
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
81
+ } // Clean local storage
82
+
83
+
84
+ (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage");
85
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+
87
+
88
+ const getStateFromCache = () => {
89
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli2;
90
+
91
+ // Getting updated state from cache
92
+ const widgetStateEventName = getWidgetCacheId((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) ?? "");
93
+ const widgetStateFromCache = (_DataStoreManager$cli2 = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.getData(widgetStateEventName, "localStorage");
94
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
95
+ return persistedState;
96
+ };
97
+
69
98
  useEffect(() => {
70
99
  var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
71
100
 
@@ -80,6 +109,10 @@ export const LiveChatWidgetStateful = props => {
80
109
  type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
81
110
  payload: ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.skipChatButtonRendering) || false
82
111
  });
112
+ dispatch({
113
+ type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
114
+ payload: false
115
+ });
83
116
  initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
84
117
  sdkCreated && dispatch({
85
118
  type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
@@ -90,7 +123,7 @@ export const LiveChatWidgetStateful = props => {
90
123
  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) {
91
124
  var _props$reconnectChatP2;
92
125
 
93
- handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
126
+ startUnauthenticatedReconnectChat(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
94
127
  } // Initialize global dir
95
128
 
96
129
 
@@ -100,25 +133,28 @@ export const LiveChatWidgetStateful = props => {
100
133
  payload: globalDir
101
134
  });
102
135
 
103
- if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.chatToken) {
136
+ if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
104
137
  var _state$domainStates2;
105
138
 
106
139
  const optionalParams = {
107
- liveChatContext: {
108
- chatToken: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.chatToken
109
- }
140
+ liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
110
141
  };
111
142
  initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
112
143
  }
113
- }, []);
144
+ }, []); // useEffect for when skip chat button rendering
145
+
114
146
  useEffect(() => {
115
147
  if (state.appStates.skipChatButtonRendering) {
116
148
  var _props$reconnectChatP3;
117
149
 
150
+ BroadcastService.postMessage({
151
+ eventName: BroadcastEvent.ChatInitiated
152
+ });
153
+
118
154
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
119
- var _props$reconnectChatP4;
155
+ var _props$reconnectChatP4, _props$reconnectChatP5;
120
156
 
121
- handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, initStartChat);
157
+ handleUnauthenticatedReconnectChat(chatSDK, 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
158
  } else {
123
159
  getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
124
160
  if (authReconnectId && !state.appStates.reconnectId) {
@@ -131,18 +167,32 @@ export const LiveChatWidgetStateful = props => {
131
167
  payload: ConversationState.ReconnectChat
132
168
  });
133
169
  } else {
134
- dispatch({
135
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
136
- payload: ConversationState.Loading
137
- });
138
- initStartChat(chatSDK, dispatch, setAdapter);
170
+ const chatStartedSkippingChatButtonRendering = {
171
+ eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
172
+ };
173
+ BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
174
+ setupChatState(chatSDK, dispatch, setAdapter);
139
175
  }
140
176
  });
141
177
  }
142
178
  }
143
- }, [state.appStates.skipChatButtonRendering]);
179
+ }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
180
+
144
181
  useEffect(() => {
145
- BroadcastService.getMessageByEventName("StartProactiveChat").subscribe(msg => {
182
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
183
+
184
+ // Add the custom context on receiving the SetCustomContext event
185
+ BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
186
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
187
+ Event: TelemetryEvent.CustomContextReceived,
188
+ Description: "CustomContext received."
189
+ });
190
+ dispatch({
191
+ type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
192
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
193
+ });
194
+ });
195
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
146
196
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
147
197
  Event: TelemetryEvent.StartProactiveChatEventReceived,
148
198
  Description: "Start proactive chat event received."
@@ -158,22 +208,105 @@ export const LiveChatWidgetStateful = props => {
158
208
  Description: "Start proactive chat method called, when chat was already triggered."
159
209
  });
160
210
  }
211
+ }); // Start chat from SDK Event
212
+
213
+ BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
214
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
215
+ Event: TelemetryEvent.StartChatEventRecevied,
216
+ Description: "Start chat event received."
217
+ });
218
+ const persistedState = getStateFromCache();
219
+
220
+ if (persistedState && (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat)) {
221
+ // Embedded mode
222
+ BroadcastService.postMessage({
223
+ eventName: BroadcastEvent.ChatInitiated
224
+ });
225
+ prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
226
+ } else if (!persistedState) {
227
+ // Popout chat
228
+ BroadcastService.postMessage({
229
+ eventName: BroadcastEvent.ChatInitiated
230
+ });
231
+ prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
232
+ } else {
233
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
234
+
235
+ // Minimize to Maximize
236
+ dispatch({
237
+ type: LiveChatWidgetActionType.SET_MINIMIZED,
238
+ payload: false
239
+ });
240
+ BroadcastService.postMessage({
241
+ eventName: BroadcastEvent.MaximizeChat,
242
+ payload: {
243
+ 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,
244
+ 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
245
+ }
246
+ });
247
+ }
248
+ }); // End chat
249
+
250
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
251
+ if (canEndChat.current) {
252
+ prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
253
+ } else {
254
+ const skipEndChatSDK = true;
255
+ const skipCloseChat = false;
256
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
257
+ }
258
+
259
+ BroadcastService.postMessage({
260
+ eventName: BroadcastEvent.CloseChat
261
+ });
161
262
  });
162
- window.addEventListener("beforeunload", event => {
263
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
264
+ initiateEndChatOnBrowserUnload();
265
+ }); // reset proactive chat params
266
+
267
+ BroadcastService.getMessageByEventName(BroadcastEvent.ResetProactiveChatParams).subscribe(async () => {
268
+ dispatch({
269
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
270
+ payload: {
271
+ proactiveChatBodyTitle: "",
272
+ proactiveChatEnablePrechat: false,
273
+ proactiveChatInNewWindow: false
274
+ }
275
+ });
276
+ }); // Listen to end chat event from other tabs
277
+
278
+ const endChatEventName = getWidgetEndChatEventName(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);
279
+ BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
280
+ endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
281
+ }); // Close popout window
282
+
283
+ window.addEventListener("beforeunload", () => {
284
+ TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
285
+ Event: TelemetryEvent.WindowClosed,
286
+ Description: "Closed window."
287
+ });
163
288
  disposeTelemetryLoggers();
164
289
  });
165
290
 
166
291
  if (state.appStates.conversationEndedByAgent) {
167
292
  endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
168
- }
293
+ } //Listen to WidgetSize
294
+
295
+
296
+ BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
297
+ dispatch({
298
+ type: LiveChatWidgetActionType.SET_WIDGET_SIZE,
299
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
300
+ });
301
+ });
169
302
  }, []);
170
303
  useEffect(() => {
171
- canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
304
+ canEndChat.current = state.appStates.conversationState === ConversationState.Active;
172
305
 
173
306
  if (state.appStates.conversationState === ConversationState.Active) {
174
307
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
175
308
  BroadcastService.postMessage({
176
- eventName: "NewMessageNotification"
309
+ eventName: BroadcastEvent.NewMessageNotification
177
310
  });
178
311
  });
179
312
  } // Track the message count
@@ -188,7 +321,10 @@ export const LiveChatWidgetStateful = props => {
188
321
  });
189
322
  });
190
323
  }
191
- }, [state.appStates.conversationState]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
324
+ }, [state.appStates.conversationState]);
325
+ useEffect(() => {
326
+ canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
327
+ }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
192
328
 
193
329
  useEffect(() => {
194
330
  currentMessageCountRef.current = -1;
@@ -198,17 +334,17 @@ export const LiveChatWidgetStateful = props => {
198
334
  });
199
335
  const customEvent = {
200
336
  elementType: ElementType.Custom,
201
- eventName: "UnreadMessageCount",
337
+ eventName: BroadcastEvent.UnreadMessageCount,
202
338
  payload: 0
203
339
  };
204
340
  BroadcastService.postMessage(customEvent);
205
341
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
206
342
 
207
343
  useEffect(() => {
208
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
344
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
209
345
  const customEvent = {
210
346
  elementType: ElementType.Custom,
211
- eventName: "UnreadMessageCount",
347
+ eventName: BroadcastEvent.UnreadMessageCount,
212
348
  payload: `${state.appStates.unreadMessageCount}`
213
349
  };
214
350
  BroadcastService.postMessage(customEvent);
@@ -220,29 +356,35 @@ export const LiveChatWidgetStateful = props => {
220
356
  setWebChatStyles({ ...webChatStyles,
221
357
  ...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
222
358
  });
223
- }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
359
+ }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
360
+
361
+ useEffect(() => {
362
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
363
+
364
+ 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);
365
+ const chatWidgetStateChangeEvent = {
366
+ eventName: widgetStateEventName,
367
+ payload: { ...state
368
+ }
369
+ };
370
+ BroadcastService.postMessage(chatWidgetStateChangeEvent);
371
+ }, [state]);
224
372
  const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
225
373
 
226
374
  const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
375
 
228
376
 
229
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
377
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
378
+
379
+
380
+ const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
230
381
 
231
382
  const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
383
 
233
384
 
234
385
  const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
235
386
 
236
- const confirmationPaneProps = initConfirmationPropsComposer(props); // publish chat widget state
237
-
238
- useEffect(() => {
239
- const chatWidgetStateChangeEvent = {
240
- eventName: TelemetryEvent.ChatWidgetStateChanged,
241
- payload: { ...state
242
- }
243
- };
244
- BroadcastService.postMessage(chatWidgetStateChangeEvent);
245
- }, [state]);
387
+ const confirmationPaneProps = initConfirmationPropsComposer(props);
246
388
  return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
247
389
  styleOptions: webChatStyles,
248
390
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
@@ -250,28 +392,28 @@ export const LiveChatWidgetStateful = props => {
250
392
  id: widgetElementId,
251
393
  styles: generalStyles,
252
394
  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, {
395
+ }, !((_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
396
  buttonProps: props.chatButtonProps,
255
397
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
256
398
  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, {
399
+ })), !((_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
400
  proactiveChatProps: props.proactiveChatPaneProps,
259
401
  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, {
402
+ })), !((_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
403
  headerProps: props.headerProps,
262
404
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
263
405
  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, {
406
+ })), !((_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
407
  reconnectChatProps: props.reconnectChatPaneProps,
266
408
  initStartChat: initStartChatRelay
267
- })), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
409
+ })), !((_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
410
  surveyProps: props.preChatSurveyPaneProps,
269
411
  initStartChat: initStartChatRelay
270
- }), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
412
+ })), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
271
413
  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, {
414
+ }, 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
415
  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))));
416
+ prepareEndChat: prepareEndChatRelay
417
+ }))), !((_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
418
  };
277
419
  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,7 +1,7 @@
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, getWidgetCacheId, parseAdaptiveCardPayload } from "../../common/utils";
5
5
  import { ConversationState } from "../../contexts/common/ConversationState";
6
6
  import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
7
7
  import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
@@ -67,13 +67,14 @@ export const PreChatSurveyPaneStateful = props => {
67
67
  });
68
68
 
69
69
  try {
70
- var _DataStoreManager$cli, _persistedState$domai;
70
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _DataStoreManager$cli, _persistedState$domai;
71
71
 
72
- const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(Constants.widgetStateDataKey, "localStorage");
72
+ const widgetStateCacheId = getWidgetCacheId(((_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) ?? "");
73
+ const widgetStateFromCache = (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateCacheId, "localStorage");
73
74
  const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
74
75
  let optionalParams = {};
75
76
 
76
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
77
+ if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext && !state.appStates.skipChatButtonRendering) {
77
78
  var _persistedState$domai2;
78
79
 
79
80
  optionalParams = {
@@ -83,9 +84,7 @@ export const PreChatSurveyPaneStateful = props => {
83
84
  } else {
84
85
  const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
85
86
  optionalParams = {
86
- initContext: {
87
- preChatResponse: prechatResponseValues
88
- }
87
+ preChatResponse: prechatResponseValues
89
88
  };
90
89
  setPreChatResponseEmail(values);
91
90
  await initStartChat(optionalParams);
@@ -1,4 +1,4 @@
1
- import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
1
+ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
2
  import React, { useEffect, useState } from "react";
3
3
  import { createTimer, setFocusOnElement } from "../../common/utils";
4
4
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
@@ -24,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
@@ -51,7 +59,7 @@ export const ProactiveChatPaneStateful = props => {
51
59
  if (state.appStates.proactiveChatStates.proactiveChatInNewWindow) {
52
60
  // TODO: BroadcastService: replace with the sdk broadcast service, when in place
53
61
  const startPopoutChatEvent = {
54
- eventName: TelemetryEvent.ProactiveChatStartPopoutChat
62
+ eventName: BroadcastEvent.ProactiveChatStartPopoutChat
55
63
  };
56
64
  BroadcastService.postMessage(startPopoutChatEvent);
57
65
  dispatch({
@@ -69,7 +77,7 @@ export const ProactiveChatPaneStateful = props => {
69
77
  });
70
78
  } else {
71
79
  const proactiveChatStarted = {
72
- eventName: TelemetryEvent.ProactiveChatStartChat
80
+ eventName: BroadcastEvent.ProactiveChatStartChat
73
81
  };
74
82
  BroadcastService.postMessage(proactiveChatStarted);
75
83
  await startChat();
@@ -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"));