@microsoft/omnichannel-chat-widget 0.1.0-main.ae3aa42 → 0.1.0-main.b511ad6

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