@microsoft/omnichannel-chat-widget 1.0.3-main.527b216 → 1.0.3-main.8b82e52

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 (93) hide show
  1. package/lib/cjs/common/Constants.js +54 -1
  2. package/lib/cjs/common/storage/default/defaultCacheManager.js +7 -6
  3. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +6 -1
  5. package/lib/cjs/common/utils.js +27 -5
  6. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +1 -10
  7. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  8. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -1
  9. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -1
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +14 -13
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  13. package/lib/cjs/components/livechatwidget/common/Deferred.js +2 -3
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -1
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +197 -99
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +29 -27
  17. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  18. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +139 -0
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +2 -255
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +70 -57
  21. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +162 -100
  22. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  23. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +15 -5
  24. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  25. package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  26. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  30. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  31. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +16 -13
  32. package/lib/cjs/contexts/createReducer.js +13 -23
  33. package/lib/cjs/controller/componentController.js +2 -1
  34. package/lib/cjs/index.js +20 -0
  35. package/lib/esm/common/Constants.js +49 -0
  36. package/lib/esm/common/storage/default/defaultCacheManager.js +5 -4
  37. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  38. package/lib/esm/common/telemetry/TelemetryConstants.js +6 -1
  39. package/lib/esm/common/utils.js +25 -4
  40. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -13
  41. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  42. package/lib/esm/components/footerstateful/FooterStateful.js +1 -1
  43. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -1
  44. package/lib/esm/components/headerstateful/HeaderStateful.js +14 -13
  45. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  46. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  47. package/lib/esm/components/livechatwidget/common/Deferred.js +2 -3
  48. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -1
  49. package/lib/esm/components/livechatwidget/common/endChat.js +196 -99
  50. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +29 -27
  51. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  52. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +130 -0
  53. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -255
  54. package/lib/esm/components/livechatwidget/common/startChat.js +71 -58
  55. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -102
  56. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  57. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +15 -5
  58. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  59. package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  60. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  61. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  62. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  64. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  65. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +18 -15
  66. package/lib/esm/contexts/createReducer.js +13 -23
  67. package/lib/esm/controller/componentController.js +2 -1
  68. package/lib/esm/index.js +4 -1
  69. package/lib/types/common/Constants.d.ts +21 -0
  70. package/lib/types/common/interfaces/IContextDataStore.d.ts +3 -3
  71. package/lib/types/common/storage/default/defaultCacheManager.d.ts +2 -1
  72. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -1
  73. package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
  74. package/lib/types/common/utils.d.ts +3 -2
  75. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +6 -0
  76. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
  77. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
  78. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
  79. package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +9 -0
  80. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -6
  81. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  82. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +4 -0
  83. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +8 -7
  84. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  85. package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +2 -1
  86. package/lib/types/index.d.ts +3 -0
  87. package/package.json +2 -1
  88. package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +0 -36
  89. package/lib/cjs/contexts/common/ConversationEndEntity.js +0 -12
  90. package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +0 -30
  91. package/lib/esm/contexts/common/ConversationEndEntity.js +0 -5
  92. package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +0 -6
  93. package/lib/types/contexts/common/ConversationEndEntity.d.ts +0 -4
@@ -3,19 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setPostChatContextAndLoadSurvey = exports.initiatePostChat = exports.checkPostChatEnabled = void 0;
6
+ exports.setPostChatContextAndLoadSurvey = void 0;
7
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
8
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
9
9
  var _ConversationState = require("../../../contexts/common/ConversationState");
10
10
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
11
11
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
12
- var _Constants = require("../../../common/Constants");
13
- var _endChat = require("./endChat");
14
- var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
15
- var _utils = require("../../../common/utils");
16
- var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
17
- var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
18
- var _ConversationEndEntity = require("../../../contexts/common/ConversationEndEntity");
19
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
13
  const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
21
14
  try {
@@ -48,250 +41,4 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
48
41
  });
49
42
  });
50
43
  };
51
-
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
54
- const checkPostChatEnabled = (props, state) => {
55
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
56
- const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_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);
57
- return isPostChatEnabled === _Constants.Constants.true;
58
- };
59
-
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- exports.checkPostChatEnabled = checkPostChatEnabled;
62
- const initiatePostChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
63
- // Check if Postchat already in progress and handle case where chat is ended by customer
64
- if (state.appStates.postChatWorkflowInProgress && state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
65
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
66
- return;
67
- }
68
-
69
- // Conversation Details call required by customer as well as agent
70
- const conversationDetails = await getConversationDetailsCall(chatSDK);
71
- // Start Postchat workflow
72
- dispatch({
73
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
74
- payload: true
75
- });
76
-
77
- // Below logic checks if agent or bot or noone joins conversation and handles them separately
78
- if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.userParticipantTypeTag) {
79
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
80
- // Set use bot settings to false
81
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
82
- } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
83
- await postChatInitiatedByAgent(props, setWebChatStyles, dispatch, state);
84
- } else {
85
- const error = `Conversation was Ended after agent joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
86
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
87
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
88
- ExceptionDetails: {
89
- exception: error
90
- }
91
- });
92
- throw new Error(error);
93
- }
94
- } else if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.botParticipantTypeTag) {
95
- // Set Use bot survey to true
96
- dispatch({
97
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
98
- payload: true
99
- });
100
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
101
- // Set use bot settings to true
102
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, true);
103
- } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
104
- await postChatInitiatedByBot(props, setWebChatStyles, dispatch, state);
105
- } else {
106
- const error = `Conversation was Ended after bot joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
107
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
108
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
109
- ExceptionDetails: {
110
- exception: error
111
- }
112
- });
113
- throw new Error(error);
114
- }
115
- } else {
116
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
117
- // No one has joined chat will be handled by postChat customer
118
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
119
- } else {
120
- const error = `ConversationDetails and App state was not set correctly: conversationDetails = ${JSON.stringify(conversationDetails)} , conversationEndedBy = ${state.appStates.conversationEndedBy}`;
121
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
122
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
123
- ExceptionDetails: {
124
- exception: error
125
- }
126
- });
127
- throw new Error(error);
128
- }
129
- }
130
- };
131
-
132
- // Function for link mode postchat workflow which is essentially same for both customer and agent
133
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
- exports.initiatePostChat = initiatePostChat;
135
- const linkModePostChatWorkflow = (props, dispatch, setWebChatStyles) => {
136
- var _props$webChatContain, _props$webChatContain2;
137
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
138
- Event: _TelemetryConstants.TelemetryEvent.LinkModePostChatWorkflowStarted
139
- });
140
- dispatch({
141
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
142
- payload: _ConversationState.ConversationState.InActive
143
- });
144
-
145
- // Disable SendBox
146
- 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) {
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- setWebChatStyles(styles => {
149
- return {
150
- ...styles,
151
- hideSendBox: true
152
- };
153
- });
154
- }
155
- };
156
-
157
- // Function for embed mode postchat workflow which is essentially same for both customer and agent
158
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
- const embedModePostChatWorkflow = async (dispatch, state) => {
160
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
161
- Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
162
- });
163
- if (state.domainStates.postChatContext) {
164
- dispatch({
165
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
166
- payload: _ConversationState.ConversationState.PostchatLoading
167
- });
168
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
169
- const loadPostChatEvent = {
170
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
171
- };
172
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
173
- } else {
174
- const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
175
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
176
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
177
- ExceptionDetails: {
178
- exception: error
179
- }
180
- });
181
- throw new Error(error);
182
- }
183
- };
184
-
185
- // Function will handle only postchat cases initiated by customer
186
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
- const postChatInitiatedByCustomer = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, shouldUseBotSetting) => {
188
- let postChatSurveyMode = "";
189
- if (shouldUseBotSetting) {
190
- var _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4;
191
- postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_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_postconversationsurveybotsurveymode);
192
- } else {
193
- var _props$chatConfig3, _props$chatConfig3$Li, _state$domainStates$l5, _state$domainStates$l6;
194
- postChatSurveyMode = ((_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : (_state$domainStates$l6 = _state$domainStates$l5.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.msdyn_postconversationsurveymode);
195
- }
196
- // Check if agent or bot has joined conversation
197
- if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
198
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
199
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromCustomer,
200
- Description: shouldUseBotSetting ? "PostChat Workflow was started by customer using bot settings" : "PostChat Workflow was started by customer using agent settings"
201
- });
202
- const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
203
- // End chat call to end chatsdk but not close chat, only if chat ended by customer
204
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
205
- // Saving request Id below for chat transcript calls
206
- if (chatSession) {
207
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
- chatSDK.chatToken = chatSession.chatToken ?? {};
209
- chatSDK.requestId = chatSession.requestId;
210
- }
211
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
212
- await embedModePostChatWorkflow(dispatch, state);
213
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
214
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
215
- } else {
216
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
217
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
218
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
219
- ExceptionDetails: {
220
- exception: error
221
- }
222
- });
223
- throw new Error(error);
224
- }
225
- } else {
226
- // Agent did not join chat so end chat normally
227
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
228
- }
229
- };
230
-
231
- // Function will handle only postchat cases initiated by agent
232
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
- const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
234
- var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
235
- const postChatSurveyMode = ((_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : (_state$domainStates$l8 = _state$domainStates$l7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l8 === void 0 ? void 0 : _state$domainStates$l8.msdyn_postconversationsurveymode);
236
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
237
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromAgent,
238
- Description: "PostChat Workflow was started by agent"
239
- });
240
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
241
- await embedModePostChatWorkflow(dispatch, state);
242
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
243
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
244
- } else {
245
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
246
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
247
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
248
- ExceptionDetails: {
249
- exception: error
250
- }
251
- });
252
- throw new Error(error);
253
- }
254
- };
255
-
256
- // Function will handle only postchat cases initiated by bot
257
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
258
- const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
259
- var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
260
- const postChatSurveyMode = ((_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l9 = state.domainStates.liveChatConfig) === null || _state$domainStates$l9 === void 0 ? void 0 : (_state$domainStates$l10 = _state$domainStates$l9.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l10 === void 0 ? void 0 : _state$domainStates$l10.msdyn_postconversationsurveybotsurveymode);
261
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
262
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromBot,
263
- Description: "PostChat Workflow was started by bot"
264
- });
265
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
266
- await embedModePostChatWorkflow(dispatch, state);
267
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
268
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
269
- } else {
270
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
271
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
272
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
273
- ExceptionDetails: {
274
- exception: error
275
- }
276
- });
277
- throw new Error(error);
278
- }
279
- };
280
-
281
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
282
- const getConversationDetailsCall = async chatSDK => {
283
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
284
- let conversationDetails = undefined;
285
- try {
286
- conversationDetails = await chatSDK.getConversationDetails();
287
- } catch (error) {
288
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
289
- Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallFailed,
290
- ExceptionDetails: {
291
- exception: `Get Conversation Details Call Failed : ${error}`
292
- }
293
- });
294
- _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
295
- }
296
- return conversationDetails;
297
- };
44
+ exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
@@ -25,21 +25,26 @@ var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
25
25
  let optionalParams = {};
26
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
27
  let widgetInstanceId;
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ let popoutWidgetInstanceId;
28
30
 
29
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
32
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
31
- var _props$controlProps;
32
33
  optionalParams = {}; //Resetting to ensure no stale values
33
- widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
34
+ widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
34
35
 
35
36
  // reconnect > chat from cache
36
37
  await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
37
-
38
38
  // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
39
39
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
40
40
  return;
41
41
  }
42
42
 
43
+ // Check if there is any active popout chats in cache
44
+ if (await canStartPopoutChat(props)) {
45
+ return;
46
+ }
47
+
43
48
  // Can connect to existing chat session
44
49
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
45
50
  return;
@@ -50,20 +55,13 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
50
55
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
51
56
 
52
57
  //Setting PreChat and intiate chat
53
- setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, undefined, props);
58
+ await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, undefined, props);
54
59
  };
55
60
 
56
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
62
  exports.prepareStartChat = prepareStartChat;
58
63
  const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
59
64
  //Handle reconnect scenario
60
- if (state) {
61
- await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
62
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
63
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
64
- return;
65
- }
66
- }
67
65
 
68
66
  // Getting prechat Survey Context
69
67
  const parseToJson = false;
@@ -95,11 +93,11 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
95
93
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
94
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
97
95
  const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
98
- var _props$controlProps2;
96
+ var _props$controlProps;
99
97
  let isStartChatSuccessful = false;
100
98
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
101
99
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
102
- const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
100
+ const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideErrorUIPane;
103
101
  try {
104
102
  var _newAdapter$activity$, _TelemetryTimers$Widg;
105
103
  //Start widget load timer
@@ -113,11 +111,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
113
111
  // set auth token to chat sdk before start chat
114
112
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
115
113
  if (!authSuccess) {
116
- dispatch({
117
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
118
- payload: _ConversationState.ConversationState.Closed
119
- });
120
- return;
114
+ // Replacing with error ui
115
+ throw new Error("Authentication was not successful");
121
116
  }
122
117
  }
123
118
 
@@ -135,7 +130,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
135
130
  try {
136
131
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
137
132
  // Set custom context params
138
- setCustomContextParams(chatSDK);
133
+ setCustomContextParams();
139
134
  const defaultOptionalParams = {
140
135
  sendDefaultInitContext: true,
141
136
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -164,21 +159,6 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
164
159
  payload: chatToken
165
160
  });
166
161
  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));
167
- if (persistedState) {
168
- dispatch({
169
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
170
- payload: persistedState
171
- });
172
- (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
173
- return;
174
- }
175
-
176
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
178
- dispatch({
179
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
180
- payload: liveChatContext
181
- });
182
162
 
183
163
  // Set app state to Active
184
164
  if (isStartChatSuccessful) {
@@ -193,14 +173,30 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
193
173
  payload: _ConversationState.ConversationState.Active
194
174
  });
195
175
  }
176
+ if (persistedState) {
177
+ dispatch({
178
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
179
+ payload: persistedState
180
+ });
181
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
182
+ return;
183
+ }
184
+
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
187
+ dispatch({
188
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
189
+ payload: liveChatContext
190
+ });
196
191
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
197
192
  Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
198
193
  Description: "Widget load complete",
199
194
  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
200
195
  });
201
196
 
202
- // Set post chat context in state, no survey load
203
- (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
197
+ // Set post chat context in state
198
+ // Commenting this for now as post chat context is fetched during end chat
199
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
204
200
 
205
201
  // Updating chat session detail for telemetry
206
202
  await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
@@ -224,12 +220,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
224
220
  });
225
221
  return;
226
222
  }
223
+ dispatch({
224
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
225
+ payload: true
226
+ });
227
227
  if (!hideErrorUIPane) {
228
228
  // Set app state to failing start chat if hideErrorUI is not turned on
229
- dispatch({
230
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
231
- payload: true
232
- });
233
229
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
234
230
  Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
235
231
  Description: "Error UI Pane Loaded"
@@ -266,15 +262,15 @@ const forceEndChat = async chatSDK => {
266
262
 
267
263
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
268
264
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
269
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
265
+ var _state$appStates, _persistedState$domai6, _persistedState$appSt;
270
266
  // By pass this function in case of popout chat
271
- if (state.appStates.hideStartChatButton === true) {
267
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.hideStartChatButton) === true) {
272
268
  return false;
273
269
  }
274
- 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, (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
270
+ const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
275
271
 
276
272
  //Connect to only active chat session
277
- 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)) {
273
+ 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) {
278
274
  var _persistedState$domai7;
279
275
  dispatch({
280
276
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -285,16 +281,15 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
285
281
  };
286
282
  await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
287
283
  return true;
288
- } else {
289
- return false;
290
284
  }
285
+ return false;
291
286
  };
292
287
 
293
288
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
- const setCustomContextParams = chatSDK => {
295
- var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
289
+ const setCustomContextParams = () => {
290
+ var _persistedState$domai8;
296
291
  // Add custom context only for unauthenticated chat
297
- const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
292
+ const persistedState = (0, _utils.getStateFromCache)(widgetInstanceId);
298
293
  if (!(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
299
294
  var _persistedState$domai9, _persistedState$domai10;
300
295
  if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
@@ -312,25 +307,43 @@ const setCustomContextParams = chatSDK => {
312
307
  });
313
308
  }
314
309
  };
310
+ const canStartPopoutChat = async props => {
311
+ if (props.allowSdkChatSupport === false) {
312
+ return false;
313
+ }
314
+ popoutWidgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props, true);
315
+ if (!(0, _utils.isNullOrEmptyString)(popoutWidgetInstanceId)) {
316
+ var _persistedState$domai11, _persistedState$appSt2;
317
+ const persistedState = (0, _utils.getStateFromCache)(popoutWidgetInstanceId);
318
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai11 = persistedState.domainStates) === null || _persistedState$domai11 === void 0 ? void 0 : _persistedState$domai11.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt2 = persistedState.appStates) === null || _persistedState$appSt2 === void 0 ? void 0 : _persistedState$appSt2.conversationState) === _ConversationState.ConversationState.Active) {
319
+ // Initiate popout chat
320
+ _omnichannelChatComponents.BroadcastService.postMessage({
321
+ eventName: _TelemetryConstants.BroadcastEvent.InitiateStartChatInPopoutMode
322
+ });
323
+ return true;
324
+ }
325
+ }
326
+ return false;
327
+ };
315
328
 
316
329
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
330
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
318
331
  var _state$domainStates, _state$domainStates$l;
319
- const requestId = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
332
+ const requestIdFromCache = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
320
333
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
334
  let conversationDetails = undefined;
322
335
 
323
- //Preserve old requestId
324
- const oldRequestId = chatSDK.requestId ?? "";
336
+ //Preserve current requestId
337
+ const currentRequestId = chatSDK.requestId ?? "";
325
338
  dispatch({
326
339
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
327
- payload: oldRequestId
340
+ payload: currentRequestId
328
341
  });
329
342
  try {
330
- chatSDK.requestId = requestId;
343
+ chatSDK.requestId = requestIdFromCache;
331
344
  conversationDetails = await chatSDK.getConversationDetails();
332
345
  if (Object.keys(conversationDetails).length === 0) {
333
- chatSDK.requestId = oldRequestId;
346
+ chatSDK.requestId = currentRequestId;
334
347
  return false;
335
348
  }
336
349
  if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
@@ -338,7 +351,7 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
338
351
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
339
352
  payload: undefined
340
353
  });
341
- chatSDK.requestId = oldRequestId;
354
+ chatSDK.requestId = currentRequestId;
342
355
  return false;
343
356
  }
344
357
  return true;
@@ -349,7 +362,7 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
349
362
  exception: `Conversation is not valid: ${erorr}`
350
363
  }
351
364
  });
352
- chatSDK.requestId = oldRequestId;
365
+ chatSDK.requestId = currentRequestId;
353
366
  return false;
354
367
  }
355
368
  };