@microsoft/omnichannel-chat-widget 0.1.0-main.50fdaaa → 0.1.0-main.52fa2fc

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 (51) hide show
  1. package/lib/cjs/common/Constants.js +8 -1
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +22 -4
  3. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -18
  4. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
  5. package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +36 -0
  6. package/lib/cjs/components/livechatwidget/common/endChat.js +38 -64
  7. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +10 -61
  8. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +6 -2
  9. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -2
  10. package/lib/cjs/components/livechatwidget/common/startChat.js +14 -6
  11. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +65 -25
  12. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
  13. package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
  14. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +1 -0
  15. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
  16. package/lib/cjs/contexts/common/ConversationEndEntity.js +12 -0
  17. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +11 -7
  18. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +6 -2
  19. package/lib/cjs/contexts/createReducer.js +36 -2
  20. package/lib/esm/common/Constants.js +6 -0
  21. package/lib/esm/common/telemetry/TelemetryConstants.js +22 -4
  22. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -18
  23. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
  24. package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +30 -0
  25. package/lib/esm/components/livechatwidget/common/endChat.js +40 -66
  26. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +12 -63
  27. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +6 -2
  28. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +255 -3
  29. package/lib/esm/components/livechatwidget/common/startChat.js +14 -6
  30. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +65 -25
  31. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +3 -1
  32. package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +2 -0
  33. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +2 -0
  34. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.js +75 -11
  35. package/lib/esm/contexts/common/ConversationEndEntity.js +5 -0
  36. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +11 -7
  37. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +6 -2
  38. package/lib/esm/contexts/createReducer.js +36 -2
  39. package/lib/types/common/Constants.d.ts +7 -0
  40. package/lib/types/common/telemetry/TelemetryConstants.d.ts +18 -6
  41. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +0 -7
  42. package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +6 -0
  43. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
  44. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
  45. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +6 -1
  46. package/lib/types/components/livechatwidget/common/startChat.d.ts +1 -1
  47. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentUploadValidatorMiddleware.d.ts +1 -1
  48. package/lib/types/contexts/common/ConversationEndEntity.d.ts +4 -0
  49. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +6 -1
  50. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -7
  51. package/package.json +1 -1
@@ -1,21 +1,17 @@
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 _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
16
- 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);
17
- const postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode);
18
-
19
15
  //Unable to end chat if token has expired
20
16
  if (props.getAuthToken) {
21
17
  const authClientFunction = getAuthClientFunction(props.chatConfig);
@@ -32,65 +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) {
59
- // Only start embedded Postchat workflow if postchat context is set successfully else close chat
60
- if (state.domainStates.postChatContext) {
61
- dispatch({
62
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
63
- payload: ConversationState.PostchatLoading
64
- });
65
- await addDelayInMs(Constants.PostChatLoadingDurationInMs);
66
- const loadPostChatEvent = {
67
- eventName: BroadcastEvent.LoadPostChatSurvey
68
- };
69
- BroadcastService.postMessage(loadPostChatEvent);
70
- } else {
71
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, true, false, true);
72
- }
73
- } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
74
- var _props$webChatContain, _props$webChatContain2;
39
+ } else {
40
+ if (state.appStates.conversationEndedBy === ConversationEndEntity.Agent) {
75
41
  dispatch({
76
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
77
- payload: ConversationState.InActive
42
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
43
+ payload: undefined
78
44
  });
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
- }
45
+ dispatch({
46
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
47
+ payload: undefined
48
+ });
49
+ } else {
50
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
90
51
  }
91
- return;
92
52
  }
93
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
94
53
  };
95
54
 
96
55
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -111,7 +70,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
111
70
  postMessageToOtherTab = false;
112
71
  }
113
72
  }
114
-
115
73
  // Need to clear these states immediately when chat ended from OC.
116
74
  dispatch({
117
75
  type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
@@ -131,12 +89,12 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
131
89
  });
132
90
  if (!skipCloseChat) {
133
91
  try {
134
- var _props$webChatContain3;
92
+ var _props$webChatContain;
135
93
  adapter === null || adapter === void 0 ? void 0 : adapter.end();
136
94
  setAdapter(undefined);
137
95
  setWebChatStyles({
138
96
  ...defaultWebChatContainerStatefulProps.webChatStyles,
139
- ...((_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)
140
98
  });
141
99
  WebChatStoreLoader.store = null;
142
100
  dispatch({
@@ -144,9 +102,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
144
102
  payload: ConversationState.Closed
145
103
  });
146
104
  dispatch({
147
- type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
105
+ type: LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
148
106
  payload: false
149
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
+ });
150
120
  dispatch({
151
121
  type: LiveChatWidgetActionType.SET_RECONNECT_ID,
152
122
  payload: undefined
@@ -170,6 +140,10 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
170
140
  eventName: endChatEventName
171
141
  });
172
142
  }
143
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
144
+ Event: TelemetryEvent.CloseChatCall,
145
+ Description: "Chat was closed succesfully"
146
+ });
173
147
  } catch (error) {
174
148
  TelemetryHelper.logActionEvent(LogLevel.ERROR, {
175
149
  Event: TelemetryEvent.CloseChatMethodException,
@@ -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, _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
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 = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
45
- const postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode);
46
-
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,58 +51,18 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
62
51
  };
63
52
  });
64
53
  }
65
- if (isPostChatEnabled === "true") {
66
- if (postChatSurveyMode === PostChatSurveyMode.Embed) {
67
- // Only start embedded Postchat workflow if postchat context is set successfully else close chat
68
- if (state.domainStates.postChatContext) {
69
- WebChatStoreLoader.store = null;
70
- dispatch({
71
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
- payload: ConversationState.PostchatLoading
73
- });
74
- await addDelayInMs(Constants.PostChatLoadingDurationInMs);
75
- const loadPostChatEvent = {
76
- eventName: BroadcastEvent.LoadPostChatSurvey
77
- };
78
- BroadcastService.postMessage(loadPostChatEvent);
79
- } else {
80
- dispatch({
81
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
82
- payload: ConversationState.InActive
83
- });
84
- dispatch({
85
- type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
86
- payload: true
87
- });
88
- }
89
- } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
90
- dispatch({
91
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
92
- payload: ConversationState.InActive
93
- });
94
- }
95
- } else {
96
- dispatch({
97
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
98
- payload: ConversationState.InActive
99
- });
100
- dispatch({
101
- type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
102
- payload: true
103
- });
104
- }
105
54
  dispatch({
106
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
107
- payload: undefined
55
+ type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT_EVENT_RECEIVED,
56
+ payload: true
108
57
  });
109
- dispatch({
110
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
111
- payload: undefined
58
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
59
+ Event: TelemetryEvent.ConversationEndedThreadEventReceived,
60
+ Description: "Conversation end by agent side or by timeout event received."
112
61
  });
113
62
  };
114
63
  webChatStore = createStore({},
115
64
  //initial state
116
- 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,
117
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
67
  ...(((_props$webChatContain6 = props.webChatContainerProps) === null || _props$webChatContain6 === void 0 ? void 0 : _props$webChatContain6.storeMiddlewares) ?? []));
119
68
  WebChatStoreLoader.store = webChatStore;
@@ -123,7 +72,7 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
123
72
  const webChatProps = {
124
73
  ...defaultWebChatContainerStatefulProps.webChatProps,
125
74
  dir: state.domainStates.globalDir,
126
- 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)),
127
76
  store: webChatStore,
128
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),
129
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),
@@ -109,8 +109,12 @@ const redirectPage = (redirectURL, redirectInSameWindow) => {
109
109
  }
110
110
  };
111
111
  const isReconnectEnabled = chatConfig => {
112
- var _chatConfig$LiveWSAnd;
113
- return chatConfig && ((_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : _chatConfig$LiveWSAnd.msdyn_enablechatreconnect) && (chatConfig.LiveWSAndLiveChatEngJoin.msdyn_enablechatreconnect === "true" || chatConfig.LiveWSAndLiveChatEngJoin.msdyn_enablechatreconnect === true);
112
+ if (chatConfig) {
113
+ var _chatConfig$LiveWSAnd, _chatConfig$LiveWSAnd2;
114
+ const reconnectEnabled = ((_chatConfig$LiveWSAnd = chatConfig.LiveWSAndLiveChatEngJoin) === null || _chatConfig$LiveWSAnd === void 0 ? void 0 : (_chatConfig$LiveWSAnd2 = _chatConfig$LiveWSAnd.msdyn_enablechatreconnect) === null || _chatConfig$LiveWSAnd2 === void 0 ? void 0 : _chatConfig$LiveWSAnd2.toLowerCase()) === "true";
115
+ return reconnectEnabled;
116
+ }
117
+ return false;
114
118
  };
115
119
  const hasReconnectId = reconnectAvailabilityResponse => {
116
120
  return reconnectAvailabilityResponse && !isNullOrUndefined(reconnectAvailabilityResponse.reconnectId);
@@ -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,249 @@ 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
+ // End chat call to end chatsdk but not close chat, only if chat ended by customer
196
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
197
+ // Saving request Id below for chat transcript calls
198
+ if (chatSession) {
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ chatSDK.chatToken = chatSession.chatToken ?? {};
201
+ chatSDK.requestId = chatSession.requestId;
202
+ }
203
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
204
+ await embedModePostChatWorkflow(dispatch, state);
205
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
206
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
207
+ } else {
208
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
209
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
210
+ Event: TelemetryEvent.AppStatesException,
211
+ ExceptionDetails: {
212
+ exception: error
213
+ }
214
+ });
215
+ throw new Error(error);
216
+ }
217
+ } else {
218
+ // Agent did not join chat so end chat normally
219
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
220
+ }
221
+ };
222
+
223
+ // Function will handle only postchat cases initiated by agent
224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
225
+ const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
226
+ var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
227
+ 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);
228
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
229
+ Event: TelemetryEvent.PostChatWorkflowFromAgent,
230
+ Description: "PostChat Workflow was started by agent"
231
+ });
232
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
233
+ await embedModePostChatWorkflow(dispatch, state);
234
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
235
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
236
+ } else {
237
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
238
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
239
+ Event: TelemetryEvent.AppStatesException,
240
+ ExceptionDetails: {
241
+ exception: error
242
+ }
243
+ });
244
+ throw new Error(error);
245
+ }
246
+ };
247
+
248
+ // Function will handle only postchat cases initiated by bot
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
+ const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
251
+ var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
252
+ 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);
253
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
254
+ Event: TelemetryEvent.PostChatWorkflowFromBot,
255
+ Description: "PostChat Workflow was started by bot"
256
+ });
257
+ if (postChatSurveyMode === PostChatSurveyMode.Embed) {
258
+ await embedModePostChatWorkflow(dispatch, state);
259
+ } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
260
+ linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
261
+ } else {
262
+ const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
263
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
264
+ Event: TelemetryEvent.AppStatesException,
265
+ ExceptionDetails: {
266
+ exception: error
267
+ }
268
+ });
269
+ throw new Error(error);
270
+ }
271
+ };
272
+
273
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
+ const getConversationDetailsCall = async chatSDK => {
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ let conversationDetails = undefined;
277
+ try {
278
+ conversationDetails = await chatSDK.getConversationDetails();
279
+ } catch (error) {
280
+ TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
281
+ Event: TelemetryEvent.GetConversationDetailsCallFailed,
282
+ ExceptionDetails: {
283
+ exception: `Get Conversation Details Call Failed : ${error}`
284
+ }
285
+ });
286
+ NotificationHandler.notifyError(NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
287
+ }
288
+ return conversationDetails;
289
+ };
290
+ export { setPostChatContextAndLoadSurvey, checkPostChatEnabled, initiatePostChat };
@@ -27,10 +27,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
27
27
  optionalParams = {}; //Resetting to ensure no stale values
28
28
  widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
29
29
 
30
- // Can connect to existing chat session
31
- if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
32
- return;
33
- }
30
+ // reconnect > chat from cache
34
31
  await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
35
32
 
36
33
  // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
@@ -38,6 +35,11 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
38
35
  return;
39
36
  }
40
37
 
38
+ // Can connect to existing chat session
39
+ if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
40
+ return;
41
+ }
42
+
41
43
  // Setting Proactive chat settings
42
44
  const isProactiveChat = state.appStates.conversationState === ConversationState.ProactiveChat;
43
45
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
@@ -304,12 +306,18 @@ const setCustomContextParams = chatSDK => {
304
306
  };
305
307
 
306
308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
307
- const checkIfConversationStillValid = async (chatSDK, props, requestId, dispatch) => {
309
+ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
310
+ var _state$domainStates, _state$domainStates$l;
311
+ const requestId = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
308
312
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
309
313
  let conversationDetails = undefined;
310
314
 
311
315
  //Preserve old requestId
312
- const oldRequestId = chatSDK.requestId;
316
+ const oldRequestId = chatSDK.requestId ?? "";
317
+ dispatch({
318
+ type: LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
319
+ payload: oldRequestId
320
+ });
313
321
  try {
314
322
  chatSDK.requestId = requestId;
315
323
  conversationDetails = await chatSDK.getConversationDetails();