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