@microsoft/omnichannel-chat-widget 0.1.0-main.15c1e2b → 0.1.0-main.18d1166

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 (69) hide show
  1. package/README.md +7 -34
  2. package/lib/cjs/common/Constants.js +3 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +31 -4
  4. package/lib/cjs/common/utils.js +23 -2
  5. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -18
  6. package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -4
  7. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +139 -0
  8. package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +36 -0
  9. package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
  10. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +5 -2
  11. package/lib/cjs/components/livechatwidget/common/endChat.js +43 -63
  12. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +11 -43
  13. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +3 -3
  14. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -2
  15. package/lib/cjs/components/livechatwidget/common/startChat.js +35 -50
  16. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +64 -27
  17. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
  18. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
  19. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
  20. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +7 -3
  21. package/lib/cjs/contexts/common/ConversationEndEntity.js +12 -0
  22. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +10 -7
  23. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +4 -1
  24. package/lib/cjs/contexts/createReducer.js +28 -2
  25. package/lib/cjs/hooks/useDebounce.js +28 -0
  26. package/lib/cjs/hooks/useWindowDimensions.js +30 -0
  27. package/lib/cjs/plugins/newMessageEventHandler.js +10 -0
  28. package/lib/esm/common/Constants.js +3 -0
  29. package/lib/esm/common/telemetry/TelemetryConstants.js +31 -4
  30. package/lib/esm/common/utils.js +20 -0
  31. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -18
  32. package/lib/esm/components/headerstateful/HeaderStateful.js +5 -4
  33. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +134 -0
  34. package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +30 -0
  35. package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
  36. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +5 -2
  37. package/lib/esm/components/livechatwidget/common/endChat.js +45 -65
  38. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +13 -45
  39. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +3 -3
  40. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +254 -3
  41. package/lib/esm/components/livechatwidget/common/startChat.js +35 -50
  42. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +64 -27
  43. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +8 -1
  44. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
  45. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +1 -1
  46. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +5 -3
  47. package/lib/esm/contexts/common/ConversationEndEntity.js +5 -0
  48. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +10 -7
  49. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +4 -1
  50. package/lib/esm/contexts/createReducer.js +28 -2
  51. package/lib/esm/hooks/useDebounce.js +22 -0
  52. package/lib/esm/hooks/useWindowDimensions.js +23 -0
  53. package/lib/esm/plugins/newMessageEventHandler.js +10 -0
  54. package/lib/types/common/Constants.d.ts +3 -0
  55. package/lib/types/common/telemetry/TelemetryConstants.d.ts +27 -6
  56. package/lib/types/common/utils.d.ts +1 -0
  57. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +0 -7
  58. package/lib/types/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.d.ts +9 -0
  59. package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +6 -0
  60. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
  61. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +6 -1
  62. package/lib/types/components/livechatwidget/common/startChat.d.ts +2 -3
  63. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  64. package/lib/types/contexts/common/ConversationEndEntity.d.ts +4 -0
  65. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +5 -1
  66. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +10 -7
  67. package/lib/types/hooks/useDebounce.d.ts +3 -0
  68. package/lib/types/hooks/useWindowDimensions.d.ts +4 -0
  69. package/package.json +3 -3
@@ -11,21 +11,17 @@ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidget
11
11
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
12
12
  var _WebChatStoreLoader = require("../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader");
13
13
  var _defaultWebChatContainerStatefulProps = require("../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps");
14
- var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
15
- var _Constants = require("../../../common/Constants");
16
14
  var _utils = require("../../../common/utils");
17
15
  var _authHelper = require("./authHelper");
16
+ var _setPostChatContextAndLoadSurvey = require("./setPostChatContextAndLoadSurvey");
17
+ var _ConversationEndEntity = require("../../../contexts/common/ConversationEndEntity");
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;
23
-
24
20
  //Unable to end chat if token has expired
25
21
  if (props.getAuthToken) {
26
22
  const authClientFunction = (0, _authHelper.getAuthClientFunction)(props.chatConfig);
27
23
  if (props.getAuthToken && authClientFunction) {
28
- // set auth token to chat sdk before start chat
24
+ // set auth token to chat sdk before end chat
29
25
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, props.chatConfig, props.getAuthToken);
30
26
  if (!authSuccess) {
31
27
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
@@ -37,60 +33,28 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
37
33
  }
38
34
  }
39
35
  }
40
-
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- let conversationDetails = undefined;
43
- try {
44
- conversationDetails = await chatSDK.getConversationDetails();
45
- } catch (erorr) {
46
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
47
- Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsException,
48
- ExceptionDetails: {
49
- exception: `Failed to get conversation details: ${erorr}`
50
- }
51
- });
52
- }
53
- if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
54
- const skipEndChatSDK = false;
55
- const skipCloseChat = true;
56
- const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
57
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, false);
58
- if (chatSession) {
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- chatSDK.chatToken = chatSession.chatToken ?? {};
61
- chatSDK.requestId = chatSession.requestId;
36
+ const isPostChatEnabled = (0, _setPostChatContextAndLoadSurvey.checkPostChatEnabled)(props, state);
37
+ if (isPostChatEnabled) {
38
+ try {
39
+ await (0, _setPostChatContextAndLoadSurvey.initiatePostChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
40
+ } catch (error) {
41
+ // Ending chat because something went wrong
42
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
62
43
  }
63
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
44
+ } else {
45
+ if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
64
46
  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);
73
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
74
- var _props$webChatContain, _props$webChatContain2;
47
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
48
+ payload: undefined
49
+ });
75
50
  dispatch({
76
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
77
- payload: _ConversationState.ConversationState.InActive
51
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
52
+ payload: undefined
78
53
  });
79
-
80
- // Disable SendBox
81
- if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- setWebChatStyles(styles => {
84
- return {
85
- ...styles,
86
- hideSendBox: true
87
- };
88
- });
89
- }
54
+ } else {
55
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
90
56
  }
91
- return;
92
57
  }
93
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
94
58
  };
95
59
 
96
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -112,7 +76,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
112
76
  postMessageToOtherTab = false;
113
77
  }
114
78
  }
115
-
116
79
  // Need to clear these states immediately when chat ended from OC.
117
80
  dispatch({
118
81
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
@@ -132,12 +95,12 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
132
95
  });
133
96
  if (!skipCloseChat) {
134
97
  try {
135
- var _props$webChatContain3;
98
+ var _props$webChatContain;
136
99
  adapter === null || adapter === void 0 ? void 0 : adapter.end();
137
100
  setAdapter(undefined);
138
101
  setWebChatStyles({
139
102
  ..._defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.webChatStyles,
140
- ...((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles)
103
+ ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
141
104
  });
142
105
  _WebChatStoreLoader.WebChatStoreLoader.store = null;
143
106
  dispatch({
@@ -145,9 +108,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
145
108
  payload: _ConversationState.ConversationState.Closed
146
109
  });
147
110
  dispatch({
148
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
111
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
149
112
  payload: false
150
113
  });
114
+ dispatch({
115
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
116
+ payload: false
117
+ });
118
+ dispatch({
119
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
120
+ payload: false
121
+ });
122
+ dispatch({
123
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
124
+ payload: undefined
125
+ });
151
126
  dispatch({
152
127
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_RECONNECT_ID,
153
128
  payload: undefined
@@ -156,10 +131,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
156
131
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
157
132
  payload: null
158
133
  });
159
- dispatch({
160
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
161
- payload: 0
162
- });
163
134
  dispatch({
164
135
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
165
136
  payload: {
@@ -175,6 +146,10 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
175
146
  eventName: endChatEventName
176
147
  });
177
148
  }
149
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
150
+ Event: _TelemetryConstants.TelemetryEvent.CloseChatCall,
151
+ Description: "Chat was closed succesfully"
152
+ });
178
153
  } catch (error) {
179
154
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
180
155
  Event: _TelemetryConstants.TelemetryEvent.CloseChatMethodException,
@@ -182,6 +157,11 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
182
157
  exception: `Failed to endChat: ${error}`
183
158
  }
184
159
  });
160
+ } finally {
161
+ dispatch({
162
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
163
+ payload: 0
164
+ });
185
165
  }
186
166
  }
187
167
  };
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.initWebChatComposer = void 0;
7
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
8
  var _botframeworkWebchat = require("botframework-webchat");
9
- var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
10
- var _ConversationState = require("../../../contexts/common/ConversationState");
11
9
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
12
- var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
13
10
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
14
11
  var _WebChatStoreLoader = require("../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader");
15
12
  var _attachmentProcessingMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware"));
@@ -35,11 +32,10 @@ var _preProcessingMiddleware = _interopRequireDefault(require("../../webchatcont
35
32
  var _sanitizationMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"));
36
33
  var _cardActionMiddleware = require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware");
37
34
  var _messageTimestampMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware"));
38
- var _Constants = require("../../../common/Constants");
39
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
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;
37
+ const initWebChatComposer = (props, chatSDK, setAdapter, state, dispatch, adapter, setWebChatStyles) => {
38
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l4, _state$domainStates$l5, _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
39
  const localizedTexts = {
44
40
  ..._defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts,
45
41
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -47,19 +43,12 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
47
43
  const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
48
44
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
45
  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;
52
-
53
46
  // Initialize Web Chat's redux store
54
47
  let webChatStore = _WebChatStoreLoader.WebChatStoreLoader.store;
55
48
  if (!webChatStore) {
56
- var _state$domainStates$l5, _state$domainStates$l6, _state$domainStates$l7, _props$webChatContain6;
49
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _props$webChatContain6;
57
50
  const conversationEndCallback = async () => {
58
51
  var _props$webChatContain4, _props$webChatContain5;
59
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
60
- Event: _TelemetryConstants.TelemetryEvent.ConversationEndedThreadEventReceived,
61
- Description: "Conversation is ended by agent side or by timeout."
62
- });
63
52
  if ((props === null || props === void 0 ? void 0 : (_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : (_props$webChatContain5 = _props$webChatContain4.renderingMiddlewareProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.hideSendboxOnConversationEnd) !== false) {
64
53
  setWebChatStyles(styles => {
65
54
  return {
@@ -68,40 +57,18 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
68
57
  };
69
58
  });
70
59
  }
71
- if (isPostChatEnabled === "true" && postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed && state.appStates.conversationState === _ConversationState.ConversationState.Active) {
72
- _WebChatStoreLoader.WebChatStoreLoader.store = null;
73
- dispatch({
74
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
75
- payload: _ConversationState.ConversationState.PostchatLoading
76
- });
77
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
78
- const loadPostChatEvent = {
79
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
80
- };
81
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
82
- }
83
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
84
- dispatch({
85
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
86
- payload: _ConversationState.ConversationState.InActive
87
- });
88
- dispatch({
89
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
90
- payload: true
91
- });
92
- }
93
60
  dispatch({
94
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
95
- payload: undefined
61
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
62
+ payload: true
96
63
  });
97
- dispatch({
98
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
99
- payload: undefined
64
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
65
+ Event: _TelemetryConstants.TelemetryEvent.ConversationEndedThreadEventReceived,
66
+ Description: "Conversation end by agent side or by timeout event received."
100
67
  });
101
68
  };
102
69
  webChatStore = (0, _botframeworkWebchat.createStore)({},
103
70
  //initial state
104
- _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.allowedFileExtensions, (_state$domainStates$l6 = state.domainStates.liveChatConfig) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.maxUploadFileSize, localizedTexts), _channelDataMiddleware.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : _state$domainStates$l7.DataMaskingInfo), _messageTimestampMiddleware.default, _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default,
71
+ _preProcessingMiddleware.default, _attachmentProcessingMiddleware.default, (0, _attachmentUploadValidatorMiddleware.default)((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), _channelDataMiddleware.default, (0, _conversationEndMiddleware.default)(conversationEndCallback), (0, _dataMaskingMiddleware.default)((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), _messageTimestampMiddleware.default, _gifUploadMiddleware.default, _htmlPlayerMiddleware.default, _htmlTextMiddleware.default, (0, _maxMessageSizeValidator.default)(localizedTexts), _sanitizationMiddleware.default,
105
72
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
73
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
107
74
  _WebChatStoreLoader.WebChatStoreLoader.store = webChatStore;
@@ -111,7 +78,7 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
111
78
  const webChatProps = {
112
79
  ..._defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.webChatProps,
113
80
  dir: state.domainStates.globalDir,
114
- locale: (0, _utils.changeLanguageCodeFormatForWebChat)((0, _omnichannelChatSdk.getLocaleStringFromId)((_state$domainStates$l8 = state.domainStates.liveChatConfig) === null || _state$domainStates$l8 === void 0 ? void 0 : (_state$domainStates$l9 = _state$domainStates$l8.ChatWidgetLanguage) === null || _state$domainStates$l9 === void 0 ? void 0 : _state$domainStates$l9.msdyn_localeid)),
81
+ locale: (0, _utils.changeLanguageCodeFormatForWebChat)((0, _omnichannelChatSdk.getLocaleStringFromId)((_state$domainStates$l4 = state.domainStates.liveChatConfig) === null || _state$domainStates$l4 === void 0 ? void 0 : (_state$domainStates$l5 = _state$domainStates$l4.ChatWidgetLanguage) === null || _state$domainStates$l5 === void 0 ? void 0 : _state$domainStates$l5.msdyn_localeid)),
115
82
  store: webChatStore,
116
83
  activityMiddleware: (_props$webChatContain7 = props.webChatContainerProps) !== null && _props$webChatContain7 !== void 0 && (_props$webChatContain8 = _props$webChatContain7.renderingMiddlewareProps) !== null && _props$webChatContain8 !== void 0 && _props$webChatContain8.disableActivityMiddleware ? undefined : (0, _activityMiddleware.createActivityMiddleware)((_state$domainStates$r = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r === void 0 ? void 0 : _state$domainStates$r.systemMessageStyleProps, (_state$domainStates$r2 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r2 === void 0 ? void 0 : _state$domainStates$r2.userMessageStyleProps),
117
84
  attachmentMiddleware: (_props$webChatContain9 = props.webChatContainerProps) !== null && _props$webChatContain9 !== void 0 && (_props$webChatContain10 = _props$webChatContain9.renderingMiddlewareProps) !== null && _props$webChatContain10 !== void 0 && _props$webChatContain10.disableAttachmentMiddleware ? undefined : (0, _attachmentMiddleware.default)(((_state$domainStates$r3 = state.domainStates.renderingMiddlewareProps) === null || _state$domainStates$r3 === void 0 ? void 0 : (_state$domainStates$r4 = _state$domainStates$r3.attachmentProps) === null || _state$domainStates$r4 === void 0 ? void 0 : _state$domainStates$r4.enableInlinePlaying) ?? _defaultAttachmentProps.defaultAttachmentProps.enableInlinePlaying),
@@ -122,6 +89,7 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
122
89
  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,
123
90
  onTelemetry: (0, _WebChatLogger.createWebChatTelemetry)(),
124
91
  cardActionMiddleware: (0, _cardActionMiddleware.createCardActionMiddleware)(((_props$webChatContain21 = props.webChatContainerProps) === null || _props$webChatContain21 === void 0 ? void 0 : _props$webChatContain21.botMagicCode) || undefined),
92
+ sendTypingIndicator: true,
125
93
  ...((_props$webChatContain22 = props.webChatContainerProps) === null || _props$webChatContain22 === void 0 ? void 0 : _props$webChatContain22.webChatProps)
126
94
  };
127
95
  return webChatProps;
@@ -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 = {
@@ -3,12 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setPostChatContextAndLoadSurvey = void 0;
6
+ exports.setPostChatContextAndLoadSurvey = exports.initiatePostChat = exports.checkPostChatEnabled = void 0;
7
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
8
  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 _endChat = require("./endChat");
14
+ var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
15
+ var _utils = require("../../../common/utils");
16
+ var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
17
+ var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
18
+ var _ConversationEndEntity = require("../../../contexts/common/ConversationEndEntity");
12
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
20
  const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
14
21
  try {
@@ -41,4 +48,249 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
41
48
  });
42
49
  });
43
50
  };
44
- exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
51
+
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
54
+ const checkPostChatEnabled = (props, state) => {
55
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
56
+ 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);
57
+ return isPostChatEnabled === _Constants.Constants.true;
58
+ };
59
+
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ exports.checkPostChatEnabled = checkPostChatEnabled;
62
+ const initiatePostChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
63
+ // Check if Postchat already in progress and handle case where chat is ended by customer
64
+ if (state.appStates.postChatWorkflowInProgress && state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
65
+ await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
66
+ return;
67
+ }
68
+
69
+ // Conversation Details call required by customer as well as agent
70
+ const conversationDetails = await getConversationDetailsCall(chatSDK);
71
+ // Start Postchat workflow
72
+ dispatch({
73
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
74
+ payload: true
75
+ });
76
+
77
+ // Below logic checks if agent or bot or noone joins conversation and handles them separately
78
+ if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.userParticipantTypeTag) {
79
+ if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
80
+ // Set use bot settings to false
81
+ await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
82
+ } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
83
+ await postChatInitiatedByAgent(props, setWebChatStyles, dispatch, state);
84
+ } else {
85
+ const error = `Conversation was Ended after agent joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
86
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
87
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
88
+ ExceptionDetails: {
89
+ exception: error
90
+ }
91
+ });
92
+ throw new Error(error);
93
+ }
94
+ } else if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.botParticipantTypeTag) {
95
+ // Set Use bot survey to true
96
+ dispatch({
97
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
98
+ payload: true
99
+ });
100
+ if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
101
+ // Set use bot settings to true
102
+ await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, true);
103
+ } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
104
+ await postChatInitiatedByBot(props, setWebChatStyles, dispatch, state);
105
+ } else {
106
+ const error = `Conversation was Ended after bot joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
107
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
108
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
109
+ ExceptionDetails: {
110
+ exception: error
111
+ }
112
+ });
113
+ throw new Error(error);
114
+ }
115
+ } else {
116
+ if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
117
+ // No one has joined chat will be handled by postChat customer
118
+ await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
119
+ } else {
120
+ const error = `ConversationDetails and App state was not set correctly: conversationDetails = ${JSON.stringify(conversationDetails)} , conversationEndedBy = ${state.appStates.conversationEndedBy}`;
121
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
122
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
123
+ ExceptionDetails: {
124
+ exception: error
125
+ }
126
+ });
127
+ throw new Error(error);
128
+ }
129
+ }
130
+ };
131
+
132
+ // Function for link mode postchat workflow which is essentially same for both customer and agent
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ exports.initiatePostChat = initiatePostChat;
135
+ const linkModePostChatWorkflow = (props, dispatch, setWebChatStyles) => {
136
+ var _props$webChatContain, _props$webChatContain2;
137
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
138
+ Event: _TelemetryConstants.TelemetryEvent.LinkModePostChatWorkflowStarted
139
+ });
140
+ dispatch({
141
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
142
+ payload: _ConversationState.ConversationState.InActive
143
+ });
144
+
145
+ // Disable SendBox
146
+ if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
+ setWebChatStyles(styles => {
149
+ return {
150
+ ...styles,
151
+ hideSendBox: true
152
+ };
153
+ });
154
+ }
155
+ };
156
+
157
+ // Function for embed mode postchat workflow which is essentially same for both customer and agent
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ const embedModePostChatWorkflow = async (dispatch, state) => {
160
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
161
+ Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
162
+ });
163
+ if (state.domainStates.postChatContext) {
164
+ dispatch({
165
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
166
+ payload: _ConversationState.ConversationState.PostchatLoading
167
+ });
168
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
169
+ const loadPostChatEvent = {
170
+ eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
171
+ };
172
+ _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
173
+ } else {
174
+ const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
175
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
176
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
177
+ ExceptionDetails: {
178
+ exception: error
179
+ }
180
+ });
181
+ throw new Error(error);
182
+ }
183
+ };
184
+
185
+ // Function will handle only postchat cases initiated by customer
186
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
+ const postChatInitiatedByCustomer = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, shouldUseBotSetting) => {
188
+ let postChatSurveyMode = "";
189
+ if (shouldUseBotSetting) {
190
+ var _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4;
191
+ 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_postconversationsurveybotsurveymode) ?? ((_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_postconversationsurveybotsurveymode);
192
+ } else {
193
+ var _props$chatConfig3, _props$chatConfig3$Li, _state$domainStates$l5, _state$domainStates$l6;
194
+ postChatSurveyMode = ((_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : (_state$domainStates$l6 = _state$domainStates$l5.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.msdyn_postconversationsurveymode);
195
+ }
196
+ // Check if agent or bot has joined conversation
197
+ if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
198
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
199
+ Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromCustomer,
200
+ Description: shouldUseBotSetting ? "PostChat Workflow was started by customer using bot settings" : "PostChat Workflow was started by customer using agent settings"
201
+ });
202
+ const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
203
+ if (chatSession) {
204
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
205
+ chatSDK.chatToken = chatSession.chatToken ?? {};
206
+ chatSDK.requestId = chatSession.requestId;
207
+ }
208
+ // End chat call to end chatsdk but not close chat, only if chat ended by customer
209
+ await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
210
+ if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
211
+ await embedModePostChatWorkflow(dispatch, state);
212
+ } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
213
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
214
+ } else {
215
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
216
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
217
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
218
+ ExceptionDetails: {
219
+ exception: error
220
+ }
221
+ });
222
+ throw new Error(error);
223
+ }
224
+ } else {
225
+ // Agent did not join chat so end chat normally
226
+ await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
227
+ }
228
+ };
229
+
230
+ // Function will handle only postchat cases initiated by agent
231
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
+ const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
233
+ var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
234
+ const postChatSurveyMode = ((_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l7 = state.domainStates.liveChatConfig) === null || _state$domainStates$l7 === void 0 ? void 0 : (_state$domainStates$l8 = _state$domainStates$l7.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l8 === void 0 ? void 0 : _state$domainStates$l8.msdyn_postconversationsurveymode);
235
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
236
+ Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromAgent,
237
+ Description: "PostChat Workflow was started by agent"
238
+ });
239
+ if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
240
+ await embedModePostChatWorkflow(dispatch, state);
241
+ } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
242
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
243
+ } else {
244
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
245
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
246
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
247
+ ExceptionDetails: {
248
+ exception: error
249
+ }
250
+ });
251
+ throw new Error(error);
252
+ }
253
+ };
254
+
255
+ // Function will handle only postchat cases initiated by bot
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
257
+ const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
258
+ var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
259
+ const postChatSurveyMode = ((_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l9 = state.domainStates.liveChatConfig) === null || _state$domainStates$l9 === void 0 ? void 0 : (_state$domainStates$l10 = _state$domainStates$l9.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l10 === void 0 ? void 0 : _state$domainStates$l10.msdyn_postconversationsurveybotsurveymode);
260
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
261
+ Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromBot,
262
+ Description: "PostChat Workflow was started by bot"
263
+ });
264
+ if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
265
+ await embedModePostChatWorkflow(dispatch, state);
266
+ } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
267
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
268
+ } else {
269
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
270
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
271
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
272
+ ExceptionDetails: {
273
+ exception: error
274
+ }
275
+ });
276
+ throw new Error(error);
277
+ }
278
+ };
279
+
280
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
281
+ const getConversationDetailsCall = async chatSDK => {
282
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
+ let conversationDetails = undefined;
284
+ try {
285
+ conversationDetails = await chatSDK.getConversationDetails();
286
+ } catch (error) {
287
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
288
+ Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallFailed,
289
+ ExceptionDetails: {
290
+ exception: `Get Conversation Details Call Failed : ${error}`
291
+ }
292
+ });
293
+ _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
294
+ }
295
+ return conversationDetails;
296
+ };