@microsoft/omnichannel-chat-widget 1.7.2-main.f7a7d61 → 1.7.3-main.112d01b

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 (27) hide show
  1. package/lib/cjs/common/Constants.js +6 -2
  2. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +2 -0
  3. package/lib/cjs/components/livechatwidget/common/endChat.js +4 -0
  4. package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +23 -0
  5. package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +28 -0
  6. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +19 -15
  7. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +16 -12
  8. package/lib/cjs/components/livechatwidget/common/startChat.js +42 -28
  9. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +4 -0
  10. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -0
  11. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +11 -0
  12. package/lib/esm/common/Constants.js +4 -1
  13. package/lib/esm/components/livechatwidget/common/createMarkdown.js +2 -0
  14. package/lib/esm/components/livechatwidget/common/endChat.js +4 -0
  15. package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +16 -0
  16. package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +22 -0
  17. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +21 -16
  18. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +16 -12
  19. package/lib/esm/components/livechatwidget/common/startChat.js +42 -28
  20. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +4 -0
  21. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -0
  22. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +11 -0
  23. package/lib/types/common/Constants.d.ts +4 -0
  24. package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -0
  25. package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +1 -0
  26. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +7 -0
  27. package/package.json +3 -2
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WidgetLoadTelemetryMessage = exports.WidgetLoadCustomErrorString = exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.StartChatErrorPaneConstants = exports.Regex = exports.PrepareEndChatDescriptionConstants = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
6
+ exports.WidgetLoadTelemetryMessage = exports.WidgetLoadCustomErrorString = exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.StartChatErrorPaneConstants = exports.Regex = exports.PrepareEndChatDescriptionConstants = exports.PostChatSurveyTelemetryMessage = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
7
7
  var _class;
8
8
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
@@ -318,4 +318,8 @@ _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceived", "
318
318
  _defineProperty(PrepareEndChatDescriptionConstants, "EndChatReceivedFromOtherTabs", "Received EndChat BroadcastEvent from other tabs. Closing this chat.");
319
319
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseChatOnFailureOrPostChat", "Customer is trying to close chat widget on start chat failure or post chat pane.");
320
320
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseInactiveChat", "Chat was Inactive and customer is trying to close chat widget or refreshing the page.");
321
- _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
321
+ _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
322
+ class PostChatSurveyTelemetryMessage {}
323
+ exports.PostChatSurveyTelemetryMessage = PostChatSurveyTelemetryMessage;
324
+ _defineProperty(PostChatSurveyTelemetryMessage, "PostChatContextCallFailed", "Failed to get post chat context.");
325
+ _defineProperty(PostChatSurveyTelemetryMessage, "PostChatContextCallSucceed", "Postchat context call succeed.");
@@ -38,6 +38,8 @@ const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineMarkdown
38
38
  ]);
39
39
  }
40
40
 
41
+ markdown.disable(["strikethrough"]);
42
+
41
43
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
44
  markdown.use(_markdownItForInline.default, "url_new_win", "link_open", function (tokens, idx, env) {
43
45
  const targetAttrIndex = tokens[idx].attrIndex(_Constants.Constants.Target);
@@ -179,6 +179,10 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
179
179
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
180
180
  payload: 0
181
181
  });
182
+ dispatch({
183
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
184
+ payload: undefined
185
+ });
182
186
  // Always allow to close the chat for embedded mode irrespective of end chat errors
183
187
  closeChatWidget(dispatch, props, state);
184
188
  }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isPostChatSurveyEnabled = exports.isPersistentChatEnabled = void 0;
7
+ var _Constants = require("../../../common/Constants");
8
+ var _utils = require("../../../common/utils");
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const isPostChatSurveyEnabled = async chatSDK => {
11
+ var _chatConfig$LiveWSAnd;
12
+ const chatConfig = await chatSDK.getLiveChatConfig();
13
+ const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
14
+ return postChatEnabled === "true";
15
+ };
16
+ exports.isPostChatSurveyEnabled = isPostChatSurveyEnabled;
17
+ const isPersistentChatEnabled = async conversationMode => {
18
+ if ((0, _utils.isNullOrUndefined)(conversationMode)) {
19
+ return false;
20
+ }
21
+ return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString().toLowerCase()) === _Constants.ConversationMode.Persistent;
22
+ };
23
+ exports.isPersistentChatEnabled = isPersistentChatEnabled;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shouldSetPreChatIfPersistentChat = void 0;
7
+ var _liveChatConfigUtils = require("./liveChatConfigUtils");
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const shouldSetPreChatIfPersistentChat = async (chatSDK, conversationMode, showPreChat) => {
10
+ const persistentEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(conversationMode);
11
+ let skipPreChat = false;
12
+ if (persistentEnabled) {
13
+ const reconnectableChatsParams = {
14
+ authenticatedUserToken: chatSDK.authenticatedUserToken
15
+ };
16
+ try {
17
+ const reconnectableChatsResponse = await chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams);
18
+ if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
19
+ // Skip rendering prechat on existing persistent chat session
20
+ skipPreChat = true;
21
+ }
22
+ } catch {
23
+ // eslint-disable-line no-empty
24
+ }
25
+ }
26
+ return showPreChat && !skipPreChat;
27
+ };
28
+ exports.shouldSetPreChatIfPersistentChat = shouldSetPreChatIfPersistentChat;
@@ -11,6 +11,7 @@ var _utils = require("../../../common/utils");
11
11
  var _ConversationState = require("../../../contexts/common/ConversationState");
12
12
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
13
13
  var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
14
+ var _liveChatConfigUtils = require("./liveChatConfigUtils");
14
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
16
  let conversationDetails = undefined;
16
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -108,24 +109,27 @@ const isPostChatEnabled = (props, state) => {
108
109
  exports.checkPostChatEnabled = isPostChatEnabled;
109
110
  const getPostChatContext = async (chatSDK, state, dispatch) => {
110
111
  try {
111
- var _state$domainStates2;
112
- if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
113
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
- const context = await chatSDK.getPostChatSurveyContext();
115
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
116
- Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallSucceed,
117
- Description: "Postchat context call succeed."
118
- });
119
- dispatch({
120
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
121
- payload: context
122
- });
123
- return context;
112
+ const postChatEnabled = await (0, _liveChatConfigUtils.isPostChatSurveyEnabled)(chatSDK);
113
+ if (postChatEnabled) {
114
+ var _state$domainStates2;
115
+ if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ const context = await chatSDK.getPostChatSurveyContext();
118
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
119
+ Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallSucceed,
120
+ Description: _Constants.PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
121
+ });
122
+ dispatch({
123
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
124
+ payload: context
125
+ });
126
+ return context;
127
+ }
124
128
  }
125
129
  } catch (error) {
126
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
130
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
127
131
  Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallFailed,
128
- Description: "Failed to get post chat context."
132
+ Description: _Constants.PostChatSurveyTelemetryMessage.PostChatContextCallFailed
129
133
  });
130
134
  }
131
135
  };
@@ -9,20 +9,25 @@ 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 _liveChatConfigUtils = require("./liveChatConfigUtils");
12
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
15
  const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
14
16
  try {
15
- if (!persistedChat) {
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- const context = await chatSDK.getPostChatSurveyContext();
18
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
19
- Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallSucceed,
20
- Description: "Postchat context call succeed."
21
- });
22
- dispatch({
23
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
24
- payload: context
25
- });
17
+ const postChatEnabled = await (0, _liveChatConfigUtils.isPostChatSurveyEnabled)(chatSDK);
18
+ if (postChatEnabled) {
19
+ if (!persistedChat) {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const context = await chatSDK.getPostChatSurveyContext();
22
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
23
+ Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallSucceed,
24
+ Description: _Constants.PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
25
+ });
26
+ dispatch({
27
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
28
+ payload: context
29
+ });
30
+ }
26
31
  }
27
32
  } catch (ex) {
28
33
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
@@ -32,7 +37,6 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
32
37
  }
33
38
  });
34
39
  }
35
-
36
40
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
41
  _omnichannelChatComponents.BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
38
42
  dispatch({
@@ -21,6 +21,8 @@ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurve
21
21
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
22
22
  var _startChatErrorHandler = require("./startChatErrorHandler");
23
23
  var _endChat = require("./endChat");
24
+ var _liveChatConfigUtils = require("./liveChatConfigUtils");
25
+ var _persistentChatHelper = require("./persistentChatHelper");
24
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
27
  let optionalParams = {};
26
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -28,6 +30,20 @@ let widgetInstanceId;
28
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
31
  let popoutWidgetInstanceId;
30
32
 
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const setAuthenticationIfApplicable = async (props, chatSDK) => {
35
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
36
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
37
+ const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
38
+ if (getAuthToken && authClientFunction) {
39
+ // set auth token to chat sdk before start chat
40
+ const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
41
+ if (!authSuccess) {
42
+ throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
43
+ }
44
+ }
45
+ };
46
+
31
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
48
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
33
49
  optionalParams = {}; //Resetting to ensure no stale values
@@ -53,6 +69,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
53
69
  // Setting Proactive chat settings
54
70
  const isProactiveChat = state.appStates.conversationState === _ConversationState.ConversationState.ProactiveChat;
55
71
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
72
+ await setAuthenticationIfApplicable(props, chatSDK);
56
73
 
57
74
  //Setting PreChat and intiate chat
58
75
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
@@ -61,16 +78,17 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
61
78
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
79
  exports.prepareStartChat = prepareStartChat;
63
80
  const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
64
- var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps;
81
+ var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
65
82
  //Handle reconnect scenario
66
83
 
67
84
  // Getting prechat Survey Context
68
85
  const parseToJson = false;
69
86
  const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await chatSDK.getPreChatSurvey(parseToJson));
70
- const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
87
+ let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
88
+ showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(chatSDK, state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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_conversationmode, showPrechat);
71
89
  if (showPrechat) {
72
- var _state$domainStates, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3;
73
- const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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$l3 = _state$domainStates$l2.OutOfOperatingHours) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.toLowerCase()) === "true";
90
+ var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
91
+ const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toLowerCase()) === "true";
74
92
  if (isOutOfOperatingHours) {
75
93
  (state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
76
94
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
@@ -94,7 +112,7 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
94
112
 
95
113
  // If minimized, maximize the chat, if the state is missing, consider it as minimized
96
114
  if ((state === null || state === void 0 ? void 0 : state.appStates.isMinimized) == undefined || (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.isMinimized) === true) {
97
- var _state$domainStates2, _state$domainStates2$, _state$domainStates3, _state$domainStates3$;
115
+ var _state$domainStates3, _state$domainStates3$, _state$domainStates4, _state$domainStates4$;
98
116
  dispatch({
99
117
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
100
118
  payload: false
@@ -104,8 +122,8 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
104
122
  _omnichannelChatComponents.BroadcastService.postMessage({
105
123
  eventName: _TelemetryConstants.BroadcastEvent.MaximizeChat,
106
124
  payload: {
107
- height: state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.widgetSize) === null || _state$domainStates2$ === void 0 ? void 0 : _state$domainStates2$.height,
108
- width: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.width
125
+ height: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.height,
126
+ width: state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.widgetSize) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.width
109
127
  }
110
128
  });
111
129
  }
@@ -127,9 +145,9 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
127
145
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
146
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
129
147
  const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
148
+ var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
130
149
  let isStartChatSuccessful = false;
131
- const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
132
- const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
150
+ const persistentChatEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
133
151
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
134
152
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
135
153
  (0, _endChat.chatSDKStateCleanUp)(chatSDK);
@@ -148,14 +166,6 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
148
166
  Event: _TelemetryConstants.TelemetryEvent.WidgetLoadStarted,
149
167
  Description: "Widget loading started"
150
168
  });
151
- const authClientFunction = (0, _authHelper.getAuthClientFunction)(chatConfig);
152
- if (getAuthToken && authClientFunction) {
153
- // set auth token to chat sdk before start chat
154
- const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
155
- if (!authSuccess) {
156
- throw new Error(_Constants.WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
157
- }
158
- }
159
169
 
160
170
  //Check if chat retrieved from cache
161
171
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -227,10 +237,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
227
237
 
228
238
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
239
  const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
230
- dispatch({
231
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
232
- payload: liveChatContext
233
- });
240
+
241
+ // Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
242
+ if (!persistentChatEnabled) {
243
+ dispatch({
244
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
245
+ payload: liveChatContext
246
+ });
247
+ }
234
248
  (0, _startChatErrorHandler.logWidgetLoadComplete)();
235
249
  // Set post chat context in state
236
250
  // Commenting this for now as post chat context is fetched during end chat
@@ -274,17 +288,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
274
288
 
275
289
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
290
  const setCustomContextParams = async (state, props) => {
277
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates4, _persistedState$domai8;
291
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates6, _persistedState$domai8;
278
292
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
279
293
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
280
294
  //Should not set custom context for auth chat
281
295
  if (isAuthenticatedChat) {
282
296
  return;
283
297
  }
284
- if (state !== null && state !== void 0 && (_state$domainStates4 = state.domainStates) !== null && _state$domainStates4 !== void 0 && _state$domainStates4.customContext) {
285
- var _state$domainStates5;
298
+ if (state !== null && state !== void 0 && (_state$domainStates6 = state.domainStates) !== null && _state$domainStates6 !== void 0 && _state$domainStates6.customContext) {
299
+ var _state$domainStates7;
286
300
  optionalParams = Object.assign({}, optionalParams, {
287
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : _state$domainStates5.customContext))
301
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.customContext))
288
302
  });
289
303
  return;
290
304
  }
@@ -332,9 +346,9 @@ const canStartPopoutChat = async props => {
332
346
 
333
347
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
348
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
335
- var _state$domainStates6, _state$domainStates6$, _state$domainStates7;
336
- const requestIdFromCache = (_state$domainStates6 = state.domainStates) === null || _state$domainStates6 === void 0 ? void 0 : (_state$domainStates6$ = _state$domainStates6.liveChatContext) === null || _state$domainStates6$ === void 0 ? void 0 : _state$domainStates6$.requestId;
337
- const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.liveChatContext;
349
+ var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
350
+ const requestIdFromCache = (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : (_state$domainStates8$ = _state$domainStates8.liveChatContext) === null || _state$domainStates8$ === void 0 ? void 0 : _state$domainStates8$.requestId;
351
+ const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
338
352
 
339
353
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
340
354
  let conversationDetails = undefined;
@@ -58,6 +58,10 @@ const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSuccessfu
58
58
  case _omnichannelChatSdk.ChatSDKErrorName.UninitializedChatSDK:
59
59
  handleUninitializedChatSDK(ex);
60
60
  break;
61
+ // Handle the case indicating failure to retrieve an authenticated chat conversation
62
+ case _omnichannelChatSdk.ChatSDKErrorName.AuthenticatedChatConversationRetrievalFailure:
63
+ logWidgetLoadCompleteWithError(ex);
64
+ break;
61
65
  case _omnichannelChatSdk.ChatSDKErrorName.InvalidConversation:
62
66
  case _omnichannelChatSdk.ChatSDKErrorName.ClosedConversation:
63
67
  handleInvalidOrClosedConversation(dispatch, chatSDK, props, ex);
@@ -218,6 +218,9 @@ const WebChatContainerStateful = props => {
218
218
  .webchat__stacked-layout_container>div {
219
219
  background: ${(props === null || props === void 0 ? void 0 : (_props$webChatContain9 = props.webChatContainerProps) === null || _props$webChatContain9 === void 0 ? void 0 : (_props$webChatContain10 = _props$webChatContain9.containerStyles) === null || _props$webChatContain10 === void 0 ? void 0 : _props$webChatContain10.background) ?? ""}
220
220
  }
221
+ .webchat__toaster__expandText {
222
+ display: flex;
223
+ }
221
224
  `), /*#__PURE__*/_react2.default.createElement(_react.Stack, {
222
225
  styles: containerStyles,
223
226
  className: "webchat__stacked-layout_container"
@@ -63,5 +63,16 @@ class MockChatSDK {
63
63
  getVoiceVideoCalling() {
64
64
  return null;
65
65
  }
66
+ getLiveChatConfig() {
67
+ return {
68
+ LiveWSAndLiveChatEngJoin: {
69
+ msdyn_postconversationsurveyenable: "true",
70
+ msdyn_conversationmode: "192350000"
71
+ }
72
+ };
73
+ }
74
+ sendTypingEvent() {
75
+ return null;
76
+ }
66
77
  }
67
78
  exports.MockChatSDK = MockChatSDK;
@@ -286,4 +286,7 @@ _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceived", "
286
286
  _defineProperty(PrepareEndChatDescriptionConstants, "EndChatReceivedFromOtherTabs", "Received EndChat BroadcastEvent from other tabs. Closing this chat.");
287
287
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseChatOnFailureOrPostChat", "Customer is trying to close chat widget on start chat failure or post chat pane.");
288
288
  _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseInactiveChat", "Chat was Inactive and customer is trying to close chat widget or refreshing the page.");
289
- _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
289
+ _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
290
+ export class PostChatSurveyTelemetryMessage {}
291
+ _defineProperty(PostChatSurveyTelemetryMessage, "PostChatContextCallFailed", "Failed to get post chat context.");
292
+ _defineProperty(PostChatSurveyTelemetryMessage, "PostChatContextCallSucceed", "Postchat context call succeed.");
@@ -32,6 +32,8 @@ export const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineM
32
32
  ]);
33
33
  }
34
34
 
35
+ markdown.disable(["strikethrough"]);
36
+
35
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
38
  markdown.use(MarkdownItForInline, "url_new_win", "link_open", function (tokens, idx, env) {
37
39
  const targetAttrIndex = tokens[idx].attrIndex(Constants.Target);
@@ -173,6 +173,10 @@ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatSt
173
173
  type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
174
174
  payload: 0
175
175
  });
176
+ dispatch({
177
+ type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
178
+ payload: undefined
179
+ });
176
180
  // Always allow to close the chat for embedded mode irrespective of end chat errors
177
181
  closeChatWidget(dispatch, props, state);
178
182
  }
@@ -0,0 +1,16 @@
1
+ import { ConversationMode } from "../../../common/Constants";
2
+ import { isNullOrUndefined } from "../../../common/utils";
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ export const isPostChatSurveyEnabled = async chatSDK => {
6
+ var _chatConfig$LiveWSAnd;
7
+ const chatConfig = await chatSDK.getLiveChatConfig();
8
+ const postChatEnabled = (_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_postconversationsurveyenable.toString().toLowerCase();
9
+ return postChatEnabled === "true";
10
+ };
11
+ export const isPersistentChatEnabled = async conversationMode => {
12
+ if (isNullOrUndefined(conversationMode)) {
13
+ return false;
14
+ }
15
+ return (conversationMode === null || conversationMode === void 0 ? void 0 : conversationMode.toString().toLowerCase()) === ConversationMode.Persistent;
16
+ };
@@ -0,0 +1,22 @@
1
+ import { isPersistentChatEnabled } from "./liveChatConfigUtils";
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ export const shouldSetPreChatIfPersistentChat = async (chatSDK, conversationMode, showPreChat) => {
5
+ const persistentEnabled = await isPersistentChatEnabled(conversationMode);
6
+ let skipPreChat = false;
7
+ if (persistentEnabled) {
8
+ const reconnectableChatsParams = {
9
+ authenticatedUserToken: chatSDK.authenticatedUserToken
10
+ };
11
+ try {
12
+ const reconnectableChatsResponse = await chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams);
13
+ if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
14
+ // Skip rendering prechat on existing persistent chat session
15
+ skipPreChat = true;
16
+ }
17
+ } catch {
18
+ // eslint-disable-line no-empty
19
+ }
20
+ }
21
+ return showPreChat && !skipPreChat;
22
+ };
@@ -1,10 +1,12 @@
1
- import { Constants, ParticipantType } from "../../../common/Constants";
1
+ import { Constants, ParticipantType, PostChatSurveyTelemetryMessage } from "../../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
4
4
  import { addDelayInMs } from "../../../common/utils";
5
5
  import { ConversationState } from "../../../contexts/common/ConversationState";
6
6
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
7
7
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
8
+ import { isPostChatSurveyEnabled } from "./liveChatConfigUtils";
9
+
8
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
11
  let conversationDetails = undefined;
10
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -100,24 +102,27 @@ const isPostChatEnabled = (props, state) => {
100
102
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
103
  const getPostChatContext = async (chatSDK, state, dispatch) => {
102
104
  try {
103
- var _state$domainStates2;
104
- if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
- const context = await chatSDK.getPostChatSurveyContext();
107
- TelemetryHelper.logSDKEvent(LogLevel.INFO, {
108
- Event: TelemetryEvent.PostChatContextCallSucceed,
109
- Description: "Postchat context call succeed."
110
- });
111
- dispatch({
112
- type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
113
- payload: context
114
- });
115
- return context;
105
+ const postChatEnabled = await isPostChatSurveyEnabled(chatSDK);
106
+ if (postChatEnabled) {
107
+ var _state$domainStates2;
108
+ if ((state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.postChatContext) === undefined) {
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
+ const context = await chatSDK.getPostChatSurveyContext();
111
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
112
+ Event: TelemetryEvent.PostChatContextCallSucceed,
113
+ Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
114
+ });
115
+ dispatch({
116
+ type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
117
+ payload: context
118
+ });
119
+ return context;
120
+ }
116
121
  }
117
122
  } catch (error) {
118
- TelemetryHelper.logSDKEvent(LogLevel.INFO, {
123
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
119
124
  Event: TelemetryEvent.PostChatContextCallFailed,
120
- Description: "Failed to get post chat context."
125
+ Description: PostChatSurveyTelemetryMessage.PostChatContextCallFailed
121
126
  });
122
127
  }
123
128
  };
@@ -3,21 +3,26 @@ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
3
3
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
4
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
5
5
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
6
+ import { PostChatSurveyTelemetryMessage } from "../../../common/Constants";
7
+ import { isPostChatSurveyEnabled } from "./liveChatConfigUtils";
6
8
 
7
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
10
  export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
9
11
  try {
10
- if (!persistedChat) {
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- const context = await chatSDK.getPostChatSurveyContext();
13
- TelemetryHelper.logSDKEvent(LogLevel.INFO, {
14
- Event: TelemetryEvent.PostChatContextCallSucceed,
15
- Description: "Postchat context call succeed."
16
- });
17
- dispatch({
18
- type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
19
- payload: context
20
- });
12
+ const postChatEnabled = await isPostChatSurveyEnabled(chatSDK);
13
+ if (postChatEnabled) {
14
+ if (!persistedChat) {
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ const context = await chatSDK.getPostChatSurveyContext();
17
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
18
+ Event: TelemetryEvent.PostChatContextCallSucceed,
19
+ Description: PostChatSurveyTelemetryMessage.PostChatContextCallSucceed
20
+ });
21
+ dispatch({
22
+ type: LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
23
+ payload: context
24
+ });
25
+ }
21
26
  }
22
27
  } catch (ex) {
23
28
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
@@ -27,7 +32,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
27
32
  }
28
33
  });
29
34
  }
30
-
31
35
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
36
  BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
33
37
  dispatch({
@@ -15,6 +15,8 @@ import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurv
15
15
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
16
16
  import { logWidgetLoadComplete, handleStartChatError } from "./startChatErrorHandler";
17
17
  import { chatSDKStateCleanUp } from "./endChat";
18
+ import { isPersistentChatEnabled } from "./liveChatConfigUtils";
19
+ import { shouldSetPreChatIfPersistentChat } from "./persistentChatHelper";
18
20
 
19
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
22
  let optionalParams = {};
@@ -23,6 +25,20 @@ let widgetInstanceId;
23
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
26
  let popoutWidgetInstanceId;
25
27
 
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ const setAuthenticationIfApplicable = async (props, chatSDK) => {
30
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
31
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
32
+ const authClientFunction = getAuthClientFunction(chatConfig);
33
+ if (getAuthToken && authClientFunction) {
34
+ // set auth token to chat sdk before start chat
35
+ const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
36
+ if (!authSuccess) {
37
+ throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
38
+ }
39
+ }
40
+ };
41
+
26
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
43
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
28
44
  optionalParams = {}; //Resetting to ensure no stale values
@@ -48,6 +64,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
48
64
  // Setting Proactive chat settings
49
65
  const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
50
66
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
67
+ await setAuthenticationIfApplicable(props, chatSDK);
51
68
 
52
69
  //Setting PreChat and intiate chat
53
70
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
@@ -55,16 +72,17 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
55
72
 
56
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
74
  const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
58
- var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps;
75
+ var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
59
76
  //Handle reconnect scenario
60
77
 
61
78
  // Getting prechat Survey Context
62
79
  const parseToJson = false;
63
80
  const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await chatSDK.getPreChatSurvey(parseToJson));
64
- const showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
81
+ let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
82
+ showPrechat = await shouldSetPreChatIfPersistentChat(chatSDK, state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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_conversationmode, showPrechat);
65
83
  if (showPrechat) {
66
- var _state$domainStates, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3;
67
- const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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$l3 = _state$domainStates$l2.OutOfOperatingHours) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.toLowerCase()) === "true";
84
+ var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
85
+ const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toLowerCase()) === "true";
68
86
  if (isOutOfOperatingHours) {
69
87
  (state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
70
88
  type: LiveChatWidgetActionType.SET_MINIMIZED,
@@ -88,7 +106,7 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
88
106
 
89
107
  // If minimized, maximize the chat, if the state is missing, consider it as minimized
90
108
  if ((state === null || state === void 0 ? void 0 : state.appStates.isMinimized) == undefined || (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.isMinimized) === true) {
91
- var _state$domainStates2, _state$domainStates2$, _state$domainStates3, _state$domainStates3$;
109
+ var _state$domainStates3, _state$domainStates3$, _state$domainStates4, _state$domainStates4$;
92
110
  dispatch({
93
111
  type: LiveChatWidgetActionType.SET_MINIMIZED,
94
112
  payload: false
@@ -98,8 +116,8 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
98
116
  BroadcastService.postMessage({
99
117
  eventName: BroadcastEvent.MaximizeChat,
100
118
  payload: {
101
- height: state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.widgetSize) === null || _state$domainStates2$ === void 0 ? void 0 : _state$domainStates2$.height,
102
- width: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.width
119
+ height: state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.widgetSize) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.height,
120
+ width: state === null || state === void 0 ? void 0 : (_state$domainStates4 = state.domainStates) === null || _state$domainStates4 === void 0 ? void 0 : (_state$domainStates4$ = _state$domainStates4.widgetSize) === null || _state$domainStates4$ === void 0 ? void 0 : _state$domainStates4$.width
103
121
  }
104
122
  });
105
123
  }
@@ -120,9 +138,9 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
120
138
 
121
139
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
140
  const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
141
+ var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
123
142
  let isStartChatSuccessful = false;
124
- const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
125
- const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
143
+ const persistentChatEnabled = await isPersistentChatEnabled(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
126
144
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
127
145
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
128
146
  chatSDKStateCleanUp(chatSDK);
@@ -141,14 +159,6 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
141
159
  Event: TelemetryEvent.WidgetLoadStarted,
142
160
  Description: "Widget loading started"
143
161
  });
144
- const authClientFunction = getAuthClientFunction(chatConfig);
145
- if (getAuthToken && authClientFunction) {
146
- // set auth token to chat sdk before start chat
147
- const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
148
- if (!authSuccess) {
149
- throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
150
- }
151
- }
152
162
 
153
163
  //Check if chat retrieved from cache
154
164
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -220,10 +230,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
220
230
 
221
231
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
232
  const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
223
- dispatch({
224
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
225
- payload: liveChatContext
226
- });
233
+
234
+ // Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
235
+ if (!persistentChatEnabled) {
236
+ dispatch({
237
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
238
+ payload: liveChatContext
239
+ });
240
+ }
227
241
  logWidgetLoadComplete();
228
242
  // Set post chat context in state
229
243
  // Commenting this for now as post chat context is fetched during end chat
@@ -266,17 +280,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
266
280
 
267
281
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
268
282
  const setCustomContextParams = async (state, props) => {
269
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates4, _persistedState$domai8;
283
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates6, _persistedState$domai8;
270
284
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
285
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
272
286
  //Should not set custom context for auth chat
273
287
  if (isAuthenticatedChat) {
274
288
  return;
275
289
  }
276
- if (state !== null && state !== void 0 && (_state$domainStates4 = state.domainStates) !== null && _state$domainStates4 !== void 0 && _state$domainStates4.customContext) {
277
- var _state$domainStates5;
290
+ if (state !== null && state !== void 0 && (_state$domainStates6 = state.domainStates) !== null && _state$domainStates6 !== void 0 && _state$domainStates6.customContext) {
291
+ var _state$domainStates7;
278
292
  optionalParams = Object.assign({}, optionalParams, {
279
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : _state$domainStates5.customContext))
293
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.customContext))
280
294
  });
281
295
  return;
282
296
  }
@@ -324,9 +338,9 @@ const canStartPopoutChat = async props => {
324
338
 
325
339
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
326
340
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
327
- var _state$domainStates6, _state$domainStates6$, _state$domainStates7;
328
- const requestIdFromCache = (_state$domainStates6 = state.domainStates) === null || _state$domainStates6 === void 0 ? void 0 : (_state$domainStates6$ = _state$domainStates6.liveChatContext) === null || _state$domainStates6$ === void 0 ? void 0 : _state$domainStates6$.requestId;
329
- const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : _state$domainStates7.liveChatContext;
341
+ var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
342
+ const requestIdFromCache = (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : (_state$domainStates8$ = _state$domainStates8.liveChatContext) === null || _state$domainStates8$ === void 0 ? void 0 : _state$domainStates8$.requestId;
343
+ const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
330
344
 
331
345
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
346
  let conversationDetails = undefined;
@@ -53,6 +53,10 @@ export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSu
53
53
  case ChatSDKErrorName.UninitializedChatSDK:
54
54
  handleUninitializedChatSDK(ex);
55
55
  break;
56
+ // Handle the case indicating failure to retrieve an authenticated chat conversation
57
+ case ChatSDKErrorName.AuthenticatedChatConversationRetrievalFailure:
58
+ logWidgetLoadCompleteWithError(ex);
59
+ break;
56
60
  case ChatSDKErrorName.InvalidConversation:
57
61
  case ChatSDKErrorName.ClosedConversation:
58
62
  handleInvalidOrClosedConversation(dispatch, chatSDK, props, ex);
@@ -210,6 +210,9 @@ export const WebChatContainerStateful = props => {
210
210
  .webchat__stacked-layout_container>div {
211
211
  background: ${(props === null || props === void 0 ? void 0 : (_props$webChatContain9 = props.webChatContainerProps) === null || _props$webChatContain9 === void 0 ? void 0 : (_props$webChatContain10 = _props$webChatContain9.containerStyles) === null || _props$webChatContain10 === void 0 ? void 0 : _props$webChatContain10.background) ?? ""}
212
212
  }
213
+ .webchat__toaster__expandText {
214
+ display: flex;
215
+ }
213
216
  `), /*#__PURE__*/React.createElement(Stack, {
214
217
  styles: containerStyles,
215
218
  className: "webchat__stacked-layout_container"
@@ -56,4 +56,15 @@ export class MockChatSDK {
56
56
  getVoiceVideoCalling() {
57
57
  return null;
58
58
  }
59
+ getLiveChatConfig() {
60
+ return {
61
+ LiveWSAndLiveChatEngJoin: {
62
+ msdyn_postconversationsurveyenable: "true",
63
+ msdyn_conversationmode: "192350000"
64
+ }
65
+ };
66
+ }
67
+ sendTypingEvent() {
68
+ return null;
69
+ }
59
70
  }
@@ -267,3 +267,7 @@ export declare class PrepareEndChatDescriptionConstants {
267
267
  static readonly CustomerCloseInactiveChat = "Chat was Inactive and customer is trying to close chat widget or refreshing the page.";
268
268
  static readonly BrowserUnload = "Browser unload event received. Ending chat.";
269
269
  }
270
+ export declare class PostChatSurveyTelemetryMessage {
271
+ static readonly PostChatContextCallFailed = "Failed to get post chat context.";
272
+ static readonly PostChatContextCallSucceed = "Postchat context call succeed.";
273
+ }
@@ -0,0 +1,2 @@
1
+ export declare const isPostChatSurveyEnabled: (chatSDK: any) => Promise<boolean>;
2
+ export declare const isPersistentChatEnabled: (conversationMode: string | undefined) => Promise<boolean>;
@@ -0,0 +1 @@
1
+ export declare const shouldSetPreChatIfPersistentChat: (chatSDK: any, conversationMode: string, showPreChat: boolean) => Promise<boolean>;
@@ -28,4 +28,11 @@ export declare class MockChatSDK {
28
28
  reconnectId: string;
29
29
  };
30
30
  getVoiceVideoCalling(): null;
31
+ getLiveChatConfig(): {
32
+ LiveWSAndLiveChatEngJoin: {
33
+ msdyn_postconversationsurveyenable: string;
34
+ msdyn_conversationmode: string;
35
+ };
36
+ };
37
+ sendTypingEvent(): null;
31
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.7.2-main.f7a7d61",
3
+ "version": "1.7.3-main.112d01b",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@microsoft/omnichannel-chat-components": "1.1.5",
78
- "@microsoft/omnichannel-chat-sdk": "^1.9.1",
78
+ "@microsoft/omnichannel-chat-sdk": "^1.9.5",
79
79
  "abort-controller-es5": "^2.0.1",
80
80
  "dompurify": "^2.3.4",
81
81
  "markdown-it": "^12.3.2",
@@ -101,6 +101,7 @@
101
101
  "test:all": "yarn test:unit && yarn test:visual",
102
102
  "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
103
103
  "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
104
+ "build:umd": "webpack --config ./webpack.umd.config.cjs",
104
105
  "verify": "yarn install && yarn build-storybook && yarn test:all && yarn build && yarn storybook",
105
106
  "testpack": "yarn build && yarn pack",
106
107
  "build-sample": "yarn build && webpack --config ./webpack.config.cjs",