@microsoft/omnichannel-chat-widget 0.1.0-main.243d300 → 0.1.0-main.2b2f787

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 (80) hide show
  1. package/README.md +7 -34
  2. package/lib/cjs/common/Constants.js +3 -1
  3. package/lib/cjs/common/storage/default/defaultCacheManager.js +2 -2
  4. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +15 -6
  5. package/lib/cjs/common/telemetry/TelemetryConstants.js +13 -0
  6. package/lib/cjs/common/telemetry/TelemetryHelper.js +2 -1
  7. package/lib/cjs/common/utils.js +23 -2
  8. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +1 -1
  9. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -2
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +139 -0
  12. package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
  13. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -10
  14. package/lib/cjs/components/livechatwidget/common/endChat.js +23 -17
  15. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +26 -13
  16. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +5 -5
  17. package/lib/cjs/components/livechatwidget/common/startChat.js +70 -59
  18. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -37
  19. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
  20. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
  21. package/lib/cjs/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
  22. package/lib/cjs/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +1 -0
  23. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
  24. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  25. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
  26. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +7 -4
  30. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
  31. package/lib/cjs/hooks/useDebounce.js +28 -0
  32. package/lib/cjs/hooks/useWindowDimensions.js +30 -0
  33. package/lib/cjs/plugins/newMessageEventHandler.js +14 -0
  34. package/lib/esm/common/Constants.js +3 -1
  35. package/lib/esm/common/storage/default/defaultCacheManager.js +2 -2
  36. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +15 -6
  37. package/lib/esm/common/telemetry/TelemetryConstants.js +13 -0
  38. package/lib/esm/common/telemetry/TelemetryHelper.js +2 -1
  39. package/lib/esm/common/utils.js +20 -0
  40. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +1 -1
  41. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +1 -1
  42. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -2
  43. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +134 -0
  44. package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
  45. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +14 -10
  46. package/lib/esm/components/livechatwidget/common/endChat.js +23 -17
  47. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +26 -13
  48. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +6 -5
  49. package/lib/esm/components/livechatwidget/common/startChat.js +70 -59
  50. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +44 -38
  51. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
  52. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
  53. package/lib/esm/components/prechatsurveypanestateful/common/defaultStyles/defaultGeneralPreChatSurveyPaneStyleProps.js +1 -1
  54. package/lib/esm/components/webchatcontainerstateful/common/utils/FileAttachmentIconManager.js +1 -0
  55. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +1 -3
  56. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +2 -1
  57. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageBoxStyles.js +1 -1
  58. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultUserMessageBoxStyles.js +1 -1
  59. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -14
  60. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -11
  61. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +5 -5
  62. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
  63. package/lib/esm/hooks/useDebounce.js +22 -0
  64. package/lib/esm/hooks/useWindowDimensions.js +23 -0
  65. package/lib/esm/plugins/newMessageEventHandler.js +14 -0
  66. package/lib/types/common/Constants.d.ts +2 -0
  67. package/lib/types/common/storage/default/defaultCacheManager.d.ts +1 -1
  68. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +1 -1
  69. package/lib/types/common/telemetry/TelemetryConstants.d.ts +14 -1
  70. package/lib/types/common/telemetry/definitions/Contracts.d.ts +2 -0
  71. package/lib/types/common/telemetry/definitions/Payload.d.ts +1 -0
  72. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +4 -0
  73. package/lib/types/common/utils.d.ts +1 -0
  74. package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +9 -0
  75. package/lib/types/components/livechatwidget/common/startChat.d.ts +3 -3
  76. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +2 -0
  77. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.d.ts +1 -1
  78. package/lib/types/hooks/useDebounce.d.ts +3 -0
  79. package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
  80. package/package.json +3 -3
@@ -33,7 +33,7 @@ import { Constants } from "../../../common/Constants";
33
33
 
34
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
35
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
36
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
36
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
37
37
  const localizedTexts = {
38
38
  ...defaultMiddlewareLocalizedTexts,
39
39
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -41,8 +41,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
41
41
  const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
42
42
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
43
43
  const markdown = createMarkdown(((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.disableMarkdownMessageFormatting) ?? defaultWebChatContainerStatefulProps.disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
44
- const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
45
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
44
+ const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
45
+ const postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode);
46
46
 
47
47
  // Initialize Web Chat's redux store
48
48
  let webChatStore = WebChatStoreLoader.store;
@@ -64,16 +64,28 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
64
64
  }
65
65
  if (isPostChatEnabled === "true") {
66
66
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
67
- WebChatStoreLoader.store = null;
68
- dispatch({
69
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
70
- payload: ConversationState.PostchatLoading
71
- });
72
- await addDelayInMs(Constants.PostChatLoadingDurationInMs);
73
- const loadPostChatEvent = {
74
- eventName: BroadcastEvent.LoadPostChatSurvey
75
- };
76
- BroadcastService.postMessage(loadPostChatEvent);
67
+ // Only start embedded Postchat workflow if postchat context is set successfully else close chat
68
+ if (state.domainStates.postChatContext) {
69
+ WebChatStoreLoader.store = null;
70
+ dispatch({
71
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
+ payload: ConversationState.PostchatLoading
73
+ });
74
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
75
+ const loadPostChatEvent = {
76
+ eventName: BroadcastEvent.LoadPostChatSurvey
77
+ };
78
+ BroadcastService.postMessage(loadPostChatEvent);
79
+ } else {
80
+ dispatch({
81
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
82
+ payload: ConversationState.InActive
83
+ });
84
+ dispatch({
85
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
86
+ payload: true
87
+ });
88
+ }
77
89
  } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
78
90
  dispatch({
79
91
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -122,6 +134,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
122
134
  typingIndicatorMiddleware: (_props$webChatContain19 = props.webChatContainerProps) !== null && _props$webChatContain19 !== void 0 && (_props$webChatContain20 = _props$webChatContain19.renderingMiddlewareProps) !== null && _props$webChatContain20 !== void 0 && _props$webChatContain20.disableTypingIndicatorMiddleware ? undefined : (_defaultWebChatContai3 = defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
123
135
  onTelemetry: createWebChatTelemetry(),
124
136
  cardActionMiddleware: createCardActionMiddleware(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
137
+ sendTypingIndicator: true,
125
138
  ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
126
139
  };
127
140
  return webChatProps;
@@ -1,11 +1,12 @@
1
1
  import "regenerator-runtime/runtime";
2
2
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
+ import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
4
+ import { isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
3
5
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
6
  import { ConversationState } from "../../../contexts/common/ConversationState";
5
7
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
8
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
7
- import { handleAuthentication, removeAuthTokenProvider } from "./authHelper";
8
- import { isNullOrEmptyString, isNullOrUndefined } from "../../../common/utils";
9
+
9
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
11
  const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
11
12
  var _props$chatConfig, _props$chatConfig$Liv;
@@ -53,14 +54,14 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
53
54
  const chatReconnectOptionalParams = {
54
55
  reconnectId: (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId
55
56
  };
57
+ // Get auth token for getting chat reconnect context
56
58
  if (isAuthenticatedChat) {
57
- // Get auth token for for getting chat reconnect context
58
59
  await handleAuthentication(chatSDK, chatConfig, props.getAuthToken);
59
60
  }
60
61
  const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
61
62
  if (isAuthenticatedChat) {
62
63
  // remove auth token after reconnectId is fetched
63
- // this will be reset later at start chat
64
+ // AuthToken will be reset later at start chat
64
65
  removeAuthTokenProvider(chatSDK);
65
66
  }
66
67
  return reconnectChatContext;
@@ -93,7 +94,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, d
93
94
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
94
95
  payload: ConversationState.Loading
95
96
  });
96
- await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
97
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
97
98
  };
98
99
  const redirectPage = (redirectURL, redirectInSameWindow) => {
99
100
  const redirectPageRequest = {
@@ -1,5 +1,9 @@
1
- import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
2
1
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
+ import { ChatSDKError, LiveWorkItemState } from "../../../common/Constants";
3
+ import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
4
+ import { getAuthClientFunction, handleAuthentication } from "./authHelper";
5
+ import { ActivityStreamHandler } from "./ActivityStreamHandler";
6
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
3
7
  import { ConversationState } from "../../../contexts/common/ConversationState";
4
8
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
5
9
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
@@ -8,13 +12,9 @@ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
8
12
  import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
9
13
  import { createAdapter } from "./createAdapter";
10
14
  import { createOnNewAdapterActivityHandler } from "../../../plugins/newMessageEventHandler";
11
- import { createTimer, getStateFromCache, isUndefinedOrEmpty } from "../../../common/utils";
15
+ import { handleChatReconnect } from "./reconnectChatHelper";
12
16
  import { setPostChatContextAndLoadSurvey } from "./setPostChatContextAndLoadSurvey";
13
17
  import { updateSessionDataForTelemetry } from "./updateSessionDataForTelemetry";
14
- import { BroadcastService } from "@microsoft/omnichannel-chat-components";
15
- import { ActivityStreamHandler } from "./ActivityStreamHandler";
16
- import { getAuthClientFunction, handleAuthentication } from "./authHelper";
17
- import { handleChatReconnect } from "./reconnectChatHelper";
18
18
 
19
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
20
  let optionalParams = {};
@@ -78,11 +78,19 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
78
78
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
79
79
  payload: ConversationState.Loading
80
80
  });
81
- await initStartChat(chatSDK, props === null || props === void 0 ? void 0 : props.chatConfig, props === null || props === void 0 ? void 0 : props.getAuthToken, dispatch, setAdapter);
81
+ const optionalParams = {
82
+ isProactiveChat
83
+ };
84
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
82
85
  };
83
86
 
84
87
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
88
+ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
89
+ var _props$controlProps2;
90
+ let isStartChatSuccessful = false;
91
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
92
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
93
+ const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
86
94
  try {
87
95
  var _newAdapter$activity$, _TelemetryTimers$Widg;
88
96
  //Start widget load timer
@@ -96,10 +104,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
96
104
  // set auth token to chat sdk before start chat
97
105
  const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
98
106
  if (!authSuccess) {
107
+ dispatch({
108
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
109
+ payload: ConversationState.Closed
110
+ });
99
111
  return;
100
112
  }
101
113
  }
102
- let isStartChatSuccessful = false;
103
114
 
104
115
  //Check if chat retrieved from cache
105
116
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -113,10 +124,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
113
124
  });
114
125
  }
115
126
  try {
127
+ var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
116
128
  // Set custom context params
117
129
  setCustomContextParams(chatSDK);
118
- optionalParams = Object.assign({}, params, optionalParams);
119
- await chatSDK.startChat(optionalParams);
130
+ const defaultOptionalParams = {
131
+ sendDefaultInitContext: true,
132
+ isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
133
+ portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
134
+ };
135
+ const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
136
+ await chatSDK.startChat(startChatOptionalParams);
120
137
  isStartChatSuccessful = true;
121
138
  } catch (error) {
122
139
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
@@ -126,12 +143,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
126
143
  }
127
144
  });
128
145
  isStartChatSuccessful = false;
129
- // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
130
- // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
131
- dispatch({
132
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
133
- payload: ConversationState.Closed
134
- });
135
146
  return;
136
147
  }
137
148
 
@@ -160,12 +171,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
160
171
  payload: liveChatContext
161
172
  });
162
173
 
163
- // Set post chat context in state, no survey load
164
- setPostChatContextAndLoadSurvey(chatSDK, dispatch);
165
-
166
- // Updating chat session detail for telemetry
167
- await updateSessionDataForTelemetry(chatSDK, dispatch);
168
-
169
174
  // Set app state to Active
170
175
  if (isStartChatSuccessful) {
171
176
  ActivityStreamHandler.uncork();
@@ -184,6 +189,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
184
189
  Description: "Widget load complete",
185
190
  ElapsedTimeInMilliseconds: TelemetryTimers === null || TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
186
191
  });
192
+
193
+ // Set post chat context in state, no survey load
194
+ setPostChatContextAndLoadSurvey(chatSDK, dispatch);
195
+
196
+ // Updating chat session detail for telemetry
197
+ await updateSessionDataForTelemetry(chatSDK, dispatch);
187
198
  } catch (ex) {
188
199
  TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
189
200
  Event: TelemetryEvent.WidgetLoadFailed,
@@ -204,33 +215,56 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
204
215
  });
205
216
  return;
206
217
  }
207
- // Set app state to failing start chat
208
- dispatch({
209
- type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
210
- payload: true
211
- });
218
+ if (!hideErrorUIPane) {
219
+ // Set app state to failing start chat if hideErrorUI is not turned on
220
+ dispatch({
221
+ type: LiveChatWidgetActionType.SET_START_CHAT_FAILING,
222
+ payload: true
223
+ });
224
+ TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
225
+ Event: TelemetryEvent.ErrorUIPaneLoaded,
226
+ Description: "Error UI Pane Loaded"
227
+ });
228
+ }
212
229
  // Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
213
230
  dispatch({
214
231
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
215
232
  payload: ConversationState.Loading
216
233
  });
234
+
235
+ // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
236
+ // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
237
+ if (isStartChatSuccessful === true) {
238
+ await forceEndChat(chatSDK);
239
+ }
217
240
  } finally {
218
241
  optionalParams = {};
219
242
  widgetInstanceId = "";
220
243
  }
221
244
  };
222
245
 
246
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
+ const forceEndChat = async chatSDK => {
248
+ TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
249
+ Event: TelemetryEvent.WidgetLoadFailed,
250
+ ExceptionDetails: {
251
+ Exception: "SessionInit was successful, but widget load failed."
252
+ }
253
+ });
254
+ chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
255
+ };
256
+
223
257
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
224
258
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
225
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
259
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
226
260
  // By pass this function in case of popout chat
227
261
  if (state.appStates.hideStartChatButton === true) {
228
262
  return false;
229
263
  }
230
- const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
264
+ const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
231
265
 
232
266
  //Connect to only active chat session
233
- if (persistedState && !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.Active) {
267
+ if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext)) {
234
268
  var _persistedState$domai7;
235
269
  dispatch({
236
270
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -239,7 +273,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
239
273
  const optionalParams = {
240
274
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
241
275
  };
242
- await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
276
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
243
277
  return true;
244
278
  } else {
245
279
  return false;
@@ -269,38 +303,11 @@ const setCustomContextParams = chatSDK => {
269
303
  }
270
304
  };
271
305
 
272
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
273
- const handleAuthenticationIfEnabled = async (chatSDK, props) => {
274
- //For auth chat
275
- if (props.getAuthToken) {
276
- const authClientFunction = getAuthClientFunction(props.chatConfig);
277
- if (authClientFunction) {
278
- // set auth token to chat sdk before start chat
279
- const authSuccess = await handleAuthentication(chatSDK, props.chatConfig, props.getAuthToken);
280
- if (!authSuccess) {
281
- return false;
282
- }
283
- return true;
284
- }
285
- }
286
- return true;
287
- };
288
-
289
306
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
290
307
  const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
291
308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
309
  let conversationDetails = undefined;
293
310
 
294
- // Show Loading screen during auth check and start chat calls
295
- dispatch({
296
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
297
- payload: ConversationState.Loading
298
- });
299
- const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
300
- if (!authSucceed) {
301
- return false;
302
- }
303
-
304
311
  //Preserve old requestId
305
312
  const oldRequestId = chatSDK.requestId;
306
313
  try {
@@ -311,6 +318,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
311
318
  return false;
312
319
  }
313
320
  if (conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
321
+ dispatch({
322
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
323
+ payload: undefined
324
+ });
314
325
  chatSDK.requestId = oldRequestId;
315
326
  return false;
316
327
  }