@microsoft/omnichannel-chat-widget 1.5.0 → 1.5.1-main.6b98130

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 (84) hide show
  1. package/lib/cjs/common/Constants.js +19 -8
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +1 -2
  3. package/lib/cjs/common/utils.js +2 -1
  4. package/lib/cjs/components/livechatwidget/common/chatDisconnectHelper.js +31 -16
  5. package/lib/cjs/components/livechatwidget/common/endChat.js +16 -4
  6. package/lib/cjs/components/livechatwidget/common/startChat.js +19 -80
  7. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +219 -0
  8. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +300 -0
  9. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +18 -16
  10. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  11. package/lib/cjs/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +82 -0
  12. package/lib/cjs/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneGeneralStyleProps.js +17 -0
  13. package/lib/cjs/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconImageProps.js +17 -0
  14. package/lib/cjs/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconStyleProps.js +15 -0
  15. package/lib/cjs/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneSubtitleStyleProps.js +17 -0
  16. package/lib/cjs/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneTitleStyleProps.js +17 -0
  17. package/lib/cjs/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.js +1 -0
  18. package/lib/cjs/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneProps.js +1 -0
  19. package/lib/cjs/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneStyleProps.js +1 -0
  20. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +2 -11
  21. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +1 -1
  22. package/lib/cjs/contexts/common/ConversationState.js +1 -0
  23. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +37 -36
  24. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +4 -1
  25. package/lib/cjs/contexts/common/StartChatFailureType.js +13 -0
  26. package/lib/cjs/contexts/createReducer.js +8 -0
  27. package/lib/cjs/controller/componentController.js +5 -1
  28. package/lib/esm/common/Constants.js +15 -6
  29. package/lib/esm/common/telemetry/TelemetryConstants.js +1 -2
  30. package/lib/esm/common/utils.js +3 -2
  31. package/lib/esm/components/livechatwidget/common/chatDisconnectHelper.js +31 -16
  32. package/lib/esm/components/livechatwidget/common/endChat.js +14 -3
  33. package/lib/esm/components/livechatwidget/common/startChat.js +20 -81
  34. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +212 -0
  35. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +298 -0
  36. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +20 -18
  37. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +1 -1
  38. package/lib/esm/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +71 -0
  39. package/lib/esm/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneGeneralStyleProps.js +10 -0
  40. package/lib/esm/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconImageProps.js +10 -0
  41. package/lib/esm/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconStyleProps.js +8 -0
  42. package/lib/esm/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneSubtitleStyleProps.js +10 -0
  43. package/lib/esm/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneTitleStyleProps.js +10 -0
  44. package/lib/esm/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.js +1 -0
  45. package/lib/esm/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneProps.js +1 -0
  46. package/lib/esm/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneStyleProps.js +1 -0
  47. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +2 -11
  48. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +1 -1
  49. package/lib/esm/contexts/common/ConversationState.js +1 -0
  50. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +37 -36
  51. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +4 -1
  52. package/lib/esm/contexts/common/StartChatFailureType.js +6 -0
  53. package/lib/esm/contexts/createReducer.js +8 -0
  54. package/lib/esm/controller/componentController.js +3 -0
  55. package/lib/types/common/Constants.d.ts +17 -4
  56. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -1
  57. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
  58. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +5 -0
  59. package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +1 -0
  60. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  61. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -1
  62. package/lib/types/components/startchaterrorpanestateful/StartChatErrorPaneStateful.d.ts +3 -0
  63. package/lib/types/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneGeneralStyleProps.d.ts +2 -0
  64. package/lib/types/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconImageProps.d.ts +2 -0
  65. package/lib/types/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneIconStyleProps.d.ts +2 -0
  66. package/lib/types/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneSubtitleStyleProps.d.ts +2 -0
  67. package/lib/types/components/startchaterrorpanestateful/common/defaultStartChatErrorPaneTitleStyleProps.d.ts +2 -0
  68. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneClassNames.d.ts +5 -0
  69. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneComponentOverrides.d.ts +6 -0
  70. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.d.ts +14 -0
  71. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneProps.d.ts +8 -0
  72. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneStyleProps.d.ts +10 -0
  73. package/lib/types/contexts/common/ConversationState.d.ts +2 -1
  74. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +3 -0
  75. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +37 -36
  76. package/lib/types/contexts/common/StartChatFailureType.d.ts +5 -0
  77. package/lib/types/controller/componentController.d.ts +1 -0
  78. package/package.json +3 -3
  79. package/lib/types/components/loadingpanestateful/interfaces/IStartChatErrorPaneControlProps.d.ts +0 -4
  80. package/lib/types/components/loadingpanestateful/interfaces/IStartChatErrorPaneProps.d.ts +0 -4
  81. /package/lib/cjs/components/{loadingpanestateful/interfaces/IStartChatErrorPaneControlProps.js → startchaterrorpanestateful/interfaces/IStartChatErrorPaneClassNames.js} +0 -0
  82. /package/lib/cjs/components/{loadingpanestateful/interfaces/IStartChatErrorPaneProps.js → startchaterrorpanestateful/interfaces/IStartChatErrorPaneComponentOverrides.js} +0 -0
  83. /package/lib/esm/components/{loadingpanestateful/interfaces/IStartChatErrorPaneControlProps.js → startchaterrorpanestateful/interfaces/IStartChatErrorPaneClassNames.js} +0 -0
  84. /package/lib/esm/components/{loadingpanestateful/interfaces/IStartChatErrorPaneProps.js → startchaterrorpanestateful/interfaces/IStartChatErrorPaneComponentOverrides.js} +0 -0
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.Regex = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.ChatSDKError = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
6
+ exports.WidgetLoadTelemetryMessage = exports.WidgetLoadCustomErrorString = exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.StartChatErrorPaneConstants = exports.Regex = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
7
7
  var _class;
8
8
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
@@ -191,12 +191,6 @@ exports.ElementType = ElementType;
191
191
  (function (ElementType) {
192
192
  ElementType["CallingContainerSDK"] = "CallingContainerSDK";
193
193
  })(ElementType || (exports.ElementType = ElementType = {}));
194
- let ChatSDKError;
195
- exports.ChatSDKError = ChatSDKError;
196
- (function (ChatSDKError) {
197
- ChatSDKError["WidgetUseOutsideOperatingHour"] = "WidgetUseOutsideOperatingHour";
198
- ChatSDKError["AuthContactIdNotFoundFailure"] = "AuthContactIdNotFoundFailure";
199
- })(ChatSDKError || (exports.ChatSDKError = ChatSDKError = {}));
200
194
  let EnvironmentVersion;
201
195
  exports.EnvironmentVersion = EnvironmentVersion;
202
196
  (function (EnvironmentVersion) {
@@ -280,6 +274,15 @@ _defineProperty(NotificationPaneConstants, "IconText", "Notification Icon");
280
274
  _defineProperty(NotificationPaneConstants, "ChatDisconnectTitleText", "Chat disconnected");
281
275
  _defineProperty(NotificationPaneConstants, "ChatDisconnectSubtitleText", "For additional assistance, please close the chat and try again.");
282
276
  _defineProperty(NotificationPaneConstants, "ChromeCloseIconName", "ChromeClose");
277
+ class StartChatErrorPaneConstants {}
278
+ exports.StartChatErrorPaneConstants = StartChatErrorPaneConstants;
279
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorPaneId", "oc-lcw-start-chat-error-pane");
280
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorTitleText", "We are unable to load chat at this time.");
281
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorSubtitleText", "Please try again later.");
282
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorUnauthorizedTitleText", "Chat authentication has failed.");
283
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorAuthSetupErrorTitleText", "Chat authentication has failed.");
284
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorUnauthorizedSubtitleText", "UNAUTHORIZED");
285
+ _defineProperty(StartChatErrorPaneConstants, "DefaultStartChatErrorAuthSetupErrorSubtitleText", "AUTH SETUP ERROR");
283
286
  class AriaTelemetryConstants {}
284
287
  exports.AriaTelemetryConstants = AriaTelemetryConstants;
285
288
  // Aria Endpoint for different environment types.
@@ -294,4 +297,12 @@ _defineProperty(AriaTelemetryConstants, "MOONCAKE_ENDPOINT", "");
294
297
  _defineProperty(AriaTelemetryConstants, "Public", "Public");
295
298
  _defineProperty(AriaTelemetryConstants, "EU", "Europe");
296
299
  // EUR: crm4; FRA: crm12; GER: crm16; CHE: crm17; NOR: crm19
297
- _defineProperty(AriaTelemetryConstants, "lcwEUDomainNames", ["crm4.omnichannelengagementhub.com", "crm12.omnichannelengagementhub.com", "crm16.omnichannelengagementhub.com", "crm17.omnichannelengagementhub.com", "crm19.omnichannelengagementhub.com"]);
300
+ _defineProperty(AriaTelemetryConstants, "lcwEUDomainNames", ["crm4.omnichannelengagementhub.com", "crm12.omnichannelengagementhub.com", "crm16.omnichannelengagementhub.com", "crm17.omnichannelengagementhub.com", "crm19.omnichannelengagementhub.com"]);
301
+ class WidgetLoadTelemetryMessage {}
302
+ exports.WidgetLoadTelemetryMessage = WidgetLoadTelemetryMessage;
303
+ _defineProperty(WidgetLoadTelemetryMessage, "OOOHMessage", "Widget is OOOH");
304
+ _defineProperty(WidgetLoadTelemetryMessage, "PersistedStateRetrievedMessage", "Persisted state retrieved");
305
+ class WidgetLoadCustomErrorString {}
306
+ exports.WidgetLoadCustomErrorString = WidgetLoadCustomErrorString;
307
+ _defineProperty(WidgetLoadCustomErrorString, "AuthenticationFailedErrorString", "Authentication was not successful");
308
+ _defineProperty(WidgetLoadCustomErrorString, "NetworkErrorString", "Network Error");
@@ -133,10 +133,10 @@ exports.TelemetryEvent = TelemetryEvent;
133
133
  TelemetryEvent["ErrorUIPaneLoaded"] = "ErrorUIPaneLoaded";
134
134
  TelemetryEvent["DownloadTranscriptFailed"] = "DownloadTranscriptFailed";
135
135
  TelemetryEvent["StartChatFailed"] = "StartChatFailed";
136
- TelemetryEvent["IC3ThreadUpdateEventReceived"] = "IC3ThreadUpdateEventReceived";
137
136
  TelemetryEvent["ConfirmationCancelButtonClicked"] = "ConfirmationCancelButtonClicked";
138
137
  TelemetryEvent["ConfirmationConfirmButtonClicked"] = "ConfirmationConfirmButtonClicked";
139
138
  TelemetryEvent["LoadingPaneLoaded"] = "LoadingPaneLoaded";
139
+ TelemetryEvent["StartChatErrorPaneLoaded"] = "StartChatErrorPaneLoaded";
140
140
  TelemetryEvent["EmailTranscriptLoaded"] = "EmailTranscriptLoaded";
141
141
  TelemetryEvent["OutOfOfficePaneLoaded"] = "OutOfOfficePaneLoaded";
142
142
  TelemetryEvent["ConfirmationPaneLoaded"] = "ConfirmationPaneLoaded";
@@ -250,7 +250,6 @@ class TelemetryConstants {
250
250
  case TelemetryEvent.EmailTranscriptSent:
251
251
  case TelemetryEvent.EmailTranscriptFailed:
252
252
  case TelemetryEvent.DownloadTranscriptFailed:
253
- case TelemetryEvent.IC3ThreadUpdateEventReceived:
254
253
  case TelemetryEvent.ConfirmationCancelButtonClicked:
255
254
  case TelemetryEvent.ConfirmationConfirmButtonClicked:
256
255
  case TelemetryEvent.PreChatSurveyStartChatMethodFailed:
@@ -11,6 +11,7 @@ var _DataStoreManager = require("./contextDataStore/DataStoreManager");
11
11
  var _KeyCodes = require("./KeyCodes");
12
12
  var _md5Typescript = require("md5-typescript");
13
13
  var _TelemetryHelper = require("./telemetry/TelemetryHelper");
14
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
14
15
  var _this = void 0;
15
16
  const getElementBySelector = selector => {
16
17
  let element;
@@ -406,7 +407,7 @@ const getConversationDetailsCall = async chatSDK => {
406
407
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
407
408
  exports.getConversationDetailsCall = getConversationDetailsCall;
408
409
  const checkContactIdError = e => {
409
- if ((e === null || e === void 0 ? void 0 : e.message) === _Constants.ChatSDKError.AuthContactIdNotFoundFailure) {
410
+ if ((e === null || e === void 0 ? void 0 : e.message) === _omnichannelChatSdk.ChatSDKErrorName.AuthContactIdNotFoundFailure) {
410
411
  const contactIdNotFoundErrorEvent = {
411
412
  eventName: _TelemetryConstants.BroadcastEvent.ContactIdNotFound,
412
413
  payload: {
@@ -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;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChatStateCleanUp = exports.endChat = exports.closeChatStateCleanUp = exports.callingStateCleanUp = void 0;
6
+ exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChatStateCleanUp = exports.endChat = exports.closeChatStateCleanUp = exports.chatSDKStateCleanUp = 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");
@@ -16,6 +16,7 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
16
16
  var _WebChatStoreLoader = require("../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader");
17
17
  var _defaultWebChatContainerStatefulProps = require("../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps");
18
18
  var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
19
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
19
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
21
  const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
21
22
  try {
@@ -152,7 +153,7 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
152
153
  }
153
154
  };
154
155
  exports.endChat = endChat;
155
- const callingStateCleanUp = async dispatch => {
156
+ const callingStateCleanUp = dispatch => {
156
157
  dispatch({
157
158
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SHOW_CALLING_CONTAINER,
158
159
  payload: false
@@ -175,7 +176,7 @@ const callingStateCleanUp = async dispatch => {
175
176
  });
176
177
  };
177
178
  exports.callingStateCleanUp = callingStateCleanUp;
178
- const endChatStateCleanUp = async dispatch => {
179
+ const endChatStateCleanUp = dispatch => {
179
180
  // Need to clear these states immediately when chat ended from OC.
180
181
  dispatch({
181
182
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
@@ -191,7 +192,7 @@ const endChatStateCleanUp = async dispatch => {
191
192
  });
192
193
  };
193
194
  exports.endChatStateCleanUp = endChatStateCleanUp;
194
- const closeChatStateCleanUp = async dispatch => {
195
+ const closeChatStateCleanUp = dispatch => {
195
196
  dispatch({
196
197
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
197
198
  payload: undefined
@@ -229,6 +230,17 @@ const closeChatStateCleanUp = async dispatch => {
229
230
 
230
231
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
232
  exports.closeChatStateCleanUp = closeChatStateCleanUp;
233
+ const chatSDKStateCleanUp = chatSDK => {
234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
235
+ chatSDK.requestId = (0, _omnichannelChatSdk.uuidv4)();
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
+ chatSDK.chatToken = {};
238
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
239
+ chatSDK.reconnectId = null;
240
+ };
241
+
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
+ exports.chatSDKStateCleanUp = chatSDKStateCleanUp;
232
244
  const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
233
245
  let callId = "";
234
246
  try {
@@ -12,8 +12,6 @@ var _ActivityStreamHandler = require("./ActivityStreamHandler");
12
12
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
13
13
  var _ConversationState = require("../../../contexts/common/ConversationState");
14
14
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
15
- var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
16
- var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
17
15
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
18
16
  var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
19
17
  var _createAdapter = require("./createAdapter");
@@ -21,6 +19,8 @@ var _newMessageEventHandler = require("../../../plugins/newMessageEventHandler")
21
19
  var _reconnectChatHelper = require("./reconnectChatHelper");
22
20
  var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
23
21
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
22
+ var _startChatErrorHandler = require("./startChatErrorHandler");
23
+ var _endChat = require("./endChat");
24
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
25
  let optionalParams = {};
26
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -114,13 +114,21 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
114
114
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
115
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
116
116
  const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
117
- var _props$controlProps2;
118
117
  let isStartChatSuccessful = false;
119
118
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
120
119
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
121
- const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
120
+ if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
121
+ // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
122
+ (0, _endChat.chatSDKStateCleanUp)(chatSDK);
123
+ }
122
124
  try {
123
- var _newAdapter$activity$, _TelemetryTimers$Widg2;
125
+ var _state$appStates, _newAdapter$activity$;
126
+ // Clear disconnect state on start chat
127
+ (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.chatDisconnectEventReceived) && dispatch({
128
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
129
+ payload: false
130
+ });
131
+
124
132
  //Start widget load timer
125
133
  _TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
126
134
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -132,8 +140,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
132
140
  // set auth token to chat sdk before start chat
133
141
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
134
142
  if (!authSuccess) {
135
- // Replacing with error ui
136
- throw new Error("Authentication was not successful");
143
+ throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
137
144
  }
138
145
  }
139
146
 
@@ -196,16 +203,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
196
203
  });
197
204
  }
198
205
  if (persistedState) {
199
- var _TelemetryTimers$Widg;
200
206
  dispatch({
201
207
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
202
208
  payload: persistedState
203
209
  });
204
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
205
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
206
- Description: "Widget load complete. Persisted state retrieved",
207
- ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
208
- });
210
+ (0, _startChatErrorHandler.logWidgetLoadComplete)(_Constants.WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
209
211
  await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
210
212
  return;
211
213
  }
@@ -216,11 +218,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
216
218
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
217
219
  payload: liveChatContext
218
220
  });
219
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
220
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
221
- Description: "Widget load complete",
222
- ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg2 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg2 === void 0 ? void 0 : _TelemetryTimers$Widg2.milliSecondsElapsed
223
- });
221
+ (0, _startChatErrorHandler.logWidgetLoadComplete)();
224
222
 
225
223
  // Set post chat context in state
226
224
  // Commenting this for now as post chat context is fetched during end chat
@@ -229,55 +227,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
229
227
  // Updating chat session detail for telemetry
230
228
  await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
231
229
  } catch (ex) {
232
- var _TelemetryTimers$Widg4;
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
- if (ex.message === _Constants.ChatSDKError.WidgetUseOutsideOperatingHour) {
235
- var _TelemetryTimers$Widg3;
236
- dispatch({
237
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_OUTSIDE_OPERATING_HOURS,
238
- payload: true
239
- });
240
- dispatch({
241
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
242
- payload: _ConversationState.ConversationState.OutOfOffice
243
- });
244
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
245
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
246
- Description: "Widget load complete. Widget is OOOH.",
247
- ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg3 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg3 === void 0 ? void 0 : _TelemetryTimers$Widg3.milliSecondsElapsed
248
- });
249
- return;
250
- }
251
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
252
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
253
- ExceptionDetails: {
254
- Exception: `Widget load Failed: ${ex}`
255
- },
256
- ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg4 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg4 === void 0 ? void 0 : _TelemetryTimers$Widg4.milliSecondsElapsed
257
- });
258
- _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Start Chat Failed: " + ex);
259
- dispatch({
260
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
261
- payload: true
262
- });
263
- if (!hideErrorUIPane) {
264
- // Set app state to failing start chat if hideErrorUI is not turned on
265
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
266
- Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
267
- Description: "Error UI Pane Loaded"
268
- });
269
- }
270
- // Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
271
- dispatch({
272
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
273
- payload: _ConversationState.ConversationState.Loading
274
- });
275
-
276
- // 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
278
- if (isStartChatSuccessful === true) {
279
- await forceEndChat(chatSDK);
280
- }
230
+ (0, _startChatErrorHandler.handleStartChatError)(dispatch, chatSDK, props, ex, isStartChatSuccessful);
281
231
  } finally {
282
232
  optionalParams = {};
283
233
  widgetInstanceId = "";
@@ -286,21 +236,10 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
286
236
 
287
237
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
288
238
  exports.initStartChat = initStartChat;
289
- const forceEndChat = async chatSDK => {
290
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
291
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
292
- ExceptionDetails: {
293
- Exception: "SessionInit was successful, but widget load failed."
294
- }
295
- });
296
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
297
- };
298
-
299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
239
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
301
- var _state$appStates, _persistedState$domai6, _persistedState$appSt;
240
+ var _state$appStates2, _persistedState$domai6, _persistedState$appSt;
302
241
  // 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) {
242
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.hideStartChatButton) === true) {
304
243
  return false;
305
244
  }
306
245
  const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.logWidgetLoadComplete = exports.handleStartChatError = void 0;
7
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
8
+ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
+ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
10
+ var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
11
+ var _ConversationState = require("../../../contexts/common/ConversationState");
12
+ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
13
+ var _endChat = require("./endChat");
14
+ var _DataStoreManager = require("../../../common/contextDataStore/DataStoreManager");
15
+ var _utils = require("../../../common/utils");
16
+ var _Constants = require("../../../common/Constants");
17
+ var _StartChatFailureType = require("../../../contexts/common/StartChatFailureType");
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSuccessful) => {
20
+ var _props$controlProps;
21
+ if (!ex) {
22
+ logWidgetLoadFailed();
23
+ return;
24
+ }
25
+
26
+ // Handle internal or misc errors
27
+ if (ex.message === _Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString) {
28
+ dispatch({
29
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILURE_TYPE,
30
+ payload: _StartChatFailureType.StartChatFailureType.AuthSetupError
31
+ });
32
+ logWidgetLoadCompleteWithError(ex);
33
+ }
34
+ if (ex.message === _Constants.WidgetLoadCustomErrorString.NetworkErrorString) {
35
+ logWidgetLoadCompleteWithError(ex);
36
+ }
37
+
38
+ // Handle ChatSDK errors
39
+ if (ex instanceof _omnichannelChatSdk.ChatSDKError) {
40
+ switch (ex.message) {
41
+ case _omnichannelChatSdk.ChatSDKErrorName.WidgetUseOutsideOperatingHour:
42
+ handleWidgetUseOutsideOperatingHour(dispatch);
43
+ return;
44
+ case _omnichannelChatSdk.ChatSDKErrorName.PersistentChatConversationRetrievalFailure:
45
+ handlePersistentChatConversationRetrievalFailure(ex);
46
+ break;
47
+ case _omnichannelChatSdk.ChatSDKErrorName.ConversationInitializationFailure:
48
+ handleConversationInitializationFailure(ex);
49
+ break;
50
+ case _omnichannelChatSdk.ChatSDKErrorName.ChatTokenRetrievalFailure:
51
+ handleChatTokenRetrievalFailure(dispatch, ex);
52
+ break;
53
+ case _omnichannelChatSdk.ChatSDKErrorName.UninitializedChatSDK:
54
+ handleUninitializedChatSDK(ex);
55
+ break;
56
+ case _omnichannelChatSdk.ChatSDKErrorName.InvalidConversation:
57
+ case _omnichannelChatSdk.ChatSDKErrorName.ClosedConversation:
58
+ handleInvalidOrClosedConversation(dispatch, chatSDK, props, ex);
59
+ return;
60
+ default:
61
+ logWidgetLoadFailed(ex);
62
+ }
63
+ }
64
+
65
+ // Show the error UI pane
66
+ dispatch({
67
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
68
+ payload: true
69
+ });
70
+ if (!(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hideErrorUIPane)) {
71
+ // New flow of leveraging ConversationState.Error
72
+ // Set app state to failing start chat if hideErrorUI is not turned on
73
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
74
+ Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
75
+ Description: "Error UI Pane Loaded"
76
+ });
77
+ dispatch({
78
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
79
+ payload: _ConversationState.ConversationState.Error
80
+ });
81
+ } else {
82
+ // Old flow of leveraging ConversationState.Loading
83
+ // Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
84
+ dispatch({
85
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
86
+ payload: _ConversationState.ConversationState.Loading
87
+ });
88
+ }
89
+
90
+ // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
91
+ // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
92
+ if (isStartChatSuccessful === true) {
93
+ forceEndChat(chatSDK);
94
+ }
95
+ };
96
+ exports.handleStartChatError = handleStartChatError;
97
+ const logWidgetLoadFailed = ex => {
98
+ var _TelemetryTimers$Widg;
99
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
+ const exDetails = {
101
+ Exception: `Widget load complete with error: ${ex}`
102
+ };
103
+ if (ex !== null && ex !== void 0 && ex.httpResponseStatusCode) {
104
+ exDetails.HttpResponseStatusCode = ex.httpResponseStatusCode;
105
+ }
106
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
107
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
108
+ ExceptionDetails: exDetails,
109
+ ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
110
+ });
111
+ };
112
+ const logWidgetLoadComplete = additionalMessage => {
113
+ var _TelemetryTimers$Widg2;
114
+ let descriptionString = "Widget load complete";
115
+ if (additionalMessage) {
116
+ descriptionString += `. ${additionalMessage}`;
117
+ }
118
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
119
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
120
+ Description: descriptionString,
121
+ ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg2 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg2 === void 0 ? void 0 : _TelemetryTimers$Widg2.milliSecondsElapsed
122
+ });
123
+ };
124
+ exports.logWidgetLoadComplete = logWidgetLoadComplete;
125
+ const logWidgetLoadCompleteWithError = ex => {
126
+ var _TelemetryTimers$Widg3;
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ const exDetails = {
129
+ Exception: `Widget load complete with error: ${ex}`
130
+ };
131
+ if (ex !== null && ex !== void 0 && ex.httpResponseStatusCode) {
132
+ exDetails.HttpResponseStatusCode = ex.httpResponseStatusCode;
133
+ }
134
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.WARN, {
135
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
136
+ Description: "Widget load complete with error",
137
+ ExceptionDetails: exDetails,
138
+ ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg3 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg3 === void 0 ? void 0 : _TelemetryTimers$Widg3.milliSecondsElapsed
139
+ });
140
+ };
141
+
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ const forceEndChat = chatSDK => {
144
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
145
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
146
+ ExceptionDetails: {
147
+ Exception: "SessionInit was successful, but widget load failed."
148
+ }
149
+ });
150
+ chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
151
+ };
152
+ const handleWidgetUseOutsideOperatingHour = dispatch => {
153
+ dispatch({
154
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_OUTSIDE_OPERATING_HOURS,
155
+ payload: true
156
+ });
157
+ dispatch({
158
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
159
+ payload: _ConversationState.ConversationState.OutOfOffice
160
+ });
161
+ logWidgetLoadComplete(_Constants.WidgetLoadTelemetryMessage.OOOHMessage);
162
+ };
163
+
164
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
+ const handlePersistentChatConversationRetrievalFailure = ex => {
166
+ if (ex.httpResponseStatusCode === 400) {
167
+ logWidgetLoadFailed(ex);
168
+ } else {
169
+ logWidgetLoadCompleteWithError(ex);
170
+ }
171
+ };
172
+
173
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174
+ const handleConversationInitializationFailure = ex => {
175
+ if (ex.httpResponseStatusCode === 400) {
176
+ logWidgetLoadFailed(ex);
177
+ } else {
178
+ logWidgetLoadCompleteWithError(ex);
179
+ }
180
+ };
181
+
182
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
+ const handleChatTokenRetrievalFailure = (dispatch, ex) => {
184
+ if (ex.httpResponseStatusCode === 400) {
185
+ logWidgetLoadFailed(ex);
186
+ } else {
187
+ if (ex.httpResponseStatusCode === 401) {
188
+ dispatch({
189
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILURE_TYPE,
190
+ payload: _StartChatFailureType.StartChatFailureType.Unauthorized
191
+ });
192
+ }
193
+ logWidgetLoadCompleteWithError(ex);
194
+ }
195
+ };
196
+
197
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
198
+ const handleUninitializedChatSDK = ex => {
199
+ logWidgetLoadCompleteWithError(ex);
200
+ };
201
+
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ const handleInvalidOrClosedConversation = (dispatch, chatSDK, props, ex) => {
204
+ var _DataStoreManager$cli;
205
+ logWidgetLoadCompleteWithError(ex);
206
+
207
+ // Reset all internal states
208
+ (0, _endChat.callingStateCleanUp)(dispatch);
209
+ (0, _endChat.endChatStateCleanUp)(dispatch);
210
+ (0, _endChat.closeChatStateCleanUp)(dispatch);
211
+ (0, _endChat.chatSDKStateCleanUp)(chatSDK);
212
+ (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData((0, _utils.getWidgetCacheIdfromProps)(props));
213
+
214
+ // Starts new chat
215
+ dispatch({
216
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
217
+ payload: _ConversationState.ConversationState.Closed
218
+ });
219
+ };