@microsoft/omnichannel-chat-widget 1.0.3-main.527b216 → 1.0.3-main.87088f3

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 (95) hide show
  1. package/lib/cjs/common/Constants.js +54 -1
  2. package/lib/cjs/common/storage/default/defaultCacheManager.js +7 -6
  3. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -1
  5. package/lib/cjs/common/utils.js +27 -5
  6. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +1 -10
  7. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  8. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -1
  9. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +12 -1
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +14 -13
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  13. package/lib/cjs/components/livechatwidget/common/Deferred.js +2 -3
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -2
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +197 -99
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +32 -27
  17. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  18. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +139 -0
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +2 -255
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +85 -69
  21. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +162 -100
  22. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  23. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
  24. package/lib/cjs/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  26. package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  27. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  31. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  32. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +16 -13
  33. package/lib/cjs/contexts/createReducer.js +13 -23
  34. package/lib/cjs/controller/componentController.js +2 -1
  35. package/lib/cjs/index.js +20 -0
  36. package/lib/esm/common/Constants.js +49 -0
  37. package/lib/esm/common/storage/default/defaultCacheManager.js +5 -4
  38. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  39. package/lib/esm/common/telemetry/TelemetryConstants.js +7 -1
  40. package/lib/esm/common/utils.js +25 -4
  41. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -13
  42. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  43. package/lib/esm/components/footerstateful/FooterStateful.js +1 -1
  44. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -1
  45. package/lib/esm/components/headerstateful/HeaderStateful.js +14 -13
  46. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  47. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  48. package/lib/esm/components/livechatwidget/common/Deferred.js +2 -3
  49. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -2
  50. package/lib/esm/components/livechatwidget/common/endChat.js +196 -99
  51. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +32 -27
  52. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  53. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +130 -0
  54. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -255
  55. package/lib/esm/components/livechatwidget/common/startChat.js +86 -70
  56. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -102
  57. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  58. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
  59. package/lib/esm/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
  60. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  61. package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  62. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  64. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  65. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  66. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  67. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +18 -15
  68. package/lib/esm/contexts/createReducer.js +13 -23
  69. package/lib/esm/controller/componentController.js +2 -1
  70. package/lib/esm/index.js +4 -1
  71. package/lib/types/common/Constants.d.ts +21 -0
  72. package/lib/types/common/interfaces/IContextDataStore.d.ts +3 -3
  73. package/lib/types/common/storage/default/defaultCacheManager.d.ts +2 -1
  74. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -1
  75. package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
  76. package/lib/types/common/utils.d.ts +3 -2
  77. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +6 -0
  78. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
  79. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
  80. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
  81. package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +9 -0
  82. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -6
  83. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  84. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +4 -0
  85. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +8 -7
  86. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  87. package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +2 -1
  88. package/lib/types/index.d.ts +3 -0
  89. package/package.json +2 -1
  90. package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +0 -36
  91. package/lib/cjs/contexts/common/ConversationEndEntity.js +0 -12
  92. package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +0 -30
  93. package/lib/esm/contexts/common/ConversationEndEntity.js +0 -5
  94. package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +0 -6
  95. package/lib/types/contexts/common/ConversationEndEntity.d.ts +0 -4
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setWidgetStateToInactive = exports.initiatePostChat = exports.getPostChatContext = exports.checkPostChatEnabled = void 0;
7
+ var _Constants = require("../../../common/Constants");
8
+ var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
+ var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
10
+ var _utils = require("../../../common/utils");
11
+ var _ConversationState = require("../../../contexts/common/ConversationState");
12
+ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
13
+ var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ let conversationDetails = undefined;
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ let postChatSurveyMode = undefined;
18
+ const getBotSurveyMode = (props, state) => {
19
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
20
+ return ((_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_postconversationsurveybotsurveymode) ?? ((_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_postconversationsurveybotsurveymode);
21
+ };
22
+ const getUserSurveyMode = (props, state) => {
23
+ var _props$chatConfig2, _props$chatConfig2$Li, _props$chatConfig3, _props$chatConfig3$Li;
24
+ if (!((_props$chatConfig2 = props.chatConfig) !== null && _props$chatConfig2 !== void 0 && (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) !== null && _props$chatConfig2$Li !== void 0 && _props$chatConfig2$Li.msdyn_postconversationsurveymode)) {
25
+ var _state$domainStates, _state$domainStates$l3, _state$domainStates$l4;
26
+ return (state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_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) ?? _PostChatSurveyMode.PostChatSurveyMode.Embed;
27
+ }
28
+ return (_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;
29
+ };
30
+
31
+ // Set Survey mode based on conversation ended by entity
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ const setSurveyMode = async (props, participantType, state, dispatch) => {
34
+ if (participantType === _Constants.ParticipantType.User) {
35
+ postChatSurveyMode = getUserSurveyMode(props, state);
36
+ dispatch({
37
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SURVEY_MODE,
38
+ payload: postChatSurveyMode
39
+ });
40
+ return;
41
+ }
42
+ if (participantType === _Constants.ParticipantType.Bot) {
43
+ postChatSurveyMode = getBotSurveyMode(props, state);
44
+ dispatch({
45
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SURVEY_MODE,
46
+ payload: postChatSurveyMode
47
+ });
48
+ return;
49
+ }
50
+ };
51
+ const renderSurvey = async (state, dispatch) => {
52
+ if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
53
+ setWidgetStateToInactive(dispatch);
54
+ return;
55
+ }
56
+ if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
57
+ await embedModePostChatWorkflow(state, dispatch);
58
+ }
59
+ };
60
+
61
+ // Function for embed mode postchat workflow which is essentially same for both customer and agent
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ const embedModePostChatWorkflow = async (state, dispatch) => {
64
+ var _state$domainStates2;
65
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
66
+ Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
67
+ });
68
+ if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
69
+ dispatch({
70
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
71
+ payload: _ConversationState.ConversationState.PostchatLoading
72
+ });
73
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
74
+ dispatch({
75
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
76
+ payload: _ConversationState.ConversationState.Postchat
77
+ });
78
+ } else {
79
+ const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
80
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
81
+ Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
82
+ ExceptionDetails: {
83
+ exception: error
84
+ }
85
+ });
86
+ }
87
+ };
88
+
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ const initiatePostChat = async (props, conversationDetailsParam, state, dispatch) => {
91
+ var _conversationDetails;
92
+ conversationDetails = conversationDetailsParam;
93
+ await setSurveyMode(props, (_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.participantType, state, dispatch);
94
+ await renderSurvey(state, dispatch);
95
+ };
96
+
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ exports.initiatePostChat = initiatePostChat;
99
+ const isPostChatEnabled = (props, state) => {
100
+ var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l5, _state$domainStates$l6;
101
+ const isPostChatEnabled = ((_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_postconversationsurveyenable) ?? ((_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_postconversationsurveyenable);
102
+ return isPostChatEnabled === _Constants.Constants.true;
103
+ };
104
+
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ exports.checkPostChatEnabled = isPostChatEnabled;
107
+ const getPostChatContext = async (chatSDK, state, dispatch) => {
108
+ try {
109
+ var _state$domainStates3;
110
+ if ((state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.postChatContext) === undefined) {
111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
+ const context = await chatSDK.getPostChatSurveyContext();
113
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
114
+ Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallSucceed,
115
+ Description: "Postchat context call succeed."
116
+ });
117
+ dispatch({
118
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_CONTEXT,
119
+ payload: context
120
+ });
121
+ }
122
+ } catch (error) {
123
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
124
+ Event: _TelemetryConstants.TelemetryEvent.PostChatContextCallFailed,
125
+ Description: "Failed to get post chat context."
126
+ });
127
+ }
128
+ };
129
+
130
+ // Function for link mode postchat workflow which is essentially same for both customer and agent
131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
+ exports.getPostChatContext = getPostChatContext;
133
+ const setWidgetStateToInactive = async dispatch => {
134
+ dispatch({
135
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
136
+ payload: _ConversationState.ConversationState.InActive
137
+ });
138
+ };
139
+ exports.setWidgetStateToInactive = setWidgetStateToInactive;
@@ -3,19 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setPostChatContextAndLoadSurvey = exports.initiatePostChat = exports.checkPostChatEnabled = void 0;
6
+ exports.setPostChatContextAndLoadSurvey = void 0;
7
7
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
8
8
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
9
9
  var _ConversationState = require("../../../contexts/common/ConversationState");
10
10
  var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidgetActionType");
11
11
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
12
- var _Constants = require("../../../common/Constants");
13
- var _endChat = require("./endChat");
14
- var _PostChatSurveyMode = require("../../postchatsurveypanestateful/enums/PostChatSurveyMode");
15
- var _utils = require("../../../common/utils");
16
- var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
17
- var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios");
18
- var _ConversationEndEntity = require("../../../contexts/common/ConversationEndEntity");
19
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
13
  const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat) => {
21
14
  try {
@@ -48,250 +41,4 @@ const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persistedChat)
48
41
  });
49
42
  });
50
43
  };
51
-
52
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
- exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;
54
- const checkPostChatEnabled = (props, state) => {
55
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2;
56
- const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
57
- return isPostChatEnabled === _Constants.Constants.true;
58
- };
59
-
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- exports.checkPostChatEnabled = checkPostChatEnabled;
62
- const initiatePostChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
63
- // Check if Postchat already in progress and handle case where chat is ended by customer
64
- if (state.appStates.postChatWorkflowInProgress && state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
65
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
66
- return;
67
- }
68
-
69
- // Conversation Details call required by customer as well as agent
70
- const conversationDetails = await getConversationDetailsCall(chatSDK);
71
- // Start Postchat workflow
72
- dispatch({
73
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_POST_CHAT_WORKFLOW_IN_PROGRESS,
74
- payload: true
75
- });
76
-
77
- // Below logic checks if agent or bot or noone joins conversation and handles them separately
78
- if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.userParticipantTypeTag) {
79
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
80
- // Set use bot settings to false
81
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
82
- } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
83
- await postChatInitiatedByAgent(props, setWebChatStyles, dispatch, state);
84
- } else {
85
- const error = `Conversation was Ended after agent joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
86
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
87
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
88
- ExceptionDetails: {
89
- exception: error
90
- }
91
- });
92
- throw new Error(error);
93
- }
94
- } else if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.Constants.botParticipantTypeTag) {
95
- // Set Use bot survey to true
96
- dispatch({
97
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_USE_BOT_SURVEY,
98
- payload: true
99
- });
100
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
101
- // Set use bot settings to true
102
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, true);
103
- } else if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Agent) {
104
- await postChatInitiatedByBot(props, setWebChatStyles, dispatch, state);
105
- } else {
106
- const error = `Conversation was Ended after bot joined but App State was not set correctly: conversationEndedBy = ${state.appStates.conversationEndedBy}`;
107
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
108
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
109
- ExceptionDetails: {
110
- exception: error
111
- }
112
- });
113
- throw new Error(error);
114
- }
115
- } else {
116
- if (state.appStates.conversationEndedBy === _ConversationEndEntity.ConversationEndEntity.Customer) {
117
- // No one has joined chat will be handled by postChat customer
118
- await postChatInitiatedByCustomer(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, false);
119
- } else {
120
- const error = `ConversationDetails and App state was not set correctly: conversationDetails = ${JSON.stringify(conversationDetails)} , conversationEndedBy = ${state.appStates.conversationEndedBy}`;
121
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
122
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
123
- ExceptionDetails: {
124
- exception: error
125
- }
126
- });
127
- throw new Error(error);
128
- }
129
- }
130
- };
131
-
132
- // Function for link mode postchat workflow which is essentially same for both customer and agent
133
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
- exports.initiatePostChat = initiatePostChat;
135
- const linkModePostChatWorkflow = (props, dispatch, setWebChatStyles) => {
136
- var _props$webChatContain, _props$webChatContain2;
137
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
138
- Event: _TelemetryConstants.TelemetryEvent.LinkModePostChatWorkflowStarted
139
- });
140
- dispatch({
141
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
142
- payload: _ConversationState.ConversationState.InActive
143
- });
144
-
145
- // Disable SendBox
146
- if ((props === null || props === void 0 ? void 0 : (_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : (_props$webChatContain2 = _props$webChatContain.renderingMiddlewareProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.hideSendboxOnConversationEnd) !== false) {
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- setWebChatStyles(styles => {
149
- return {
150
- ...styles,
151
- hideSendBox: true
152
- };
153
- });
154
- }
155
- };
156
-
157
- // Function for embed mode postchat workflow which is essentially same for both customer and agent
158
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
- const embedModePostChatWorkflow = async (dispatch, state) => {
160
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
161
- Event: _TelemetryConstants.TelemetryEvent.EmbedModePostChatWorkflowStarted
162
- });
163
- if (state.domainStates.postChatContext) {
164
- dispatch({
165
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
166
- payload: _ConversationState.ConversationState.PostchatLoading
167
- });
168
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
169
- const loadPostChatEvent = {
170
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
171
- };
172
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
173
- } else {
174
- const error = `Conversation was Ended but App State was not set correctly: postChatContext = ${state.domainStates.postChatContext}`;
175
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
176
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
177
- ExceptionDetails: {
178
- exception: error
179
- }
180
- });
181
- throw new Error(error);
182
- }
183
- };
184
-
185
- // Function will handle only postchat cases initiated by customer
186
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
- const postChatInitiatedByCustomer = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state, conversationDetails, shouldUseBotSetting) => {
188
- let postChatSurveyMode = "";
189
- if (shouldUseBotSetting) {
190
- var _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4;
191
- postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveybotsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveybotsurveymode);
192
- } else {
193
- var _props$chatConfig3, _props$chatConfig3$Li, _state$domainStates$l5, _state$domainStates$l6;
194
- postChatSurveyMode = ((_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l5 = state.domainStates.liveChatConfig) === null || _state$domainStates$l5 === void 0 ? void 0 : (_state$domainStates$l6 = _state$domainStates$l5.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l6 === void 0 ? void 0 : _state$domainStates$l6.msdyn_postconversationsurveymode);
195
- }
196
- // Check if agent or bot has joined conversation
197
- if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === _Constants.Constants.truePascal) {
198
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
199
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromCustomer,
200
- Description: shouldUseBotSetting ? "PostChat Workflow was started by customer using bot settings" : "PostChat Workflow was started by customer using agent settings"
201
- });
202
- const chatSession = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
203
- // End chat call to end chatsdk but not close chat, only if chat ended by customer
204
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, true, false);
205
- // Saving request Id below for chat transcript calls
206
- if (chatSession) {
207
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
- chatSDK.chatToken = chatSession.chatToken ?? {};
209
- chatSDK.requestId = chatSession.requestId;
210
- }
211
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
212
- await embedModePostChatWorkflow(dispatch, state);
213
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
214
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
215
- } else {
216
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
217
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
218
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
219
- ExceptionDetails: {
220
- exception: error
221
- }
222
- });
223
- throw new Error(error);
224
- }
225
- } else {
226
- // Agent did not join chat so end chat normally
227
- await (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
228
- }
229
- };
230
-
231
- // Function will handle only postchat cases initiated by agent
232
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
- const postChatInitiatedByAgent = async (props, setWebChatStyles, dispatch, state) => {
234
- var _props$chatConfig4, _props$chatConfig4$Li, _state$domainStates$l7, _state$domainStates$l8;
235
- 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);
236
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
237
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromAgent,
238
- Description: "PostChat Workflow was started by agent"
239
- });
240
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
241
- await embedModePostChatWorkflow(dispatch, state);
242
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
243
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
244
- } else {
245
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveymode = ${postChatSurveyMode}`;
246
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
247
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
248
- ExceptionDetails: {
249
- exception: error
250
- }
251
- });
252
- throw new Error(error);
253
- }
254
- };
255
-
256
- // Function will handle only postchat cases initiated by bot
257
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
258
- const postChatInitiatedByBot = async (props, setWebChatStyles, dispatch, state) => {
259
- var _props$chatConfig5, _props$chatConfig5$Li, _state$domainStates$l9, _state$domainStates$l10;
260
- 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);
261
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
262
- Event: _TelemetryConstants.TelemetryEvent.PostChatWorkflowFromBot,
263
- Description: "PostChat Workflow was started by bot"
264
- });
265
- if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
266
- await embedModePostChatWorkflow(dispatch, state);
267
- } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
268
- linkModePostChatWorkflow(props, dispatch, setWebChatStyles);
269
- } else {
270
- const error = `Conversation was Ended but App State was not set correctly: msdyn_postconversationsurveybotsurveymode = ${postChatSurveyMode}`;
271
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
272
- Event: _TelemetryConstants.TelemetryEvent.AppStatesException,
273
- ExceptionDetails: {
274
- exception: error
275
- }
276
- });
277
- throw new Error(error);
278
- }
279
- };
280
-
281
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
282
- const getConversationDetailsCall = async chatSDK => {
283
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
284
- let conversationDetails = undefined;
285
- try {
286
- conversationDetails = await chatSDK.getConversationDetails();
287
- } catch (error) {
288
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
289
- Event: _TelemetryConstants.TelemetryEvent.GetConversationDetailsCallFailed,
290
- ExceptionDetails: {
291
- exception: `Get Conversation Details Call Failed : ${error}`
292
- }
293
- });
294
- _NotificationHandler.NotificationHandler.notifyError(_NotificationScenarios.NotificationScenarios.Connection, "Get Conversation Details Call Failed: " + error);
295
- }
296
- return conversationDetails;
297
- };
44
+ exports.setPostChatContextAndLoadSurvey = setPostChatContextAndLoadSurvey;