@microsoft/omnichannel-chat-widget 0.1.0-main.4188c11 → 0.1.0-main.4eb4d1f

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 (101) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +16 -2
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +21 -3
  4. package/lib/cjs/common/utils.js +62 -2
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
  9. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  11. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  12. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -1
  13. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +68 -22
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -3
  17. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  18. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  19. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +173 -67
  21. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +179 -84
  22. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  23. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  24. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  25. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  26. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  32. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  33. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  34. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  35. package/lib/cjs/contexts/createReducer.js +8 -0
  36. package/lib/cjs/controller/componentController.js +3 -3
  37. package/lib/esm/common/Constants.js +16 -2
  38. package/lib/esm/common/telemetry/TelemetryConstants.js +21 -3
  39. package/lib/esm/common/utils.js +43 -0
  40. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  41. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  42. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  43. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  44. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  45. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  46. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  47. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  48. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  49. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  50. package/lib/esm/components/livechatwidget/common/endChat.js +65 -22
  51. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -5
  52. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  53. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  54. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  55. package/lib/esm/components/livechatwidget/common/startChat.js +170 -68
  56. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +173 -86
  57. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  58. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  59. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  60. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  61. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  62. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  64. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  65. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  66. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  67. package/lib/esm/contexts/common/ConversationState.js +3 -2
  68. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  69. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  70. package/lib/esm/contexts/createReducer.js +8 -0
  71. package/lib/esm/controller/componentController.js +3 -3
  72. package/lib/types/common/Constants.d.ts +8 -1
  73. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  74. package/lib/types/common/telemetry/TelemetryConstants.d.ts +21 -4
  75. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  76. package/lib/types/common/utils.d.ts +6 -1
  77. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  78. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  79. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  80. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  81. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  82. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  83. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  84. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  85. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  86. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  87. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  88. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  89. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  90. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  91. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  92. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  93. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  94. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  95. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  96. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  97. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  98. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  99. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  100. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  101. package/package.json +2 -2
@@ -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");
@@ -35,10 +33,17 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
35
33
 
36
34
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
37
35
 
36
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
37
+
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ let optionalParams = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+
39
41
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
40
42
  var _props$reconnectChatP;
41
43
 
44
+ optionalParams = {}; //Resetting to ensure no stale values
45
+ // Can connect to existing chat session
46
+
42
47
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
43
48
  return;
44
49
  } // Redirecting if unauthenticated reconnect chat expired
@@ -47,58 +52,128 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
47
52
  if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
48
53
  var _props$reconnectChatP2, _props$reconnectChatP3;
49
54
 
50
- 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);
51
- } else {
52
- // Getting PreChat Survey Context
53
- const parseToJson = false;
54
- const preChatSurveyResponse = await chatSDK.getPreChatSurvey(parseToJson);
55
- const showPrechat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat ? preChatSurveyResponse && state.appStates.proactiveChatStates.proactiveChatEnablePrechat : preChatSurveyResponse; // Getting reconnectId for authenticated chat
55
+ await (0, _reconnectChatHelper.handleRedirectUnauthenticatedReconnectChat)(chatSDK, props.chatConfig, props.getAuthToken, 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);
56
+ return;
57
+ } // Getting reconnectId for authenticated chat
56
58
 
57
- const reconnectId = await (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK);
58
59
 
59
- if (reconnectId) {
60
- dispatch({
61
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
62
- payload: reconnectId
63
- });
64
- dispatch({
65
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
66
- payload: _ConversationState.ConversationState.ReconnectChat
67
- });
68
- } else if (showPrechat) {
69
- dispatch({
70
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PRE_CHAT_SURVEY_RESPONSE,
71
- payload: preChatSurveyResponse
72
- });
73
- dispatch({
74
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
75
- payload: _ConversationState.ConversationState.Prechat
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, props.chatConfig, props.getAuthToken, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat);
81
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+
83
+
84
+ exports.prepareStartChat = prepareStartChat;
85
+
86
+ const setPreChatAndInitiateChat = async (chatSDK, chatConfig, getAuthToken, 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, chatConfig, getAuthToken, dispatch, setAdapter);
110
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+
112
+
113
+ exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
114
+
115
+ const handleAuthentication = async (chatSDK, chatConfig, getAuthToken) => {
116
+ if (getAuthToken) {
117
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
118
+ Event: _TelemetryConstants.TelemetryEvent.GetAuthTokenCalled
119
+ });
120
+
121
+ let authClientFunction = undefined;
122
+
123
+ if (chatConfig !== null && chatConfig !== void 0 && chatConfig.LiveChatConfigAuthSettings) {
124
+ var _chatConfig$LiveChatC;
125
+
126
+ authClientFunction = (chatConfig === null || chatConfig === void 0 ? void 0 : (_chatConfig$LiveChatC = chatConfig.LiveChatConfigAuthSettings) === null || _chatConfig$LiveChatC === void 0 ? void 0 : _chatConfig$LiveChatC.msdyn_javascriptclientfunction) ?? undefined;
127
+ }
128
+
129
+ const token = await getAuthToken(authClientFunction);
130
+
131
+ if (!(0, _utils.isNullOrEmptyString)(token)) {
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ chatSDK.setAuthTokenProvider(async () => {
134
+ return token;
76
135
  });
77
136
  } else {
78
- dispatch({
79
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
80
- payload: _ConversationState.ConversationState.Loading
137
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
138
+ Event: _TelemetryConstants.TelemetryEvent.ReceivedNullOrEmptyToken
81
139
  });
82
- await initStartChat(chatSDK, dispatch, setAdapter);
83
140
  }
84
141
  }
85
142
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
143
 
87
144
 
88
- exports.prepareStartChat = prepareStartChat;
89
-
90
- const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedState) => {
145
+ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
91
146
  try {
92
147
  var _newAdapter$activity$, _TelemetryTimers$Widg;
93
148
 
149
+ let isStartChatSuccessful = false; //Check if chat retrieved from cache
150
+
151
+ if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
152
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4, _persistedState$domai5;
153
+
154
+ _omnichannelChatComponents.BroadcastService.postMessage({
155
+ eventName: _TelemetryConstants.BroadcastEvent.ChatRetrievedFromCache,
156
+ payload: {
157
+ chatId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.liveChatContext) === null || _persistedState$domai2 === void 0 ? void 0 : (_persistedState$domai3 = _persistedState$domai2.chatToken) === null || _persistedState$domai3 === void 0 ? void 0 : _persistedState$domai3.chatId,
158
+ requestId: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai4 = persistedState.domainStates) === null || _persistedState$domai4 === void 0 ? void 0 : (_persistedState$domai5 = _persistedState$domai4.liveChatContext) === null || _persistedState$domai5 === void 0 ? void 0 : _persistedState$domai5.requestId
159
+ }
160
+ });
161
+ }
162
+
94
163
  try {
164
+ //Start widget load timer
95
165
  _TelemetryManager.TelemetryTimers.WidgetLoadTimer = (0, _utils.createTimer)();
96
166
 
97
167
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
98
168
  Event: _TelemetryConstants.TelemetryEvent.StartChatSDKCall
99
- });
169
+ }); // Set optional params
170
+
100
171
 
101
- await chatSDK.startChat(params);
172
+ optionalParams = Object.assign({}, params, optionalParams); // set auth token to chat sdk before start chat
173
+
174
+ await handleAuthentication(chatSDK, chatConfig, getAuthToken);
175
+ await chatSDK.startChat(optionalParams);
176
+ isStartChatSuccessful = true;
102
177
  } catch (error) {
103
178
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
104
179
  Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
@@ -106,43 +181,52 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
106
181
  exception: `Failed to setup startChat: ${error}`
107
182
  }
108
183
  });
109
- }
184
+
185
+ isStartChatSuccessful = false; // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
186
+ // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
187
+
188
+ dispatch({
189
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
190
+ payload: _ConversationState.ConversationState.Closed
191
+ });
192
+ return;
193
+ } // New adapter creation
194
+
110
195
 
111
196
  const newAdapter = await (0, _createAdapter.createAdapter)(chatSDK);
112
197
  setAdapter(newAdapter);
113
198
  const chatToken = await chatSDK.getChatToken();
199
+ dispatch({
200
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
201
+ payload: chatToken
202
+ });
114
203
  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));
115
204
 
116
- if (!persistedState) {
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- if (chatSDK !== null && chatSDK !== void 0 && chatSDK.getVoiceVideoCalling) {
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- const chatToken = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatToken());
121
- dispatch({
122
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
123
- payload: chatToken
124
- });
125
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
-
127
-
128
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
205
+ if (persistedState) {
129
206
  dispatch({
130
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
131
- payload: liveChatContext
207
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
208
+ payload: persistedState
132
209
  });
133
- await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
134
- await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
210
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
211
+ return;
212
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+
214
+
215
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
216
+ dispatch({
217
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
218
+ payload: liveChatContext
219
+ }); // Set post chat context in state, no survey load
220
+
221
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // Updating chat session detail for telemetry
135
222
 
223
+ await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch); // Set app state to Active
224
+
225
+ if (isStartChatSuccessful) {
136
226
  dispatch({
137
227
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
138
228
  payload: _ConversationState.ConversationState.Active
139
229
  });
140
- } else {
141
- dispatch({
142
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
143
- payload: persistedState
144
- });
145
- await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
146
230
  }
147
231
 
148
232
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -171,6 +255,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
171
255
  payload: _ConversationState.ConversationState.OutOfOffice
172
256
  });
173
257
  }
258
+ } finally {
259
+ optionalParams = {};
174
260
  }
175
261
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
262
 
@@ -178,24 +264,44 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, params, persistedSta
178
264
  exports.initStartChat = initStartChat;
179
265
 
180
266
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
181
- var _DataStoreManager$cli, _persistedState$domai;
267
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _persistedState$domai6, _persistedState$appSt;
268
+
269
+ // By pass this function in case of popout chat
270
+ if (state.appStates.skipChatButtonRendering === true) {
271
+ return false;
272
+ }
182
273
 
183
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(_Constants.Constants.widgetStateDataKey, "localStorage");
184
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
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); //Connect to only active chat session
185
275
 
186
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
187
- var _persistedState$domai2;
276
+ 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) {
277
+ var _persistedState$domai7;
188
278
 
189
279
  dispatch({
190
280
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
191
281
  payload: _ConversationState.ConversationState.Loading
192
282
  });
193
283
  const optionalParams = {
194
- liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai2 = persistedState.domainStates) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.liveChatContext
284
+ liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
195
285
  };
196
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
286
+ await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
197
287
  return true;
198
288
  } else {
199
289
  return false;
200
290
  }
291
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
+
293
+
294
+ const setCustomContextParams = (props, chatSDK) => {
295
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$chatConfig, _persistedState$domai8;
296
+
297
+ // Add custom context only for unauthenticated chat
298
+ 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);
299
+
300
+ 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)) {
301
+ var _persistedState$domai9;
302
+
303
+ optionalParams = Object.assign({}, optionalParams, {
304
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
305
+ });
306
+ }
201
307
  };