@microsoft/omnichannel-chat-widget 0.1.0-main.9e62ed8 → 0.1.0-main.a60f242

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 (47) hide show
  1. package/lib/cjs/common/Constants.js +2 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
  3. package/lib/cjs/common/utils.js +48 -2
  4. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  5. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  6. package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
  7. package/lib/cjs/components/livechatwidget/common/endChat.js +49 -17
  8. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +9 -0
  9. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  10. package/lib/cjs/components/livechatwidget/common/startChat.js +115 -80
  11. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +89 -99
  12. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  13. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  14. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  15. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
  16. package/lib/cjs/controller/componentController.js +2 -2
  17. package/lib/esm/common/Constants.js +2 -0
  18. package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
  19. package/lib/esm/common/utils.js +36 -0
  20. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  21. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  22. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  23. package/lib/esm/components/livechatwidget/common/endChat.js +50 -18
  24. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +10 -2
  25. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  26. package/lib/esm/components/livechatwidget/common/startChat.js +114 -80
  27. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +89 -97
  28. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  29. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  30. package/lib/esm/contexts/common/ConversationState.js +3 -2
  31. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
  32. package/lib/esm/controller/componentController.js +2 -2
  33. package/lib/types/common/Constants.d.ts +1 -0
  34. package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -1
  35. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  36. package/lib/types/common/utils.d.ts +3 -0
  37. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  38. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  39. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
  40. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  41. package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -1
  42. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  43. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  44. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  45. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  46. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +0 -1
  47. package/package.json +1 -1
@@ -167,6 +167,8 @@ _defineProperty(Constants, "internetConnectionTestUrlText", "Omnichannel Connect
167
167
 
168
168
  _defineProperty(Constants, "ChatWidgetStateChangedPrefix", "ChatWidgetStateChanged");
169
169
 
170
+ _defineProperty(Constants, "PostChatLoadingDurationInMs", 2000);
171
+
170
172
  const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
171
173
  exports.Regex = Regex;
172
174
 
@@ -59,6 +59,7 @@ exports.BroadcastEvent = BroadcastEvent;
59
59
  BroadcastEvent["ChatInitiated"] = "ChatInitiated";
60
60
  BroadcastEvent["CloseChat"] = "CloseChat";
61
61
  BroadcastEvent["InitiateEndChatOnBrowserUnload"] = "InitiateEndChatOnBrowserUnload";
62
+ BroadcastEvent["ClosePopoutWindow"] = "ClosePopoutWindow";
62
63
  })(BroadcastEvent || (exports.BroadcastEvent = BroadcastEvent = {}));
63
64
 
64
65
  let TelemetryEvent;
@@ -140,6 +141,8 @@ exports.TelemetryEvent = TelemetryEvent;
140
141
  TelemetryEvent["AudioToggleButtonClicked"] = "AudioToggleButtonClicked";
141
142
  TelemetryEvent["SuppressBotMagicCodeSucceeded"] = "SuppressBotMagicCodeSucceeded";
142
143
  TelemetryEvent["SuppressBotMagicCodeFailed"] = "SuppressBotMagicCodeFailed";
144
+ TelemetryEvent["GetConversationDetailsException"] = "GetConversationDetailsException";
145
+ TelemetryEvent["BrowserUnloadEventStarted"] = "BrowserUnloadEventStarted";
143
146
  TelemetryEvent["ProcessingHTMLTextMiddlewareFailed"] = "ProcessingHTMLTextMiddlewareFailed";
144
147
  TelemetryEvent["ProcessingSanitizationMiddlewareFailed"] = "ProcessingSanitizationMiddlewareFailed";
145
148
  TelemetryEvent["FormatTagsMiddlewareJSONStringifyFailed"] = "FormatTagsMiddlewareJSONStringifyFailed";
@@ -211,6 +214,7 @@ class TelemetryConstants {
211
214
  case TelemetryEvent.MessageSent:
212
215
  case TelemetryEvent.MessageReceived:
213
216
  case TelemetryEvent.CustomContextReceived:
217
+ case TelemetryEvent.BrowserUnloadEventStarted:
214
218
  return ScenarioType.ACTIONS;
215
219
 
216
220
  case TelemetryEvent.StartChatSDKCall:
@@ -3,10 +3,12 @@
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.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.createTimer = exports.changeLanguageCodeFormatForWebChat = void 0;
6
+ exports.setTabIndices = exports.setFocusOnSendBox = exports.setFocusOnElement = exports.preventFocusToMoveOutOfElement = exports.parseAdaptiveCardPayload = exports.newGuid = exports.isUndefinedOrEmpty = exports.isNullOrUndefined = exports.isNullOrEmptyString = exports.getWidgetEndChatEventName = exports.getWidgetCacheId = exports.getTimestampHourMinute = exports.getStateFromCache = exports.getLocaleDirection = exports.getIconText = exports.getDomain = exports.findParentFocusableElementsWithoutChildContainer = exports.findAllFocusableElement = exports.extractPreChatSurveyResponseValues = exports.escapeHtml = exports.createTimer = exports.changeLanguageCodeFormatForWebChat = exports.addDelayInMs = void 0;
7
7
 
8
8
  var _Constants = require("./Constants");
9
9
 
10
+ var _DataStoreManager = require("./contextDataStore/DataStoreManager");
11
+
10
12
  var _KeyCodes = require("./KeyCodes");
11
13
 
12
14
  var _TelemetryConstants = require("./telemetry/TelemetryConstants");
@@ -360,6 +362,50 @@ exports.getWidgetCacheId = getWidgetCacheId;
360
362
 
361
363
  const getWidgetEndChatEventName = (orgId, widgetId) => {
362
364
  return `${_TelemetryConstants.BroadcastEvent.ChatEnded}_${orgId}_${widgetId}`;
365
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
366
+
367
+
368
+ exports.getWidgetEndChatEventName = getWidgetEndChatEventName;
369
+
370
+ const getStateFromCache = (orgId, widgetId) => {
371
+ // Getting updated state from cache
372
+ try {
373
+ if (_DataStoreManager.DataStoreManager.clientDataStore) {
374
+ var _DataStoreManager$cli;
375
+
376
+ const widgetStateEventName = getWidgetCacheId(orgId, widgetId);
377
+ const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
378
+ const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
379
+ return persistedState;
380
+ } else {
381
+ return null;
382
+ }
383
+ } catch (error) {
384
+ console.log(error);
385
+ return null;
386
+ }
387
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
388
+
389
+
390
+ exports.getStateFromCache = getStateFromCache;
391
+
392
+ const isUndefinedOrEmpty = object => {
393
+ if (object) {
394
+ if (Object.keys(object).length === 0) {
395
+ return true;
396
+ }
397
+
398
+ return false;
399
+ } else {
400
+ return true;
401
+ }
402
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
403
+
404
+
405
+ exports.isUndefinedOrEmpty = isUndefinedOrEmpty;
406
+
407
+ const addDelayInMs = ms => {
408
+ return new Promise(resolve => setTimeout(resolve, ms));
363
409
  };
364
410
 
365
- exports.getWidgetEndChatEventName = getWidgetEndChatEventName;
411
+ exports.addDelayInMs = addDelayInMs;
@@ -82,6 +82,10 @@ const ChatButtonStateful = props => {
82
82
  titleText: "We're Offline",
83
83
  subtitleText: "No agents available",
84
84
  onClick: async () => {
85
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
86
+ Event: _TelemetryConstants.TelemetryEvent.LCWChatButtonClicked
87
+ });
88
+
85
89
  if (state.appStates.isMinimized) {
86
90
  dispatch({
87
91
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
@@ -41,7 +41,6 @@ const ConfirmationPaneStateful = props => {
41
41
  const {
42
42
  prepareEndChat
43
43
  } = props; // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
44
 
46
45
  const [adapter] = (0, _useChatAdapterStore.default)();
47
46
  const controlProps = {
@@ -81,8 +81,8 @@ const HeaderStateful = props => {
81
81
  });
82
82
  },
83
83
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
84
- hideTitle: state.appStates.conversationState === _ConversationState.ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
85
- hideIcon: state.appStates.conversationState === _ConversationState.ConversationState.Loading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
84
+ hideTitle: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
85
+ hideIcon: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
86
86
  hideCloseButton: state.appStates.conversationState === _ConversationState.ConversationState.Loading || state.appStates.conversationState === _ConversationState.ConversationState.Prechat || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
87
87
  };
88
88
  const outOfOfficeControlProps = {
@@ -27,18 +27,35 @@ var _utils = require("../../../common/utils");
27
27
 
28
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
29
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
30
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
30
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
31
31
 
32
32
  const isPostChatEnabled = (_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$l2.msdyn_postconversationsurveyenable;
33
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
34
- const conversationDetails = await chatSDK.getConversationDetails();
33
+ const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode; // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
34
 
36
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
35
+ let conversationDetails = undefined;
36
+
37
+ try {
38
+ conversationDetails = await chatSDK.getConversationDetails();
39
+ } catch (erorr) {
40
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
41
+ Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsException,
42
+ ExceptionDetails: {
43
+ exception: `Failed to get conversation details: ${erorr}`
44
+ }
45
+ });
46
+ }
47
+
48
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
37
49
  const skipEndChatSDK = false;
38
50
  const skipCloseChat = true;
39
51
  await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
40
52
 
41
53
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
54
+ dispatch({
55
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
56
+ payload: _ConversationState.ConversationState.PostchatLoading
57
+ });
58
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
42
59
  const loadPostChatEvent = {
43
60
  eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
44
61
  };
@@ -50,9 +67,11 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
50
67
  payload: _ConversationState.ConversationState.InActive
51
68
  });
52
69
  }
53
- } else {
54
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
70
+
71
+ return;
55
72
  }
73
+
74
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
56
75
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
76
 
58
77
 
@@ -65,16 +84,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
65
84
  Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCall
66
85
  });
67
86
 
68
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
69
-
70
- dispatch({
71
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
72
- payload: undefined
73
- });
74
- dispatch({
75
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
76
- payload: undefined
77
- });
87
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
78
88
  } catch (ex) {
79
89
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
80
90
  Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCallFailed,
@@ -85,7 +95,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
85
95
 
86
96
  postMessageToOtherTab = false;
87
97
  }
88
- }
98
+ } // Need to clear these states immediately when chat ended from OC.
99
+
100
+
101
+ dispatch({
102
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
103
+ payload: undefined
104
+ });
105
+ dispatch({
106
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
107
+ payload: undefined
108
+ });
109
+ dispatch({
110
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
111
+ payload: undefined
112
+ });
89
113
 
90
114
  if (!skipCloseChat) {
91
115
  try {
@@ -117,6 +141,14 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
117
141
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
118
142
  payload: 0
119
143
  });
144
+ dispatch({
145
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
146
+ payload: {
147
+ proactiveChatBodyTitle: "",
148
+ proactiveChatEnablePrechat: false,
149
+ proactiveChatInNewWindow: false
150
+ }
151
+ });
120
152
 
121
153
  if (postMessageToOtherTab) {
122
154
  var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
@@ -67,6 +67,8 @@ var _cardActionMiddleware = require("../../webchatcontainerstateful/webchatcontr
67
67
 
68
68
  var _messageTimestampMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware"));
69
69
 
70
+ var _Constants = require("../../../common/Constants");
71
+
70
72
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
71
73
 
72
74
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -103,8 +105,15 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
103
105
  });
104
106
  }
105
107
 
108
+ _WebChatStoreLoader.WebChatStoreLoader.store = null;
109
+
106
110
  if (isPostChatEnabled === "true") {
107
111
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
112
+ dispatch({
113
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
114
+ payload: _ConversationState.ConversationState.PostchatLoading
115
+ });
116
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
108
117
  const loadPostChatEvent = {
109
118
  eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
110
119
  };
@@ -43,10 +43,6 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
43
43
 
44
44
 
45
45
  _omnichannelChatComponents.BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
46
- dispatch({
47
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
48
- payload: _ConversationState.ConversationState.Loading
49
- });
50
46
  dispatch({
51
47
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
52
48
  payload: _ConversationState.ConversationState.Postchat
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prepareStartChat = exports.initStartChat = void 0;
6
+ exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = void 0;
7
7
 
8
8
  var _Constants = require("../../../common/Constants");
9
9
 
@@ -11,8 +11,6 @@ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants"
11
11
 
12
12
  var _ConversationState = require("../../../contexts/common/ConversationState");
13
13
 
14
- var _DataStoreManager = require("../../../common/contextDataStore/DataStoreManager");
15
-
16
14
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
17
15
 
18
16
  var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
@@ -43,6 +41,9 @@ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-expli
43
41
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
44
42
  var _props$reconnectChatP;
45
43
 
44
+ optionalParams = {}; //Resetting to ensure no stale values
45
+ // Can connect to existing chat session
46
+
46
47
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
47
48
  return;
48
49
  } // Redirecting if unauthenticated reconnect chat expired
@@ -52,57 +53,74 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
52
53
  var _props$reconnectChatP2, _props$reconnectChatP3;
53
54
 
54
55
  await (0, _reconnectChatHelper.handleRedirectUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, initStartChat, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.redirectInSameWindow);
55
- } else {
56
- // Getting PreChat Survey Context
57
- const parseToJson = false;
58
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
59
- const showPrechat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
56
+ return;
57
+ } // Getting reconnectId for authenticated chat
60
58
 
61
- const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
62
59
 
63
- if (reconnectId) {
64
- dispatch({
65
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
66
- payload: reconnectId
67
- });
68
- dispatch({
69
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
70
- payload: _ConversationState.ConversationState.ReconnectChat
71
- });
72
- } else if (showPrechat) {
73
- dispatch({
74
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
75
- payload: preChatSurveyResponse
76
- });
77
- dispatch({
78
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
79
- payload: _ConversationState.ConversationState.Prechat
80
- });
81
- setCustomContextParams(props, state);
82
- } else {
83
- dispatch({
84
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
85
- payload: _ConversationState.ConversationState.Loading
86
- });
87
- setCustomContextParams(props, state);
88
- await initStartChat(chatSDK, dispatch, setAdapter);
89
- }
90
- }
60
+ const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
61
+
62
+ if (reconnectId) {
63
+ dispatch({
64
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
65
+ payload: reconnectId
66
+ });
67
+ dispatch({
68
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
69
+ payload: _ConversationState.ConversationState.ReconnectChat
70
+ });
71
+ return;
72
+ } // Set custom context params
73
+
74
+
75
+ setCustomContextParams(props, chatSDK); // Setting Proactive chat settings
76
+
77
+ const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
78
+ const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat; //Setting PreChat and intiate chat
79
+
80
+ setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
91
81
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
82
 
93
83
 
94
84
  exports.prepareStartChat = prepareStartChat;
95
85
 
86
+ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState) => {
87
+ // Getting prechat Survey Context
88
+ const parseToJson = false;
89
+ const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
90
+ const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse;
91
+
92
+ if (showPrechat) {
93
+ dispatch({
94
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
95
+ payload: preChatSurveyResponse
96
+ });
97
+ dispatch({
98
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
99
+ payload: _ConversationState.ConversationState.Prechat
100
+ });
101
+ return;
102
+ } //Initiate start chat
103
+
104
+
105
+ dispatch({
106
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
107
+ payload: _ConversationState.ConversationState.Loading
108
+ });
109
+ await initStartChat(chatSDK, dispatch, setAdapter);
110
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+
112
+
113
+ exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
114
+
96
115
  const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
97
116
  try {
98
117
  var _newAdapter$activity$, _TelemetryTimers$Widg;
99
118
 
100
- let isStartChatSuccessful = false;
119
+ let isStartChatSuccessful = false; //Check if chat retrieved from cache
101
120
 
102
121
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
103
122
  var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
104
123
 
105
- // Broadcasting limited cached chat details
106
124
  _omnichannelChatComponents.BroadcastService.postMessage({
107
125
  eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
108
126
  payload: {
@@ -113,11 +131,13 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
113
131
  }
114
132
 
115
133
  try {
134
+ //Start widget load timer
116
135
  _TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
117
136
 
118
137
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
119
138
  Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
120
- });
139
+ }); // Set optional params
140
+
121
141
 
122
142
  optionalParams = Object.assign({}, params, optionalParams);
123
143
  await chatSDK.startChat(optionalParams);
@@ -130,46 +150,51 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
130
150
  }
131
151
  });
132
152
 
133
- isStartChatSuccessful = false;
134
- }
153
+ isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
154
+ // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
155
+
156
+ dispatch({
157
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
158
+ payload: _ConversationState.ConversationState.Closed
159
+ });
160
+ return;
161
+ } // New adapter creation
162
+
135
163
 
136
164
  const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
137
165
  setAdapter(newAdapter);
138
166
  const chatToken = await chatSDK.getChatToken();
167
+ dispatch({
168
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
169
+ payload: chatToken
170
+ });
139
171
  newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
140
172
 
141
- if (!persistedState) {
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
144
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
146
- dispatch({
147
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
148
- payload: chatToken
149
- });
150
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
151
-
152
-
153
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
154
- dispatch({
155
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
156
- payload: liveChatContext
157
- });
158
- await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
159
- await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
160
-
161
- if (isStartChatSuccessful) {
162
- dispatch({
163
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
164
- payload: _ConversationState.ConversationState.Active
165
- });
166
- }
167
- } else {
173
+ if (persistedState) {
168
174
  dispatch({
169
175
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
170
176
  payload: persistedState
171
177
  });
172
178
  await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
179
+ return;
180
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+
182
+
183
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
184
+ dispatch({
185
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
186
+ payload: liveChatContext
187
+ }); // Set post chat context in state, no survey load
188
+
189
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
190
+
191
+ await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
192
+
193
+ if (isStartChatSuccessful) {
194
+ dispatch({
195
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
196
+ payload: _ConversationState.ConversationState.Active
197
+ });
173
198
  }
174
199
 
175
200
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -198,6 +223,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
198
223
  payload: _ConversationState.ConversationState.OutOfOffice
199
224
  });
200
225
  }
226
+ } finally {
227
+ optionalParams = {};
201
228
  }
202
229
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
230
 
@@ -205,13 +232,16 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
205
232
  exports.initStartChat = initStartChat;
206
233
 
207
234
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
208
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli, _persistedState$domai6;
235
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
236
+
237
+ // By pass this function in case of popout chat
238
+ if (state.appStates.skipChatButtonRendering === true) {
239
+ return false;
240
+ }
209
241
 
210
- const widgetStateEventName = (0, _utils.getWidgetCacheId)((chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId) ?? "", (chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId) ?? "");
211
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
212
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
242
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId); //Connect to only active chat session
213
243
 
214
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai6 = persistedState.domainStates) !== null && _persistedState$domai6 !== void 0 && _persistedState$domai6.liveChatContext) {
244
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === _ConversationState.ConversationState.Active) {
215
245
  var _persistedState$domai7;
216
246
 
217
247
  dispatch({
@@ -226,15 +256,20 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
226
256
  } else {
227
257
  return false;
228
258
  }
229
- };
259
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
260
+
261
+
262
+ const setCustomContextParams = (props, chatSDK) => {
263
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
264
+
265
+ // Add custom context only for unauthenticated chat
266
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId);
230
267
 
231
- const setCustomContextParams = (props, state) => {
232
- var _props$chatConfig, _state$domainStates;
268
+ if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
269
+ var _persistedState$domai9;
233
270
 
234
- // Add custom context if any only for unauthenticated chat
235
- if (!((_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && _props$chatConfig.LiveChatConfigAuthSettings) && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
236
271
  optionalParams = Object.assign({}, optionalParams, {
237
- customContext: state.domainStates.customContext
272
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
238
273
  });
239
274
  }
240
275
  };