@microsoft/omnichannel-chat-widget 0.1.0-main.8e79cb8 → 0.1.0-main.a72fbb6

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 (87) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +14 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +18 -2
  4. package/lib/cjs/common/utils.js +49 -3
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
  9. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  10. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -2
  11. package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
  12. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -3
  13. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +15 -15
  14. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  15. package/lib/cjs/components/livechatwidget/common/startChat.js +124 -84
  16. package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  17. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +172 -89
  18. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  19. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  20. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  21. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  22. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  23. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  24. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  25. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  26. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  27. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  28. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  29. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  30. package/lib/cjs/contexts/createReducer.js +8 -0
  31. package/lib/cjs/controller/componentController.js +3 -3
  32. package/lib/esm/common/Constants.js +14 -0
  33. package/lib/esm/common/telemetry/TelemetryConstants.js +18 -2
  34. package/lib/esm/common/utils.js +37 -1
  35. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  36. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  37. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  38. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  39. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  40. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +11 -2
  41. package/lib/esm/components/livechatwidget/common/endChat.js +53 -20
  42. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -5
  43. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +17 -16
  44. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  45. package/lib/esm/components/livechatwidget/common/startChat.js +125 -86
  46. package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  47. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +168 -91
  48. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  49. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  50. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  51. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  52. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  53. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  54. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  55. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  56. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  57. package/lib/esm/contexts/common/ConversationState.js +3 -2
  58. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  59. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  60. package/lib/esm/contexts/createReducer.js +8 -0
  61. package/lib/esm/controller/componentController.js +3 -3
  62. package/lib/types/common/Constants.d.ts +7 -0
  63. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  64. package/lib/types/common/telemetry/TelemetryConstants.d.ts +18 -3
  65. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  66. package/lib/types/common/utils.d.ts +3 -0
  67. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  68. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  69. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  70. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  71. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  72. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  73. package/lib/types/components/livechatwidget/interfaces/IAuthProps.d.ts +4 -0
  74. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  75. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  76. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  77. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  78. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  79. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  80. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  81. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  82. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  83. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  84. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  85. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  86. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  87. package/package.json +2 -2
@@ -95,10 +95,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
95
95
 
96
96
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
97
97
 
98
- 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); }
98
+ 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); }
99
99
 
100
100
  const LiveChatWidgetStateful = props => {
101
- 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$componentOverr7, _props$controlProps12, _props$controlProps13, _props$componentOverr8, _props$controlProps14, _props$componentOverr9, _props$controlProps15, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
101
+ 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;
102
102
 
103
103
  const [state, dispatch] = (0, _useChatContextStore.default)(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
104
 
@@ -113,8 +113,7 @@ const LiveChatWidgetStateful = props => {
113
113
  const {
114
114
  Composer
115
115
  } = _botframeworkWebchat.Components;
116
- const canStartProactiveChat = (0, _react2.useRef)(true);
117
- const canEndChat = (0, _react2.useRef)(true); // Process general styles
116
+ const canStartProactiveChat = (0, _react2.useRef)(true); // Process general styles
118
117
 
119
118
  const generalStyles = {
120
119
  root: Object.assign({}, (0, _getGeneralStylesForButton.getGeneralStylesForButton)(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
@@ -122,8 +121,38 @@ const LiveChatWidgetStateful = props => {
122
121
  _TelemetryManager.TelemetryTimers.LcwLoadToChatButtonTimer = (0, _utils.createTimer)();
123
122
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
124
123
  const currentMessageCountRef = (0, _react2.useRef)(0);
124
+ let widgetStateEventName = "";
125
+
126
+ const initiateEndChatOnBrowserUnload = () => {
127
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli;
128
+
129
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
130
+ Event: _TelemetryConstants.TelemetryEvent.BrowserUnloadEventStarted,
131
+ Description: "Browser unload event received."
132
+ });
133
+
134
+ const persistedState = (0, _utils.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
135
+
136
+ if (persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
137
+ //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
138
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
139
+ } // Clean local storage
140
+
141
+
142
+ (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
143
+
144
+ if (voiceVideoCallingSDK) {
145
+ voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
146
+ } //Message for clearing window[popouTab]
147
+
148
+
149
+ _omnichannelChatComponents.BroadcastService.postMessage({
150
+ eventName: _TelemetryConstants.BroadcastEvent.ClosePopoutWindow
151
+ });
152
+ };
153
+
125
154
  (0, _react2.useEffect)(() => {
126
- var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
155
+ var _props$controlProps2, _props$controlProps3, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps4, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
127
156
 
128
157
  (0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
129
158
  (0, _createInternetConnectionChangeHandler.createInternetConnectionChangeHandler)();
@@ -145,38 +174,58 @@ const LiveChatWidgetStateful = props => {
145
174
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
146
175
  payload: true
147
176
  });
177
+ }); // Initialize global dir
178
+
179
+ const globalDir = ((_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.dir) ?? (0, _utils.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);
180
+ dispatch({
181
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
182
+ payload: globalDir
148
183
  });
149
184
 
150
- 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) {
185
+ 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) {
151
186
  var _props$reconnectChatP2;
152
187
 
153
- (0, _reconnectChatHelper.startUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, _startChat.initStartChat);
154
- } // Initialize global dir
188
+ (0, _reconnectChatHelper.startUnauthenticatedReconnectChat)(chatSDK, props.authProps, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, _startChat.initStartChat);
189
+ return;
190
+ } // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
191
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
+
193
+
194
+ 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;
195
+
196
+ if (!isAuthenticationSettingsEnabled) {
197
+ var _state$domainStates;
198
+
199
+ if (!(0, _utils.isUndefinedOrEmpty)((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === _ConversationState.ConversationState.Active) {
200
+ var _state$domainStates2;
201
+
202
+ const optionalParams = {
203
+ liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
204
+ };
205
+ (0, _startChat.initStartChat)(chatSDK, props.authProps, dispatch, setAdapter, optionalParams);
206
+ return;
207
+ }
208
+ } // All other case should show start chat button, skipChatButtonRendering will take care of it own
155
209
 
156
210
 
157
- const globalDir = ((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.dir) ?? (0, _utils.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);
158
211
  dispatch({
159
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
160
- payload: globalDir
212
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
213
+ payload: _ConversationState.ConversationState.Closed
161
214
  });
215
+ }, []); // useEffect for when skip chat button rendering
162
216
 
163
- if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
164
- var _state$domainStates2;
165
-
166
- const optionalParams = {
167
- liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
168
- };
169
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams);
170
- }
171
- }, []);
172
217
  (0, _react2.useEffect)(() => {
173
218
  if (state.appStates.skipChatButtonRendering) {
174
219
  var _props$reconnectChatP3;
175
220
 
221
+ _omnichannelChatComponents.BroadcastService.postMessage({
222
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
223
+ });
224
+
176
225
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
177
226
  var _props$reconnectChatP4, _props$reconnectChatP5;
178
227
 
179
- (0, _reconnectChatHelper.handleUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, _startChat.initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
228
+ (0, _reconnectChatHelper.handleUnauthenticatedReconnectChat)(chatSDK, props.authProps, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, _startChat.initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
180
229
  } else {
181
230
  (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK).then(authReconnectId => {
182
231
  if (authReconnectId && !state.appStates.reconnectId) {
@@ -195,18 +244,15 @@ const LiveChatWidgetStateful = props => {
195
244
 
196
245
  _omnichannelChatComponents.BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
197
246
 
198
- dispatch({
199
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
200
- payload: _ConversationState.ConversationState.Loading
201
- });
202
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter);
247
+ (0, _startChat.setPreChatAndInitiateChat)(chatSDK, props.authProps, dispatch, setAdapter);
203
248
  }
204
249
  });
205
250
  }
206
251
  }
207
- }, [state.appStates.skipChatButtonRendering]);
252
+ }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
253
+
208
254
  (0, _react2.useEffect)(() => {
209
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
255
+ var _chatSDK$omnichannelC7, _chatSDK$omnichannelC8;
210
256
 
211
257
  // Add the custom context on receiving the SetCustomContext event
212
258
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.SetCustomContext).subscribe(msg => {
@@ -221,7 +267,7 @@ const LiveChatWidgetStateful = props => {
221
267
  });
222
268
  });
223
269
 
224
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("StartProactiveChat").subscribe(msg => {
270
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartProactiveChat).subscribe(msg => {
225
271
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
226
272
  Event: _TelemetryConstants.TelemetryEvent.StartProactiveChatEventReceived,
227
273
  Description: "Start proactive chat event received."
@@ -237,79 +283,116 @@ const LiveChatWidgetStateful = props => {
237
283
  Description: "Start proactive chat method called, when chat was already triggered."
238
284
  });
239
285
  }
240
- }); // start chat from SDK Event
286
+ }); // Start chat from SDK Event
287
+
241
288
 
289
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(() => {
290
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
242
291
 
243
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("StartChat").subscribe(() => {
244
292
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
245
293
  Event: _TelemetryConstants.TelemetryEvent.StartChatEventRecevied,
246
294
  Description: "Start chat event received."
247
295
  });
248
296
 
249
- if (state.appStates.isMinimized) {
297
+ const persistedState = (0, _utils.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);
298
+
299
+ if (persistedState && (persistedState.appStates.conversationState === _ConversationState.ConversationState.Closed || persistedState.appStates.conversationState === _ConversationState.ConversationState.InActive || persistedState.appStates.conversationState === _ConversationState.ConversationState.Postchat)) {
300
+ // Embedded mode
301
+ _omnichannelChatComponents.BroadcastService.postMessage({
302
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
303
+ });
304
+
305
+ (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
306
+ } else {
307
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
308
+
309
+ // Minimize to Maximize
250
310
  dispatch({
251
311
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
252
312
  payload: false
253
313
  });
254
- } else {
255
- (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
314
+
315
+ _omnichannelChatComponents.BroadcastService.postMessage({
316
+ eventName: _TelemetryConstants.BroadcastEvent.MaximizeChat,
317
+ payload: {
318
+ 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,
319
+ 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
320
+ }
321
+ });
256
322
  }
257
- }); // end chat from SDK Event
323
+ }); // End chat
258
324
 
259
325
 
260
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("EndChat").subscribe(async () => {
261
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
262
- Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
263
- Description: "End chat event received."
264
- });
326
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async () => {
327
+ if (state.appStates.skipChatButtonRendering !== true) {
328
+ var _chatSDK$omnichannelC5, _chatSDK$omnichannelC6;
265
329
 
266
- if (canEndChat.current) {
267
- (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
268
- } else {
269
- const skipEndChatSDK = true;
270
- const skipCloseChat = false;
271
- (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
330
+ // This is to ensure to get latest state from cache in multitab
331
+ const persistedState = (0, _utils.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);
332
+
333
+ if (persistedState && persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
334
+ (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
335
+ } else {
336
+ const skipEndChatSDK = true;
337
+ const skipCloseChat = false;
338
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
339
+ }
272
340
  }
341
+
342
+ _omnichannelChatComponents.BroadcastService.postMessage({
343
+ eventName: _TelemetryConstants.BroadcastEvent.CloseChat
344
+ });
345
+ }); // End chat on browser unload
346
+
347
+
348
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
349
+ initiateEndChatOnBrowserUnload();
273
350
  }); // Listen to end chat event from other tabs
274
351
 
275
352
 
276
- const endChatEventName = (0, _utils.getWidgetEndChatEventName)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
353
+ const endChatEventName = (0, _utils.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);
277
354
 
278
355
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
279
356
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
280
- });
357
+ }); // When conversation ended by agent
281
358
 
282
- window.addEventListener("beforeunload", () => {
283
- (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
284
- });
285
359
 
286
360
  if (state.appStates.conversationEndedByAgent) {
287
361
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
288
- }
289
- }, []);
290
- (0, _react2.useEffect)(() => {
291
- canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed;
292
- canEndChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Active;
362
+ } //Listen to WidgetSize, used for minimize to maximize
293
363
 
294
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
295
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
296
- _omnichannelChatComponents.BroadcastService.postMessage({
297
- eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
298
- });
299
- });
300
- } // Track the message count
301
364
 
365
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
366
+ dispatch({
367
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_SIZE,
368
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
369
+ });
370
+ });
302
371
 
372
+ return () => {
373
+ (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
374
+ };
375
+ }, []);
376
+ (0, _react2.useEffect)(() => {
377
+ // On new message
303
378
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
304
379
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
380
+ // Track the message count
305
381
  currentMessageCountRef.current++;
306
382
  dispatch({
307
383
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
308
384
  payload: currentMessageCountRef.current + 1
385
+ }); // New message notification
386
+
387
+ _omnichannelChatComponents.BroadcastService.postMessage({
388
+ eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
309
389
  });
310
390
  });
311
391
  }
312
- }, [state.appStates.conversationState]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
392
+ }, [state.appStates.conversationState]);
393
+ (0, _react2.useEffect)(() => {
394
+ canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
395
+ }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
313
396
 
314
397
  (0, _react2.useEffect)(() => {
315
398
  currentMessageCountRef.current = -1;
@@ -327,7 +410,7 @@ const LiveChatWidgetStateful = props => {
327
410
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
328
411
 
329
412
  (0, _react2.useEffect)(() => {
330
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
413
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
331
414
  const customEvent = {
332
415
  elementType: _omnichannelChatComponents.ElementType.Custom,
333
416
  eventName: _TelemetryConstants.BroadcastEvent.UnreadMessageCount,
@@ -343,7 +426,20 @@ const LiveChatWidgetStateful = props => {
343
426
  setWebChatStyles({ ...webChatStyles,
344
427
  ...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
345
428
  });
346
- }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
429
+ }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
430
+
431
+ (0, _react2.useEffect)(() => {
432
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
433
+
434
+ widgetStateEventName = (0, _utils.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);
435
+ const chatWidgetStateChangeEvent = {
436
+ eventName: widgetStateEventName,
437
+ payload: { ...state
438
+ }
439
+ };
440
+
441
+ _omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
442
+ }, [state]);
347
443
  const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, chatSDK, state, dispatch, setWebChatStyles);
348
444
 
349
445
  const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -357,22 +453,9 @@ const LiveChatWidgetStateful = props => {
357
453
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
358
454
 
359
455
 
360
- const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
361
-
362
- const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props); // publish chat widget state
456
+ const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, props.authProps, dispatch, setAdapter, optionalParams, persistedState);
363
457
 
364
- (0, _react2.useEffect)(() => {
365
- var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
366
-
367
- const widgetStateEventName = (0, _utils.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);
368
- const chatWidgetStateChangeEvent = {
369
- eventName: widgetStateEventName,
370
- payload: { ...state
371
- }
372
- };
373
-
374
- _omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
375
- }, [state]);
458
+ const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
376
459
  return /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
377
460
  styleOptions: webChatStyles,
378
461
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.directLine
@@ -380,29 +463,29 @@ const LiveChatWidgetStateful = props => {
380
463
  id: widgetElementId,
381
464
  styles: generalStyles,
382
465
  className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
383
- }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
466
+ }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.skipChatButtonRendering) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
384
467
  buttonProps: props.chatButtonProps,
385
468
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
386
469
  startChat: prepareStartChatRelay
387
- })), !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.hideProactiveChatPane) && (0, _componentController.shouldShowProactiveChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/_react2.default.createElement(_ProactiveChatPaneStateful.default, {
470
+ })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideProactiveChatPane) && (0, _componentController.shouldShowProactiveChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/_react2.default.createElement(_ProactiveChatPaneStateful.default, {
388
471
  proactiveChatProps: props.proactiveChatPaneProps,
389
472
  startChat: prepareStartChatRelay
390
- })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideHeader) && (0, _componentController.shouldShowHeader)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/_react2.default.createElement(_HeaderStateful.default, {
473
+ })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideHeader) && (0, _componentController.shouldShowHeader)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/_react2.default.createElement(_HeaderStateful.default, {
391
474
  headerProps: props.headerProps,
392
475
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
393
476
  endChat: endChatRelay
394
- })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideLoadingPane) && (0, _componentController.shouldShowLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/_react2.default.createElement(_LoadingPaneStateful.default, props.loadingPaneProps)), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideOutOfOfficeHoursPane) && (0, _componentController.shouldShowOutOfOfficeHoursPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/_react2.default.createElement(_OOOHPaneStateful.default, props.outOfOfficeHoursPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideReconnectChatPane) && (0, _componentController.shouldShowReconnectChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/_react2.default.createElement(_ReconnectChatPaneStateful.default, {
477
+ })), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideLoadingPane) && (0, _componentController.shouldShowLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/_react2.default.createElement(_LoadingPaneStateful.default, props.loadingPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideOutOfOfficeHoursPane) && (0, _componentController.shouldShowOutOfOfficeHoursPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/_react2.default.createElement(_OOOHPaneStateful.default, props.outOfOfficeHoursPaneProps)), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hideReconnectChatPane) && (0, _componentController.shouldShowReconnectChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/_react2.default.createElement(_ReconnectChatPaneStateful.default, {
395
478
  reconnectChatProps: props.reconnectChatPaneProps,
396
479
  initStartChat: initStartChatRelay
397
- })), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hidePreChatSurveyPane) && (0, _componentController.shouldShowPreChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PreChatSurveyPaneStateful.default, {
480
+ })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hidePreChatSurveyPane) && (0, _componentController.shouldShowPreChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PreChatSurveyPaneStateful.default, {
398
481
  surveyProps: props.preChatSurveyPaneProps,
399
482
  initStartChat: initStartChatRelay
400
- })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
483
+ })), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
401
484
  voiceVideoCallingSdk: voiceVideoCallingSDK
402
- }, props.callingContainerProps)), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideWebChatContainer) && (0, _componentController.shouldShowWebChatContainer)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/_react2.default.createElement(_WebChatContainerStateful.default, props.webChatContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideConfirmationPane) && (0, _componentController.shouldShowConfirmationPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/_react2.default.createElement(_ConfirmationPaneStateful.default, _extends({}, confirmationPaneProps, {
485
+ }, props.callingContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideWebChatContainer) && (0, _componentController.shouldShowWebChatContainer)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/_react2.default.createElement(_WebChatContainerStateful.default, props.webChatContainerProps)), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideConfirmationPane) && (0, _componentController.shouldShowConfirmationPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/_react2.default.createElement(_ConfirmationPaneStateful.default, _extends({}, confirmationPaneProps, {
403
486
  setPostChatContext: setPostChatContextRelay,
404
487
  prepareEndChat: prepareEndChatRelay
405
- }))), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hidePostChatLoadingPane) && (0, _componentController.shouldShowPostChatLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/_react2.default.createElement(_PostChatLoadingPaneStateful.default, props.postChatLoadingPaneProps)), (0, _componentController.shouldShowPostChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PostChatSurveyPaneStateful.default, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), (0, _createFooter.createFooter)(props, state), (0, _componentController.shouldShowEmailTranscriptPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/_react2.default.createElement(_EmailTranscriptPaneStateful.default, props.emailTranscriptPane))));
488
+ }))), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hidePostChatLoadingPane) && (0, _componentController.shouldShowPostChatLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/_react2.default.createElement(_PostChatLoadingPaneStateful.default, props.postChatLoadingPaneProps)), (0, _componentController.shouldShowPostChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PostChatSurveyPaneStateful.default, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), (0, _createFooter.createFooter)(props, state), (0, _componentController.shouldShowEmailTranscriptPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/_react2.default.createElement(_EmailTranscriptPaneStateful.default, props.emailTranscriptPane))));
406
489
  };
407
490
 
408
491
  exports.LiveChatWidgetStateful = LiveChatWidgetStateful;
@@ -15,8 +15,6 @@ var _utils = require("../../common/utils");
15
15
 
16
16
  var _ConversationState = require("../../contexts/common/ConversationState");
17
17
 
18
- var _DataStoreManager = require("../../common/contextDataStore/DataStoreManager");
19
-
20
18
  var _LiveChatWidgetActionType = require("../../contexts/common/LiveChatWidgetActionType");
21
19
 
22
20
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
@@ -93,14 +91,12 @@ const PreChatSurveyPaneStateful = props => {
93
91
  });
94
92
 
95
93
  try {
96
- var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _DataStoreManager$cli, _persistedState$domai;
94
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
97
95
 
98
- const widgetStateCacheId = (0, _utils.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) ?? "");
99
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateCacheId, "localStorage");
100
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
101
- let optionalParams = {};
96
+ const persistedState = (0, _utils.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) ?? "");
97
+ let optionalParams = {}; //Connect to Active chats and chat is not popout
102
98
 
103
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
99
+ if (persistedState && !(0, _utils.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.ConversationState.Active && !state.appStates.skipChatButtonRendering) {
104
100
  var _persistedState$domai2;
105
101
 
106
102
  optionalParams = {
@@ -46,6 +46,14 @@ const ProactiveChatPaneStateful = props => {
46
46
  const handleProactiveChatInviteTimeout = () => {
47
47
  if (!timeoutRemoved) {
48
48
  setTimeoutRemoved(true);
49
+ dispatch({
50
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
51
+ payload: {
52
+ proactiveChatBodyTitle: "",
53
+ proactiveChatEnablePrechat: false,
54
+ proactiveChatInNewWindow: false
55
+ }
56
+ });
49
57
  dispatch({
50
58
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
51
59
  payload: _ConversationState.ConversationState.Closed
@@ -111,13 +119,21 @@ const ProactiveChatPaneStateful = props => {
111
119
  Description: "Proactive chat closed."
112
120
  });
113
121
 
122
+ dispatch({
123
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
124
+ payload: {
125
+ proactiveChatBodyTitle: "",
126
+ proactiveChatEnablePrechat: false,
127
+ proactiveChatInNewWindow: false
128
+ }
129
+ });
114
130
  dispatch({
115
131
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
116
132
  payload: _ConversationState.ConversationState.Closed
117
133
  });
118
134
  },
119
135
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
120
- 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)
136
+ 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
121
137
  };
122
138
  (0, _react.useEffect)(() => {
123
139
  (0, _utils.setFocusOnElement)(document.getElementById(controlProps.id + "-startbutton"));
@@ -25,15 +25,53 @@ var _utils = require("../../common/utils");
25
25
 
26
26
  var _ = require("../..");
27
27
 
28
+ var _WebChatActionType = require("./webchatcontroller/enums/WebChatActionType");
29
+
30
+ var _WebChatStoreLoader = require("./webchatcontroller/WebChatStoreLoader");
31
+
32
+ var _Constants = require("../../common/Constants");
33
+
34
+ var _BotMagicCodeStore = require("./webchatcontroller/BotMagicCodeStore");
35
+
28
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
37
 
30
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
39
 
40
+ const broadcastChannelMessageEvent = "message";
41
+
42
+ const postActivity = activity => {
43
+ // eslint-disable-line @typescript-eslint/no-explicit-any
44
+ return {
45
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_POST_ACTIVITY,
46
+ meta: {
47
+ method: "keyboard"
48
+ },
49
+ payload: {
50
+ activity: {
51
+ channelData: undefined,
52
+ text: "",
53
+ textFormat: "plain",
54
+ type: _Constants.Constants.message,
55
+ ...activity
56
+ }
57
+ }
58
+ };
59
+ };
60
+
61
+ const createMagicCodeSuccessResponse = signin => {
62
+ return {
63
+ signin,
64
+ result: "Success"
65
+ };
66
+ };
67
+
32
68
  const WebChatContainerStateful = props => {
33
69
  const {
34
70
  BasicWebChat
35
71
  } = _botframeworkWebchat.Components;
36
72
  const [state, dispatch] = (0, _.useChatContextStore)();
73
+ const magicCodeBroadcastChannel = new BroadcastChannel(_Constants.Constants.magicCodeBroadcastChannel);
74
+ const magicCodeResponseBroadcastChannel = new BroadcastChannel(_Constants.Constants.magicCodeResponseBroadcastChannel);
37
75
  const containerStyles = {
38
76
  root: Object.assign({}, _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.containerStyles, props === null || props === void 0 ? void 0 : props.containerStyles, {
39
77
  display: state.appStates.isMinimized ? "none" : ""
@@ -58,6 +96,48 @@ const WebChatContainerStateful = props => {
58
96
  Event: _TelemetryConstants.TelemetryEvent.WebChatLoaded
59
97
  });
60
98
  }, []);
99
+ (0, _react2.useEffect)(() => {
100
+ const eventListener = event => {
101
+ // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-function
102
+ const {
103
+ data
104
+ } = event;
105
+
106
+ if (_BotMagicCodeStore.BotMagicCodeStore.botOAuthSignInId === data.signin) {
107
+ const {
108
+ signin,
109
+ code
110
+ } = data;
111
+ const text = `${code}`;
112
+ const action = postActivity({
113
+ text,
114
+ channelData: {
115
+ tags: [_Constants.Constants.hiddenTag]
116
+ }
117
+ });
118
+
119
+ _WebChatStoreLoader.WebChatStoreLoader.store.dispatch(action);
120
+
121
+ const response = createMagicCodeSuccessResponse(signin);
122
+ magicCodeResponseBroadcastChannel.postMessage(response);
123
+
124
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
125
+ Event: _TelemetryConstants.TelemetryEvent.SuppressBotMagicCodeSucceeded
126
+ });
127
+
128
+ _BotMagicCodeStore.BotMagicCodeStore.botOAuthSignInId = "";
129
+ magicCodeBroadcastChannel.close();
130
+ magicCodeResponseBroadcastChannel.close();
131
+ } else {
132
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
133
+ Event: _TelemetryConstants.TelemetryEvent.SuppressBotMagicCodeFailed,
134
+ Description: "Signin does not match"
135
+ });
136
+ }
137
+ };
138
+
139
+ magicCodeBroadcastChannel.addEventListener(broadcastChannelMessageEvent, eventListener);
140
+ }, []);
61
141
  return /*#__PURE__*/_react2.default.createElement(_react2.default.Fragment, null, /*#__PURE__*/_react2.default.createElement("style", null, `
62
142
  .ms_lcw_webchat_received_message img.webchat__markdown__external-link-icon {
63
143
  background-image : url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIzIDMgMTggMTgiICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik03LjI1MDEgNC41MDAxN0gxMC43NDk1QzExLjE2MzcgNC41MDAxNyAxMS40OTk1IDQuODM1OTYgMTEuNDk5NSA1LjI1MDE3QzExLjQ5OTUgNS42Mjk4NiAxMS4yMTczIDUuOTQzNjYgMTAuODUxMyA1Ljk5MzMyTDEwLjc0OTUgNi4wMDAxN0g3LjI0OTc0QzYuMDcwNzkgNS45OTk2MSA1LjEwMzQ5IDYuOTA2NTYgNS4wMDc4NiA4LjA2MTEyTDUuMDAwMjggOC4yMjAwM0w1LjAwMzEyIDE2Ljc1MDdDNS4wMDM0MyAxNy45NDE1IDUuOTI4ODUgMTguOTE2MSA3LjA5OTY2IDE4Ljk5NDlMNy4yNTM3MSAxOS4wMDAxTDE1Ljc1MTggMTguOTg4NEMxNi45NDE1IDE4Ljk4NjggMTcuOTE0NSAxOC4wNjIgMTcuOTkzNSAxNi44OTIzTDE3Ljk5ODcgMTYuNzM4NFYxMy4yMzIxQzE3Ljk5ODcgMTIuODE3OSAxOC4zMzQ1IDEyLjQ4MjEgMTguNzQ4NyAxMi40ODIxQzE5LjEyODQgMTIuNDgyMSAxOS40NDIyIDEyLjc2NDMgMTkuNDkxOCAxMy4xMzAzTDE5LjQ5ODcgMTMuMjMyMVYxNi43Mzg0QzE5LjQ5ODcgMTguNzQwNyAxNy45MjkzIDIwLjM3NjkgMTUuOTUyOCAyMC40ODI5TDE1Ljc1MzggMjAuNDg4NEw3LjI1ODI3IDIwLjUwMDFMNy4wNTQ5NSAyMC40OTQ5QzUuMTQyMzkgMjAuMzk1NCAzLjYwODk1IDE4Ljg2MjcgMy41MDgzNyAxNi45NTAyTDMuNTAzMTIgMTYuNzUxMUwzLjUwMDg5IDguMjUyN0wzLjUwNTI5IDguMDUwMkMzLjYwNTM5IDYuMTM3NDkgNS4xMzg2NyA0LjYwNDQ5IDcuMDUwOTYgNC41MDUyN0w3LjI1MDEgNC41MDAxN0gxMC43NDk1SDcuMjUwMVpNMTMuNzQ4MSAzLjAwMTQ2TDIwLjMwMTggMy4wMDE5N0wyMC40MDE0IDMuMDE1NzVMMjAuNTAyMiAzLjA0MzkzTDIwLjU1OSAzLjA2ODAzQzIwLjYxMjIgMy4wOTEyMiAyMC42NjM0IDMuMTIxNjMgMjAuNzExMSAzLjE1ODg1TDIwLjc4MDQgMy4yMjE1NkwyMC44NjQxIDMuMzIwMTRMMjAuOTE4MyAzLjQxMDI1TDIwLjk1NyAzLjUwMDU3TDIwLjk3NjIgMy41NjQ3NkwyMC45ODk4IDMuNjI4NjJMMjAuOTk5MiAzLjcyMjgyTDIwLjk5OTcgMTAuMjU1NEMyMC45OTk3IDEwLjY2OTYgMjAuNjYzOSAxMS4wMDU0IDIwLjI0OTcgMTEuMDA1NEMxOS44NyAxMS4wMDU0IDE5LjU1NjIgMTAuNzIzMiAxOS41MDY1IDEwLjM1NzFMMTkuNDk5NyAxMC4yNTU0TDE5LjQ5ODkgNS41NjE0N0wxMi4yNzk3IDEyLjc4NDdDMTIuMDEzNCAxMy4wNTEgMTEuNTk2OCAxMy4wNzUzIDExLjMwMzEgMTIuODU3NUwxMS4yMTkgMTIuNzg0OUMxMC45NTI3IDEyLjUxODcgMTAuOTI4NCAxMi4xMDIxIDExLjE0NjIgMTEuODA4NEwxMS4yMTg4IDExLjcyNDNMMTguNDM2OSA0LjUwMTQ2SDEzLjc0ODFDMTMuMzY4NCA0LjUwMTQ2IDEzLjA1NDYgNC4yMTkzMSAxMy4wMDUgMy44NTMyNEwxMi45OTgxIDMuNzUxNDZDMTIuOTk4MSAzLjM3MTc3IDEzLjI4MDMgMy4wNTc5NyAxMy42NDY0IDMuMDA4MzFMMTMuNzQ4MSAzLjAwMTQ2WiIgZmlsbD0iI0ZGRkZGRiIgLz48L3N2Zz4) !important;