@microsoft/omnichannel-chat-widget 1.4.1-main.f29a6ae → 1.5.0

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 (32) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/common/utils.js +19 -2
  3. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +8 -11
  4. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -1
  5. package/lib/cjs/components/livechatwidget/common/chatDisconnectHelper.js +3 -2
  6. package/lib/cjs/components/livechatwidget/common/endChat.js +18 -15
  7. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +1 -3
  8. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +11 -9
  9. package/lib/cjs/components/livechatwidget/common/startChat.js +36 -16
  10. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +46 -32
  11. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +22 -9
  12. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
  13. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.js +1 -0
  14. package/lib/esm/common/utils.js +16 -0
  15. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +8 -11
  16. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -2
  17. package/lib/esm/components/livechatwidget/common/chatDisconnectHelper.js +3 -2
  18. package/lib/esm/components/livechatwidget/common/endChat.js +18 -18
  19. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +1 -3
  20. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +11 -9
  21. package/lib/esm/components/livechatwidget/common/startChat.js +37 -17
  22. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +49 -35
  23. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +22 -9
  24. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +3 -1
  25. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.js +1 -0
  26. package/lib/types/common/utils.d.ts +9 -0
  27. package/lib/types/components/livechatwidget/common/endChat.d.ts +5 -2
  28. package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +1 -1
  29. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  30. package/lib/types/components/webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios.d.ts +1 -0
  31. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +9 -0
  32. package/package.json +3 -3
package/README.md CHANGED
@@ -125,7 +125,7 @@ These are components that are included in the ```@microsoft/omnichannel-chat-com
125
125
  | ProactiveChatSurveyPane | A pane that holds more information than a normal chat button and can be configured to proactively pop up | [IProactiveChatPaneProps](https://github.com/microsoft/omnichannel-chat-widget/blob/main/chat-components/src/components/proactivechatpane/interfaces/IProactiveChatPaneProps.ts) |
126
126
  | ReconnectChatPane | The pane that shows up when the customer is re-connecting to the chat to add additional conversation | [IReconnectChatPaneProps](https://github.com/microsoft/omnichannel-chat-widget/blob/main/chat-components/src/components/reconnectchatpane/interfaces/IReconnectChatPaneProps.ts) |
127
127
 
128
- > :warning: Because the components extend Microsoft's [Fluent UI](https://developer.microsoft.com/en-us/fluentui#/) components, the base interface for all the ```styleProps``` in the above table is [IStyle](https://github.com/microsoft/fluentui/blob/master/packages/merge-styles/src/IStyle.ts), which extends the [IRawStyleBase](https://docs.microsoft.com/en-us/javascript/api/merge-styles/irawstylebase?view=office-ui-fabric-react-latest) interface, which is the most useful reference.
128
+ > :warning: Because the components extend Microsoft's [Fluent UI](https://developer.microsoft.com/en-us/fluentui#/) components, the base interface for all the ```styleProps``` in the above table is [IStyle](https://github.com/microsoft/fluentui/blob/master/packages/merge-styles/src/IStyle.ts), which extends the [IRawStyleBase](https://github.com/microsoft/fluentui/blob/master/packages/merge-styles/src/IRawStyleBase.ts#L280) interface, which is the most useful reference.
129
129
 
130
130
  ### Stateful Components
131
131
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setTabIndices = exports.setFocusOnSendBox = exports.setFocusOnElement = exports.preventFocusToMoveOutOfElement = exports.parseAdaptiveCardPayload = exports.newGuid = exports.isUndefinedOrEmpty = exports.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheIdfromProps = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getStateFromCache = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.getConversationDetailsCall = exports.getBroadcastChannelName = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.debounceLeading = exports.createTimer = exports.createFileAndDownload = exports.checkContactIdError = exports.changeLanguageCodeFormatForWebChat = exports.addDelayInMs = void 0;
6
+ exports.setTabIndices = exports.setFocusOnSendBox = exports.setFocusOnElement = exports.preventFocusToMoveOutOfElement = exports.parseAdaptiveCardPayload = exports.newGuid = exports.isUndefinedOrEmpty = exports.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheIdfromProps = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getStateFromCache = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.getConversationDetailsCall = exports.getBroadcastChannelName = exports.formatTemplateString = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.debounceLeading = exports.createTimer = exports.createFileAndDownload = exports.checkContactIdError = exports.changeLanguageCodeFormatForWebChat = exports.addDelayInMs = void 0;
7
7
  var _Constants = require("./Constants");
8
8
  var _TelemetryConstants = require("./telemetry/TelemetryConstants");
9
9
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
@@ -431,4 +431,21 @@ const createFileAndDownload = (fileName, blobData, mimeType) => {
431
431
  aElement.click();
432
432
  document.body.removeChild(aElement);
433
433
  };
434
- exports.createFileAndDownload = createFileAndDownload;
434
+
435
+ /**
436
+ *
437
+ * Replace placeholders with format {0}..{n} , in a string with values
438
+ *
439
+ * @param template String with placeholders to be replaced
440
+ * @param values array of values to replace the placeholders
441
+ * @returns formatted string with replaced values
442
+ */
443
+ // use of any for values as array of any type is passed
444
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
445
+ exports.createFileAndDownload = createFileAndDownload;
446
+ const formatTemplateString = (templateMessage, values) => {
447
+ return templateMessage.replace(/{(\d+)}/g, (match, index) => {
448
+ return typeof values[index] !== "undefined" ? values[index] : match;
449
+ });
450
+ };
451
+ exports.formatTemplateString = formatTemplateString;
@@ -65,17 +65,14 @@ const ChatButtonStateful = props => {
65
65
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
66
66
  Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked
67
67
  });
68
- if (state.appStates.isMinimized) {
69
- dispatch({
70
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
71
- payload: false
72
- });
73
- } else {
74
- dispatch({
75
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
76
- payload: _ConversationState.ConversationState.OutOfOffice
77
- });
78
- }
68
+ state.appStates.isMinimized && dispatch({
69
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
70
+ payload: false
71
+ });
72
+ dispatch({
73
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
74
+ payload: _ConversationState.ConversationState.OutOfOffice
75
+ });
79
76
  },
80
77
  unreadMessageString: (_props$buttonProps3 = props.buttonProps) === null || _props$buttonProps3 === void 0 ? void 0 : (_props$buttonProps3$c = _props$buttonProps3.controlProps) === null || _props$buttonProps3$c === void 0 ? void 0 : _props$buttonProps3$c.unreadMessageString,
81
78
  ...(outOfOfficeButtonProps === null || outOfOfficeButtonProps === void 0 ? void 0 : outOfOfficeButtonProps.controlProps)
@@ -16,6 +16,7 @@ var _Constants = require("../../common/Constants");
16
16
  var _TelemetryHelper = require("../../common/telemetry/TelemetryHelper");
17
17
  var _useChatContextStore = _interopRequireDefault(require("../../hooks/useChatContextStore"));
18
18
  var _useChatSDKStore = _interopRequireDefault(require("../../hooks/useChatSDKStore"));
19
+ var _defaultMiddlewareLocalizedTexts = require("../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts");
19
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21
  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); }
21
22
  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; }
@@ -55,6 +56,7 @@ const EmailTranscriptPaneStateful = props => {
55
56
  };
56
57
  try {
57
58
  await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.emailLiveChatTranscript(chatTranscriptBody));
59
+ _NotificationHandler.NotificationHandler.notifySuccess(_NotificationScenarios.NotificationScenarios.EmailAddressSaved, _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === null || _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts === void 0 ? void 0 : _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_SUCCESS);
58
60
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
59
61
  Event: _TelemetryConstants.TelemetryEvent.EmailTranscriptSent,
60
62
  Description: "Transcript sent to email successfully."
@@ -66,7 +68,8 @@ const EmailTranscriptPaneStateful = props => {
66
68
  exception: ex
67
69
  }
68
70
  });
69
- _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.EmailTranscriptError, (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? "Email transcript to " + email + " failed.");
71
+ const message = (0, _utils.formatTemplateString)(_defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_FILE_EMAIL_ADDRESS_RECORDED_ERROR, [email]);
72
+ _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.EmailTranscriptError, (props === null || props === void 0 ? void 0 : props.bannerMessageOnError) ?? message);
70
73
  }
71
74
  },
72
75
  onCancel: () => {
@@ -13,7 +13,8 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
13
13
  const handleChatDisconnect = (props, state, setWebChatStyles) => {
14
14
  var _state$appStates;
15
15
  if (state !== null && state !== void 0 && (_state$appStates = state.appStates) !== null && _state$appStates !== void 0 && _state$appStates.chatDisconnectEventReceived) {
16
- var _props$webChatContain, _props$webChatContain2;
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;
17
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) {
18
19
  setWebChatStyles(styles => {
19
20
  return {
@@ -22,7 +23,7 @@ const handleChatDisconnect = (props, state, setWebChatStyles) => {
22
23
  };
23
24
  });
24
25
  }
25
- _NotificationHandler.NotificationHandler.notifyWarning(_NotificationScenarios.NotificationScenarios.ChatDisconnect, _defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts.MIDDLEWARE_BANNER_CHAT_DISCONNECT);
26
+ _NotificationHandler.NotificationHandler.notifyWarning(_NotificationScenarios.NotificationScenarios.ChatDisconnect, chatDisconnectMessage);
26
27
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
27
28
  Event: _TelemetryConstants.TelemetryEvent.ChatDisconnectThreadEventReceived,
28
29
  Description: "Chat disconnected due to timeout, left or removed."
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChat = void 0;
6
+ exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChatStateCleanUp = exports.endChat = exports.closeChatStateCleanUp = exports.callingStateCleanUp = void 0;
7
7
  var _Constants = require("../../../common/Constants");
8
8
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
9
  var _authHelper = require("./authHelper");
@@ -15,10 +15,11 @@ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidget
15
15
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
16
16
  var _WebChatStoreLoader = require("../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader");
17
17
  var _defaultWebChatContainerStatefulProps = require("../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps");
18
+ var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
18
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
20
+ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
20
21
  try {
21
- var _conversationDetails$, _state$domainStates, _state$domainStates2;
22
+ var _conversationDetails$, _state$domainStates;
22
23
  // Use Case: If call is ongoing, end the call by simulating end call button click
23
24
  endVoiceVideoCallIfOngoing(chatSDK, dispatch);
24
25
  const conversationDetails = await (0, _utils.getConversationDetailsCall)(chatSDK);
@@ -28,7 +29,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
28
29
  var _state$appStates;
29
30
  // If ended by customer, just close chat
30
31
  if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
31
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
32
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
32
33
  }
33
34
  // Use Case: If ended by Agent, stay chat in InActive state
34
35
  return;
@@ -43,15 +44,13 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
43
44
  }
44
45
 
45
46
  // Use Case: Can render post chat scenarios
46
- await (0, _renderSurveyHelpers.getPostChatContext)(chatSDK, state, dispatch);
47
-
48
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- const postchatContext = state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.postChatContext;
48
+ const postchatContext = (await (0, _renderSurveyHelpers.getPostChatContext)(chatSDK, state, dispatch)) ?? (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.postChatContext);
50
49
  if (postchatContext === undefined) {
51
50
  var _state$appStates2;
52
51
  // For Customer intiated conversations, just close chat widget
53
52
  if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
54
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
53
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
55
54
  return;
56
55
  }
57
56
 
@@ -62,10 +61,10 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
62
61
  });
63
62
  return;
64
63
  }
65
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true, uwid);
64
+ endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true);
66
65
 
67
66
  // Initiate post chat render
68
- if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
67
+ if (postchatContext) {
69
68
  await (0, _renderSurveyHelpers.initiatePostChat)(props, conversationDetails, state, dispatch, postchatContext);
70
69
  return;
71
70
  }
@@ -80,7 +79,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
80
79
 
81
80
  //Close chat widget for any failure in embedded to allow to show start chat button
82
81
  if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
83
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
82
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
84
83
  }
85
84
  } finally {
86
85
  //Chat token clean up
@@ -90,8 +89,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
90
89
 
91
90
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
91
  exports.prepareEndChat = prepareEndChat;
93
- const endChat = async function (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) {
94
- let uwid = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : "";
92
+ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
95
93
  if (!skipEndChatSDK && chatSDK.conversation) {
96
94
  try {
97
95
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -143,11 +141,13 @@ const endChat = async function (props, chatSDK, state, dispatch, setAdapter, set
143
141
  closeChatWidget(dispatch, props, state);
144
142
  }
145
143
  }
146
- if (postMessageToOtherTab && !(0, _utils.isNullOrEmptyString)(uwid)) {
144
+ if (postMessageToOtherTab) {
147
145
  const endChatEventName = await getEndChatEventName(chatSDK, props);
148
146
  _omnichannelChatComponents.BroadcastService.postMessage({
149
147
  eventName: endChatEventName,
150
- payload: uwid
148
+ payload: {
149
+ runtimeId: _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId
150
+ }
151
151
  });
152
152
  }
153
153
  };
@@ -174,6 +174,7 @@ const callingStateCleanUp = async dispatch => {
174
174
  payload: true
175
175
  });
176
176
  };
177
+ exports.callingStateCleanUp = callingStateCleanUp;
177
178
  const endChatStateCleanUp = async dispatch => {
178
179
  // Need to clear these states immediately when chat ended from OC.
179
180
  dispatch({
@@ -189,6 +190,7 @@ const endChatStateCleanUp = async dispatch => {
189
190
  payload: false
190
191
  });
191
192
  };
193
+ exports.endChatStateCleanUp = endChatStateCleanUp;
192
194
  const closeChatStateCleanUp = async dispatch => {
193
195
  dispatch({
194
196
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
@@ -226,6 +228,7 @@ const closeChatStateCleanUp = async dispatch => {
226
228
  };
227
229
 
228
230
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
+ exports.closeChatStateCleanUp = closeChatStateCleanUp;
229
232
  const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
230
233
  let callId = "";
231
234
  try {
@@ -17,15 +17,13 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
18
  const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
19
19
  var _props$chatConfig, _props$chatConfig$Liv;
20
- if (!isReconnectEnabled(props.chatConfig) || isPersistentEnabled(props.chatConfig)) return false;
21
-
22
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
21
  const isAuthenticatedChat = (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
24
22
 
25
23
  // Get chat reconnect context
26
24
  const reconnectChatContext = await getChatReconnectContext(chatSDK, props.chatConfig, props, isAuthenticatedChat);
27
25
 
28
- //Redirect if enabled
26
+ // Redirect if enabled
29
27
  if (reconnectChatContext !== null && reconnectChatContext !== void 0 && reconnectChatContext.redirectURL) {
30
28
  var _props$reconnectChatP;
31
29
  redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
@@ -48,24 +48,25 @@ const setSurveyMode = async (props, participantType, state, dispatch) => {
48
48
  return;
49
49
  }
50
50
  };
51
- const renderSurvey = async (state, dispatch) => {
51
+
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ const renderSurvey = async (postChatContext, dispatch) => {
52
54
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
53
55
  setWidgetStateToInactive(dispatch);
54
56
  return;
55
57
  }
56
58
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
57
- await embedModePostChatWorkflow(state, dispatch);
59
+ await embedModePostChatWorkflow(postChatContext, dispatch);
58
60
  }
59
61
  };
60
62
 
61
63
  // Function for embed mode postchat workflow which is essentially same for both customer and agent
62
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- const embedModePostChatWorkflow = async (state, dispatch) => {
64
- var _state$domainStates2;
65
+ const embedModePostChatWorkflow = async (postChatContext, dispatch) => {
65
66
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
66
67
  Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
67
68
  });
68
- if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
69
+ if (postChatContext) {
69
70
  dispatch({
70
71
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
71
72
  payload: _ConversationState.ConversationState.PostchatLoading
@@ -76,7 +77,7 @@ const embedModePostChatWorkflow = async (state, dispatch) => {
76
77
  payload: _ConversationState.ConversationState.Postchat
77
78
  });
78
79
  } else {
79
- const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
80
+ const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${postChatContext}`;
80
81
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
81
82
  Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
82
83
  ExceptionDetails: {
@@ -92,7 +93,7 @@ const initiatePostChat = async (props, conversationDetailsParam, state, dispatch
92
93
  conversationDetails = conversationDetailsParam;
93
94
  const participantType = ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.participantType) ?? postchatContext.participantType;
94
95
  await setSurveyMode(props, participantType, state, dispatch);
95
- await renderSurvey(state, dispatch);
96
+ await renderSurvey(postchatContext, dispatch);
96
97
  };
97
98
 
98
99
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -107,8 +108,8 @@ const isPostChatEnabled = (props, state) => {
107
108
  exports.checkPostChatEnabled = isPostChatEnabled;
108
109
  const getPostChatContext = async (chatSDK, state, dispatch) => {
109
110
  try {
110
- var _state$domainStates3;
111
- if ((state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.postChatContext) === undefined) {
111
+ var _state$domainStates2;
112
+ if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
112
113
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
114
  const context = await chatSDK.getPostChatSurveyContext();
114
115
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -119,6 +120,7 @@ const getPostChatContext = async (chatSDK, state, dispatch) => {
119
120
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
120
121
  payload: context
121
122
  });
123
+ return context;
122
124
  }
123
125
  } catch (error) {
124
126
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -34,7 +34,13 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
34
34
  widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
35
35
 
36
36
  // reconnect > chat from cache
37
- await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
37
+ if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true && !(0, _reconnectChatHelper.isPersistentEnabled)(props.chatConfig)) {
38
+ const shouldStartChatNormally = await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
39
+ if (!shouldStartChatNormally) {
40
+ return;
41
+ }
42
+ }
43
+
38
44
  // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
39
45
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
40
46
  return;
@@ -69,15 +75,29 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
69
75
  const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
70
76
  const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
71
77
  if (showPrechat) {
72
- dispatch({
73
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
74
- payload: preChatSurveyResponse
75
- });
76
- dispatch({
77
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
78
- payload: _ConversationState.ConversationState.Prechat
79
- });
80
- return;
78
+ var _state$domainStates, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3;
79
+ const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : (_state$domainStates$l3 = _state$domainStates$l2.OutOfOperatingHours) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.toLowerCase()) === "true";
80
+ if (isOutOfOperatingHours) {
81
+ (state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
82
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
83
+ payload: false
84
+ });
85
+ dispatch({
86
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
87
+ payload: _ConversationState.ConversationState.OutOfOffice
88
+ });
89
+ return;
90
+ } else {
91
+ dispatch({
92
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
93
+ payload: preChatSurveyResponse
94
+ });
95
+ dispatch({
96
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
97
+ payload: _ConversationState.ConversationState.Prechat
98
+ });
99
+ return;
100
+ }
81
101
  }
82
102
 
83
103
  //Initiate start chat
@@ -303,17 +323,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
303
323
 
304
324
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
325
  const setCustomContextParams = async (state, props) => {
306
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates, _persistedState$domai8;
326
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates2, _persistedState$domai8;
307
327
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
328
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
309
329
  //Should not set custom context for auth chat
310
330
  if (isAuthenticatedChat) {
311
331
  return;
312
332
  }
313
- if (state !== null && state !== void 0 && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
314
- var _state$domainStates2;
333
+ if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.customContext) {
334
+ var _state$domainStates3;
315
335
  optionalParams = Object.assign({}, optionalParams, {
316
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.customContext))
336
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.customContext))
317
337
  });
318
338
  return;
319
339
  }
@@ -361,8 +381,8 @@ const canStartPopoutChat = async props => {
361
381
 
362
382
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
363
383
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
364
- var _state$domainStates3, _state$domainStates3$;
365
- const requestIdFromCache = (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.liveChatContext) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.requestId;
384
+ var _state$domainStates4, _state$domainStates4$;
385
+ const requestIdFromCache = (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.liveChatContext) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.requestId;
366
386
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
367
387
  let conversationDetails = undefined;
368
388