@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
@@ -17,15 +17,15 @@ var _utils = require("../../../common/utils");
17
17
  var _authHelper = require("./authHelper");
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
19
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
20
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
21
- 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;
22
- 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;
20
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
21
+ 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);
22
+ 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);
23
23
 
24
24
  //Unable to end chat if token has expired
25
25
  if (props.getAuthToken) {
26
26
  const authClientFunction = (0, _authHelper.getAuthClientFunction)(props.chatConfig);
27
27
  if (props.getAuthToken && authClientFunction) {
28
- // set auth token to chat sdk before start chat
28
+ // set auth token to chat sdk before end chat
29
29
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, props.chatConfig, props.getAuthToken);
30
30
  if (!authSuccess) {
31
31
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
@@ -61,15 +61,20 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
61
61
  chatSDK.requestId = chatSession.requestId;
62
62
  }
63
63
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
64
- dispatch({
65
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
66
- payload: _ConversationState.ConversationState.PostchatLoading
67
- });
68
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
69
- const loadPostChatEvent = {
70
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
71
- };
72
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
64
+ // Only start embedded Postchat workflow if postchat context is set successfully else close chat
65
+ if (state.domainStates.postChatContext) {
66
+ dispatch({
67
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
68
+ payload: _ConversationState.ConversationState.PostchatLoading
69
+ });
70
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
71
+ const loadPostChatEvent = {
72
+ eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
73
+ };
74
+ _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
75
+ } else {
76
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, true, false, true);
77
+ }
73
78
  } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
74
79
  var _props$webChatContain, _props$webChatContain2;
75
80
  dispatch({
@@ -156,10 +161,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
156
161
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
157
162
  payload: null
158
163
  });
159
- dispatch({
160
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
161
- payload: 0
162
- });
163
164
  dispatch({
164
165
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
165
166
  payload: {
@@ -182,6 +183,11 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
182
183
  exception: `Failed to endChat: ${error}`
183
184
  }
184
185
  });
186
+ } finally {
187
+ dispatch({
188
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
189
+ payload: 0
190
+ });
185
191
  }
186
192
  }
187
193
  };
@@ -39,7 +39,7 @@ var _Constants = require("../../../common/Constants");
39
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
41
  const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
42
- 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;
42
+ 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;
43
43
  const localizedTexts = {
44
44
  ..._defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts,
45
45
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -47,8 +47,8 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
47
47
  const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
48
48
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
49
  const markdown = (0, _createMarkdown.createMarkdown)(((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.disableMarkdownMessageFormatting) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
50
- 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;
51
- 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;
50
+ 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);
51
+ 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);
52
52
 
53
53
  // Initialize Web Chat's redux store
54
54
  let webChatStore = _WebChatStoreLoader.WebChatStoreLoader.store;
@@ -70,16 +70,28 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
70
70
  }
71
71
  if (isPostChatEnabled === "true") {
72
72
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
73
- _WebChatStoreLoader.WebChatStoreLoader.store = null;
74
- dispatch({
75
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
76
- payload: _ConversationState.ConversationState.PostchatLoading
77
- });
78
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
79
- const loadPostChatEvent = {
80
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
81
- };
82
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
73
+ // Only start embedded Postchat workflow if postchat context is set successfully else close chat
74
+ if (state.domainStates.postChatContext) {
75
+ _WebChatStoreLoader.WebChatStoreLoader.store = null;
76
+ dispatch({
77
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
78
+ payload: _ConversationState.ConversationState.PostchatLoading
79
+ });
80
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
81
+ const loadPostChatEvent = {
82
+ eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
83
+ };
84
+ _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
85
+ } else {
86
+ dispatch({
87
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
88
+ payload: _ConversationState.ConversationState.InActive
89
+ });
90
+ dispatch({
91
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
92
+ payload: true
93
+ });
94
+ }
83
95
  } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
84
96
  dispatch({
85
97
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -128,6 +140,7 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
128
140
  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.defaultWebChatContainerStatefulProps.webChatProps) === null || _defaultWebChatContai3 === void 0 ? void 0 : _defaultWebChatContai3.typingIndicatorMiddleware,
129
141
  onTelemetry: (0, _WebChatLogger.createWebChatTelemetry)(),
130
142
  cardActionMiddleware: (0, _cardActionMiddleware.createCardActionMiddleware)(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
143
+ sendTypingIndicator: true,
131
144
  ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
132
145
  };
133
146
  return webChatProps;
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isReconnectEnabled = exports.handleChatReconnect = exports.getChatReconnectContext = void 0;
7
7
  require("regenerator-runtime/runtime");
8
8
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
+ var _authHelper = require("./authHelper");
10
+ var _utils = require("../../../common/utils");
9
11
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
10
12
  var _ConversationState = require("../../../contexts/common/ConversationState");
11
13
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
12
14
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
13
- var _authHelper = require("./authHelper");
14
- var _utils = require("../../../common/utils");
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
17
17
  var _props$chatConfig, _props$chatConfig$Liv;
@@ -60,14 +60,14 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
60
60
  const chatReconnectOptionalParams = {
61
61
  reconnectId: (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId
62
62
  };
63
+ // Get auth token for getting chat reconnect context
63
64
  if (isAuthenticatedChat) {
64
- // Get auth token for for getting chat reconnect context
65
65
  await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, props.getAuthToken);
66
66
  }
67
67
  const reconnectChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getChatReconnectContext(chatReconnectOptionalParams));
68
68
  if (isAuthenticatedChat) {
69
69
  // remove auth token after reconnectId is fetched
70
- // this will be reset later at start chat
70
+ // AuthToken will be reset later at start chat
71
71
  (0, _authHelper.removeAuthTokenProvider)(chatSDK);
72
72
  }
73
73
  return reconnectChatContext;
@@ -101,7 +101,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, d
101
101
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
102
102
  payload: _ConversationState.ConversationState.Loading
103
103
  });
104
- await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
104
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
105
105
  };
106
106
  const redirectPage = (redirectURL, redirectInSameWindow) => {
107
107
  const redirectPageRequest = {
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.setPreChatAndInitiateChat = exports.prepareStartChat = exports.initStartChat = exports.checkIfConversationStillValid = void 0;
7
- var _Constants = require("../../../common/Constants");
8
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
+ var _Constants = require("../../../common/Constants");
9
+ var _utils = require("../../../common/utils");
10
+ var _authHelper = require("./authHelper");
11
+ var _ActivityStreamHandler = require("./ActivityStreamHandler");
12
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
9
13
  var _ConversationState = require("../../../contexts/common/ConversationState");
10
14
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
11
15
  var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
@@ -14,13 +18,9 @@ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
14
18
  var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
15
19
  var _createAdapter = require("./createAdapter");
16
20
  var _newMessageEventHandler = require("../../../plugins/newMessageEventHandler");
17
- var _utils = require("../../../common/utils");
21
+ var _reconnectChatHelper = require("./reconnectChatHelper");
18
22
  var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
19
23
  var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
20
- var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
21
- var _ActivityStreamHandler = require("./ActivityStreamHandler");
22
- var _authHelper = require("./authHelper");
23
- var _reconnectChatHelper = require("./reconnectChatHelper");
24
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
25
  let optionalParams = {};
26
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -84,12 +84,20 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
84
84
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
85
85
  payload: _ConversationState.ConversationState.Loading
86
86
  });
87
- await initStartChat(chatSDK, props === null || props === void 0 ? void 0 : props.chatConfig, props === null || props === void 0 ? void 0 : props.getAuthToken, dispatch, setAdapter);
87
+ const optionalParams = {
88
+ isProactiveChat
89
+ };
90
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
88
91
  };
89
92
 
90
93
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
94
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
92
- const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAdapter, params, persistedState) => {
95
+ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
96
+ var _props$controlProps2;
97
+ let isStartChatSuccessful = false;
98
+ const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
99
+ const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
100
+ const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
93
101
  try {
94
102
  var _newAdapter$activity$, _TelemetryTimers$Widg;
95
103
  //Start widget load timer
@@ -103,10 +111,13 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
103
111
  // set auth token to chat sdk before start chat
104
112
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
105
113
  if (!authSuccess) {
114
+ dispatch({
115
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
116
+ payload: _ConversationState.ConversationState.Closed
117
+ });
106
118
  return;
107
119
  }
108
120
  }
109
- let isStartChatSuccessful = false;
110
121
 
111
122
  //Check if chat retrieved from cache
112
123
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -120,10 +131,16 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
120
131
  });
121
132
  }
122
133
  try {
134
+ var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
123
135
  // Set custom context params
124
136
  setCustomContextParams(chatSDK);
125
- optionalParams = Object.assign({}, params, optionalParams);
126
- await chatSDK.startChat(optionalParams);
137
+ const defaultOptionalParams = {
138
+ sendDefaultInitContext: true,
139
+ isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
140
+ 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
141
+ };
142
+ const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
143
+ await chatSDK.startChat(startChatOptionalParams);
127
144
  isStartChatSuccessful = true;
128
145
  } catch (error) {
129
146
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
@@ -133,12 +150,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
133
150
  }
134
151
  });
135
152
  isStartChatSuccessful = false;
136
- // Resetting the widget state to Closed, for recent introduction of OC rate limiting(429 Error)
137
- // TODO : How to diplay a proper UI message to customer to try after sometime at this point - cool down scenario
138
- dispatch({
139
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
140
- payload: _ConversationState.ConversationState.Closed
141
- });
142
153
  return;
143
154
  }
144
155
 
@@ -167,12 +178,6 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
167
178
  payload: liveChatContext
168
179
  });
169
180
 
170
- // Set post chat context in state, no survey load
171
- (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
172
-
173
- // Updating chat session detail for telemetry
174
- await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
175
-
176
181
  // Set app state to Active
177
182
  if (isStartChatSuccessful) {
178
183
  _ActivityStreamHandler.ActivityStreamHandler.uncork();
@@ -191,6 +196,12 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
191
196
  Description: "Widget load complete",
192
197
  ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
193
198
  });
199
+
200
+ // Set post chat context in state, no survey load
201
+ (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
202
+
203
+ // Updating chat session detail for telemetry
204
+ await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
194
205
  } catch (ex) {
195
206
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
196
207
  Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
@@ -211,16 +222,28 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
211
222
  });
212
223
  return;
213
224
  }
214
- // Set app state to failing start chat
215
- dispatch({
216
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
217
- payload: true
218
- });
225
+ if (!hideErrorUIPane) {
226
+ // Set app state to failing start chat if hideErrorUI is not turned on
227
+ dispatch({
228
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
229
+ payload: true
230
+ });
231
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
232
+ Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
233
+ Description: "Error UI Pane Loaded"
234
+ });
235
+ }
219
236
  // Show the loading pane in other cases for failure, this will help for both hideStartChatButton case
220
237
  dispatch({
221
238
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
222
239
  payload: _ConversationState.ConversationState.Loading
223
240
  });
241
+
242
+ // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
243
+ // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
244
+ if (isStartChatSuccessful === true) {
245
+ await forceEndChat(chatSDK);
246
+ }
224
247
  } finally {
225
248
  optionalParams = {};
226
249
  widgetInstanceId = "";
@@ -229,16 +252,27 @@ const initStartChat = async (chatSDK, chatConfig, getAuthToken, dispatch, setAda
229
252
 
230
253
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
254
  exports.initStartChat = initStartChat;
255
+ const forceEndChat = async chatSDK => {
256
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
257
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
258
+ ExceptionDetails: {
259
+ Exception: "SessionInit was successful, but widget load failed."
260
+ }
261
+ });
262
+ chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
263
+ };
264
+
265
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
266
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
233
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps2, _persistedState$domai6, _persistedState$appSt;
267
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
234
268
  // By pass this function in case of popout chat
235
269
  if (state.appStates.hideStartChatButton === true) {
236
270
  return false;
237
271
  }
238
- const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
272
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
239
273
 
240
274
  //Connect to only active chat session
241
- if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === _ConversationState.ConversationState.Active) {
275
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext)) {
242
276
  var _persistedState$domai7;
243
277
  dispatch({
244
278
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -247,7 +281,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
247
281
  const optionalParams = {
248
282
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
249
283
  };
250
- await initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
284
+ await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
251
285
  return true;
252
286
  } else {
253
287
  return false;
@@ -277,38 +311,11 @@ const setCustomContextParams = chatSDK => {
277
311
  }
278
312
  };
279
313
 
280
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
281
- const handleAuthenticationIfEnabled = async (chatSDK, props) => {
282
- //For auth chat
283
- if (props.getAuthToken) {
284
- const authClientFunction = (0, _authHelper.getAuthClientFunction)(props.chatConfig);
285
- if (authClientFunction) {
286
- // set auth token to chat sdk before start chat
287
- const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, props.chatConfig, props.getAuthToken);
288
- if (!authSuccess) {
289
- return false;
290
- }
291
- return true;
292
- }
293
- }
294
- return true;
295
- };
296
-
297
314
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
315
  const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
299
316
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
317
  let conversationDetails = undefined;
301
318
 
302
- // Show Loading screen during auth check and start chat calls
303
- dispatch({
304
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
305
- payload: _ConversationState.ConversationState.Loading
306
- });
307
- const authSucceed = await handleAuthenticationIfEnabled(chatSDK, props);
308
- if (!authSucceed) {
309
- return false;
310
- }
311
-
312
319
  //Preserve old requestId
313
320
  const oldRequestId = chatSDK.requestId;
314
321
  try {
@@ -319,6 +326,10 @@ const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch
319
326
  return false;
320
327
  }
321
328
  if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
329
+ dispatch({
330
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
331
+ payload: undefined
332
+ });
322
333
  chatSDK.requestId = oldRequestId;
323
334
  return false;
324
335
  }