@microsoft/omnichannel-chat-widget 1.5.1-main.132e1c6 → 1.5.1-main.c3533cf

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.
@@ -11,23 +11,38 @@ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants"
11
11
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  const handleChatDisconnect = (props, state, setWebChatStyles) => {
14
- var _state$appStates;
15
- if (state !== null && state !== void 0 && (_state$appStates = state.appStates) !== null && _state$appStates !== void 0 && _state$appStates.chatDisconnectEventReceived) {
16
- var _state$domainStates, _state$domainStates$m, _props$webChatContain, _props$webChatContain2;
17
- const chatDisconnectMessage = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$m = _state$domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_BANNER_CHAT_DISCONNECT) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_CHAT_DISCONNECT;
18
- if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
19
- setWebChatStyles(styles => {
20
- return {
21
- ...styles,
22
- hideSendBox: true
23
- };
14
+ var _state$appStates, _state$domainStates, _state$domainStates$m, _props$webChatContain, _props$webChatContain2;
15
+ const chatDisconnectState = state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.chatDisconnectEventReceived;
16
+ const chatDisconnectMessage = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$m = _state$domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_BANNER_CHAT_DISCONNECT) ?? _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_CHAT_DISCONNECT;
17
+ const hideSendBoxOnConversationEnd = props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd;
18
+ switch (chatDisconnectState) {
19
+ case true:
20
+ if (hideSendBoxOnConversationEnd !== false) {
21
+ setWebChatStyles(styles => {
22
+ return {
23
+ ...styles,
24
+ hideSendBox: true
25
+ };
26
+ });
27
+ }
28
+ _NotificationHandler.NotificationHandler.notifyWarning(_NotificationScenarios.NotificationScenarios.ChatDisconnect, chatDisconnectMessage);
29
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
30
+ Event: _TelemetryConstants.TelemetryEvent.ChatDisconnectThreadEventReceived,
31
+ Description: "Chat disconnected due to timeout, left or removed."
24
32
  });
25
- }
26
- _NotificationHandler.NotificationHandler.notifyWarning(_NotificationScenarios.NotificationScenarios.ChatDisconnect, chatDisconnectMessage);
27
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
28
- Event: _TelemetryConstants.TelemetryEvent.ChatDisconnectThreadEventReceived,
29
- Description: "Chat disconnected due to timeout, left or removed."
30
- });
33
+ break;
34
+ case false:
35
+ if (hideSendBoxOnConversationEnd !== false) {
36
+ setWebChatStyles(styles => {
37
+ return {
38
+ ...styles,
39
+ hideSendBox: false
40
+ };
41
+ });
42
+ }
43
+ break;
44
+ default:
45
+ break;
31
46
  }
32
47
  };
33
48
  exports.handleChatDisconnect = handleChatDisconnect;
@@ -21,6 +21,7 @@ var _newMessageEventHandler = require("../../../plugins/newMessageEventHandler")
21
21
  var _reconnectChatHelper = require("./reconnectChatHelper");
22
22
  var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
23
23
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
24
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
24
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
26
  let optionalParams = {};
26
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -119,8 +120,20 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
119
120
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
120
121
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
121
122
  const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
123
+ if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
124
+ // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
125
+ chatSDK.requestId = (0, _omnichannelChatSdk.uuidv4)();
126
+ chatSDK.chatToken = {};
127
+ chatSDK.reconnectId = null;
128
+ }
122
129
  try {
123
- var _newAdapter$activity$, _TelemetryTimers$Widg2;
130
+ var _state$appStates, _newAdapter$activity$, _TelemetryTimers$Widg2;
131
+ // Clear disconnect state on start chat
132
+ (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.chatDisconnectEventReceived) && dispatch({
133
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
134
+ payload: false
135
+ });
136
+
124
137
  //Start widget load timer
125
138
  _TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
126
139
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -274,7 +287,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
274
287
  });
275
288
 
276
289
  // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
277
- // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
290
+ // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
278
291
  if (isStartChatSuccessful === true) {
279
292
  await forceEndChat(chatSDK);
280
293
  }
@@ -298,9 +311,9 @@ const forceEndChat = async chatSDK => {
298
311
 
299
312
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
313
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
301
- var _state$appStates, _persistedState$domai6, _persistedState$appSt;
314
+ var _state$appStates2, _persistedState$domai6, _persistedState$appSt;
302
315
  // By pass this function in case of popout chat
303
- if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.hideStartChatButton) === true) {
316
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.hideStartChatButton) === true) {
304
317
  return false;
305
318
  }
306
319
  const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
@@ -616,9 +616,7 @@ const LiveChatWidgetStateful = props => {
616
616
 
617
617
  // Handle Chat disconnect cases
618
618
  (0, _react2.useEffect)(() => {
619
- if (state.appStates.chatDisconnectEventReceived) {
620
- (0, _chatDisconnectHelper.handleChatDisconnect)(props, state, setWebChatStyles);
621
- }
619
+ (0, _chatDisconnectHelper.handleChatDisconnect)(props, state, setWebChatStyles);
622
620
  }, [state.appStates.chatDisconnectEventReceived]);
623
621
  const initiateEndChatOnBrowserUnload = () => {
624
622
  var _DataStoreManager$cli;
@@ -5,23 +5,38 @@ import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryCon
5
5
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
6
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
7
  const handleChatDisconnect = (props, state, setWebChatStyles) => {
8
- var _state$appStates;
9
- if (state !== null && state !== void 0 && (_state$appStates = state.appStates) !== null && _state$appStates !== void 0 && _state$appStates.chatDisconnectEventReceived) {
10
- var _state$domainStates, _state$domainStates$m, _props$webChatContain, _props$webChatContain2;
11
- const chatDisconnectMessage = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$m = _state$domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_BANNER_CHAT_DISCONNECT) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_CHAT_DISCONNECT;
12
- if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
13
- setWebChatStyles(styles => {
14
- return {
15
- ...styles,
16
- hideSendBox: true
17
- };
8
+ var _state$appStates, _state$domainStates, _state$domainStates$m, _props$webChatContain, _props$webChatContain2;
9
+ const chatDisconnectState = state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.chatDisconnectEventReceived;
10
+ const chatDisconnectMessage = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$m = _state$domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_BANNER_CHAT_DISCONNECT) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_CHAT_DISCONNECT;
11
+ const hideSendBoxOnConversationEnd = props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd;
12
+ switch (chatDisconnectState) {
13
+ case true:
14
+ if (hideSendBoxOnConversationEnd !== false) {
15
+ setWebChatStyles(styles => {
16
+ return {
17
+ ...styles,
18
+ hideSendBox: true
19
+ };
20
+ });
21
+ }
22
+ NotificationHandler.notifyWarning(NotificationScenarios.ChatDisconnect, chatDisconnectMessage);
23
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
24
+ Event: TelemetryEvent.ChatDisconnectThreadEventReceived,
25
+ Description: "Chat disconnected due to timeout, left or removed."
18
26
  });
19
- }
20
- NotificationHandler.notifyWarning(NotificationScenarios.ChatDisconnect, chatDisconnectMessage);
21
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
22
- Event: TelemetryEvent.ChatDisconnectThreadEventReceived,
23
- Description: "Chat disconnected due to timeout, left or removed."
24
- });
27
+ break;
28
+ case false:
29
+ if (hideSendBoxOnConversationEnd !== false) {
30
+ setWebChatStyles(styles => {
31
+ return {
32
+ ...styles,
33
+ hideSendBox: false
34
+ };
35
+ });
36
+ }
37
+ break;
38
+ default:
39
+ break;
25
40
  }
26
41
  };
27
42
  export { handleChatDisconnect };
@@ -15,6 +15,7 @@ import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEv
15
15
  import { handleChatReconnect, isPersistentEnabled, isReconnectEnabled } from "./reconnectChatHelper";
16
16
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
17
17
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
18
+ import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
18
19
 
19
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
21
  let optionalParams = {};
@@ -112,8 +113,20 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
112
113
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
113
114
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
114
115
  const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
116
+ if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
117
+ // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
118
+ chatSDK.requestId = uuidv4();
119
+ chatSDK.chatToken = {};
120
+ chatSDK.reconnectId = null;
121
+ }
115
122
  try {
116
- var _newAdapter$activity$, _TelemetryTimers$Widg2;
123
+ var _state$appStates, _newAdapter$activity$, _TelemetryTimers$Widg2;
124
+ // Clear disconnect state on start chat
125
+ (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.chatDisconnectEventReceived) && dispatch({
126
+ type: LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
127
+ payload: false
128
+ });
129
+
117
130
  //Start widget load timer
118
131
  TelemetryTimers.WidgetLoadTimer = createTimer();
119
132
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
@@ -267,7 +280,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
267
280
  });
268
281
 
269
282
  // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
270
- // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
283
+ // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
271
284
  if (isStartChatSuccessful === true) {
272
285
  await forceEndChat(chatSDK);
273
286
  }
@@ -290,9 +303,9 @@ const forceEndChat = async chatSDK => {
290
303
 
291
304
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
305
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
293
- var _state$appStates, _persistedState$domai6, _persistedState$appSt;
306
+ var _state$appStates2, _persistedState$domai6, _persistedState$appSt;
294
307
  // By pass this function in case of popout chat
295
- if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.hideStartChatButton) === true) {
308
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.hideStartChatButton) === true) {
296
309
  return false;
297
310
  }
298
311
  const persistedState = getStateFromCache(getWidgetCacheIdfromProps(props));
@@ -608,9 +608,7 @@ export const LiveChatWidgetStateful = props => {
608
608
 
609
609
  // Handle Chat disconnect cases
610
610
  useEffect(() => {
611
- if (state.appStates.chatDisconnectEventReceived) {
612
- handleChatDisconnect(props, state, setWebChatStyles);
613
- }
611
+ handleChatDisconnect(props, state, setWebChatStyles);
614
612
  }, [state.appStates.chatDisconnectEventReceived]);
615
613
  const initiateEndChatOnBrowserUnload = () => {
616
614
  var _DataStoreManager$cli;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.5.1-main.132e1c6",
3
+ "version": "1.5.1-main.c3533cf",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",