@microsoft/omnichannel-chat-widget 0.1.0-main.c5ffed0 → 0.1.0-main.c91fa67

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.
@@ -174,6 +174,7 @@ exports.TelemetryEvent = TelemetryEvent;
174
174
  TelemetryEvent["MessageSent"] = "MessageSent";
175
175
  TelemetryEvent["MessageReceived"] = "MessageReceived";
176
176
  TelemetryEvent["SystemMessageReceived"] = "SystemMessageReceived";
177
+ TelemetryEvent["HistoryMessageReceived"] = "HistoryMessageReceived";
177
178
  TelemetryEvent["CustomContextReceived"] = "CustomContextReceived";
178
179
  TelemetryEvent["NetworkDisconnected"] = "NetworkDisconnected";
179
180
  TelemetryEvent["NetworkReconnected"] = "NetworkReconnected";
@@ -72,7 +72,7 @@ const HeaderStateful = props => {
72
72
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
73
73
  hideTitle: state.appStates.conversationState === _ConversationState.ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
74
74
  hideIcon: state.appStates.conversationState === _ConversationState.ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
75
- hideCloseButton: state.appStates.conversationState === _ConversationState.ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === _ConversationState.ConversationState.Prechat || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
75
+ hideCloseButton: state.appStates.conversationState === _ConversationState.ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading || state.appStates.conversationState === _ConversationState.ConversationState.Prechat || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
76
76
  };
77
77
  const outOfOfficeControlProps = {
78
78
  id: "oc-lcw-header",
@@ -17,9 +17,9 @@ var _utils = require("../../../common/utils");
17
17
  var _authHelper = require("./authHelper");
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
19
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
20
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
21
- const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
22
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
20
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
21
+ const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
22
+ const postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode);
23
23
 
24
24
  //Unable to end chat if token has expired
25
25
  if (props.getAuthToken) {
@@ -61,15 +61,20 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
61
61
  chatSDK.requestId = chatSession.requestId;
62
62
  }
63
63
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
64
- dispatch({
65
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
66
- payload: _ConversationState.ConversationState.PostchatLoading
67
- });
68
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
69
- const loadPostChatEvent = {
70
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
71
- };
72
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
64
+ // Only start embedded Postchat workflow if postchat context is set successfully else close chat
65
+ if (state.domainStates.postChatContext) {
66
+ dispatch({
67
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
68
+ payload: _ConversationState.ConversationState.PostchatLoading
69
+ });
70
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
71
+ const loadPostChatEvent = {
72
+ eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
73
+ };
74
+ _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
75
+ } else {
76
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, true, false, true);
77
+ }
73
78
  } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
74
79
  var _props$webChatContain, _props$webChatContain2;
75
80
  dispatch({
@@ -156,10 +161,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
156
161
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
157
162
  payload: null
158
163
  });
159
- dispatch({
160
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
161
- payload: 0
162
- });
163
164
  dispatch({
164
165
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
165
166
  payload: {
@@ -182,6 +183,11 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
182
183
  exception: `Failed to endChat: ${error}`
183
184
  }
184
185
  });
186
+ } finally {
187
+ dispatch({
188
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
189
+ payload: 0
190
+ });
185
191
  }
186
192
  }
187
193
  };
@@ -39,7 +39,7 @@ var _Constants = require("../../../common/Constants");
39
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
41
  const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
42
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
42
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$chatConfig, _props$chatConfig$Liv, _state$domainStates$l, _state$domainStates$l2, _props$chatConfig2, _props$chatConfig2$Li, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
43
43
  const localizedTexts = {
44
44
  ..._defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts,
45
45
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -47,8 +47,8 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
47
47
  const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
48
48
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
49
  const markdown = (0, _createMarkdown.createMarkdown)(((_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.disableMarkdownMessageFormatting) ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.disableMarkdownMessageFormatting, disableNewLineMarkdownSupport);
50
- const isPostChatEnabled = (_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable;
51
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
50
+ const isPostChatEnabled = ((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_postconversationsurveyenable) ?? ((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_postconversationsurveyenable);
51
+ const postChatSurveyMode = ((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_postconversationsurveymode) ?? ((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode);
52
52
 
53
53
  // Initialize Web Chat's redux store
54
54
  let webChatStore = _WebChatStoreLoader.WebChatStoreLoader.store;
@@ -70,16 +70,28 @@ const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles)
70
70
  }
71
71
  if (isPostChatEnabled === "true") {
72
72
  if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Embed) {
73
- _WebChatStoreLoader.WebChatStoreLoader.store = null;
74
- dispatch({
75
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
76
- payload: _ConversationState.ConversationState.PostchatLoading
77
- });
78
- await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
79
- const loadPostChatEvent = {
80
- eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
81
- };
82
- _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
73
+ // Only start embedded Postchat workflow if postchat context is set successfully else close chat
74
+ if (state.domainStates.postChatContext) {
75
+ _WebChatStoreLoader.WebChatStoreLoader.store = null;
76
+ dispatch({
77
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
78
+ payload: _ConversationState.ConversationState.PostchatLoading
79
+ });
80
+ await (0, _utils.addDelayInMs)(_Constants.Constants.PostChatLoadingDurationInMs);
81
+ const loadPostChatEvent = {
82
+ eventName: _TelemetryConstants.BroadcastEvent.LoadPostChatSurvey
83
+ };
84
+ _omnichannelChatComponents.BroadcastService.postMessage(loadPostChatEvent);
85
+ } else {
86
+ dispatch({
87
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
88
+ payload: _ConversationState.ConversationState.InActive
89
+ });
90
+ dispatch({
91
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY_AGENT,
92
+ payload: true
93
+ });
94
+ }
83
95
  } else if (postChatSurveyMode === _PostChatSurveyMode.PostChatSurveyMode.Link) {
84
96
  dispatch({
85
97
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -15,6 +15,7 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
15
15
  const isHistoryMessage = isActivityMessage && ((activity === null || activity === void 0 ? void 0 : (_activity$channelData = activity.channelData) === null || _activity$channelData === void 0 ? void 0 : (_activity$channelData2 = _activity$channelData.tags) === null || _activity$channelData2 === void 0 ? void 0 : _activity$channelData2.includes(_Constants.Constants.historyMessageTag)) || (activity === null || activity === void 0 ? void 0 : (_activity$channelData3 = activity.channelData) === null || _activity$channelData3 === void 0 ? void 0 : _activity$channelData3.fromList));
16
16
  raiseMessageEvent(activity, isHistoryMessage);
17
17
  };
18
+ let isHistoryMessageReceivedEventRasied = false;
18
19
  const raiseMessageEvent = (activity, isHistoryMessage) => {
19
20
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === _Constants.Constants.message) {
20
21
  var _text, _text2, _activity$channelData4, _activity$from;
@@ -73,6 +74,15 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
73
74
  Description: "New message received",
74
75
  Data: payload
75
76
  });
77
+ } else {
78
+ if (!isHistoryMessageReceivedEventRasied) {
79
+ isHistoryMessageReceivedEventRasied = true;
80
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
81
+ Event: _TelemetryConstants.TelemetryEvent.HistoryMessageReceived,
82
+ Description: "History message received",
83
+ Data: payload
84
+ });
85
+ }
76
86
  }
77
87
  }
78
88
  }
@@ -168,6 +168,7 @@ export let TelemetryEvent;
168
168
  TelemetryEvent["MessageSent"] = "MessageSent";
169
169
  TelemetryEvent["MessageReceived"] = "MessageReceived";
170
170
  TelemetryEvent["SystemMessageReceived"] = "SystemMessageReceived";
171
+ TelemetryEvent["HistoryMessageReceived"] = "HistoryMessageReceived";
171
172
  TelemetryEvent["CustomContextReceived"] = "CustomContextReceived";
172
173
  TelemetryEvent["NetworkDisconnected"] = "NetworkDisconnected";
173
174
  TelemetryEvent["NetworkReconnected"] = "NetworkReconnected";
@@ -63,7 +63,7 @@ export const HeaderStateful = props => {
63
63
  ...(headerProps === null || headerProps === void 0 ? void 0 : headerProps.controlProps),
64
64
  hideTitle: state.appStates.conversationState === ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP = headerProps.controlProps) === null || _headerProps$controlP === void 0 ? void 0 : _headerProps$controlP.hideTitle),
65
65
  hideIcon: state.appStates.conversationState === ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === ConversationState.PostchatLoading || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP2 = headerProps.controlProps) === null || _headerProps$controlP2 === void 0 ? void 0 : _headerProps$controlP2.hideIcon),
66
- hideCloseButton: state.appStates.conversationState === ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === ConversationState.Prechat || state.appStates.conversationState === ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
66
+ hideCloseButton: state.appStates.conversationState === ConversationState.Loading && !state.appStates.isStartChatFailing || state.appStates.conversationState === ConversationState.PostchatLoading || state.appStates.conversationState === ConversationState.Prechat || state.appStates.conversationState === ConversationState.ReconnectChat || (headerProps === null || headerProps === void 0 ? void 0 : (_headerProps$controlP3 = headerProps.controlProps) === null || _headerProps$controlP3 === void 0 ? void 0 : _headerProps$controlP3.hideCloseButton)
67
67
  };
68
68
  const outOfOfficeControlProps = {
69
69
  id: "oc-lcw-header",
@@ -12,9 +12,9 @@ import { getAuthClientFunction, handleAuthentication } from "./authHelper";
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;
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
18
 
19
19
  //Unable to end chat if token has expired
20
20
  if (props.getAuthToken) {
@@ -56,15 +56,20 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
56
56
  chatSDK.requestId = chatSession.requestId;
57
57
  }
58
58
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
59
- 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);
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
+ }
68
73
  } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
69
74
  var _props$webChatContain, _props$webChatContain2;
70
75
  dispatch({
@@ -150,10 +155,6 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
150
155
  type: LiveChatWidgetActionType.SET_AUDIO_NOTIFICATION,
151
156
  payload: null
152
157
  });
153
- dispatch({
154
- type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
155
- payload: 0
156
- });
157
158
  dispatch({
158
159
  type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
159
160
  payload: {
@@ -176,6 +177,11 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
176
177
  exception: `Failed to endChat: ${error}`
177
178
  }
178
179
  });
180
+ } finally {
181
+ dispatch({
182
+ type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
183
+ payload: 0
184
+ });
179
185
  }
180
186
  }
181
187
  };
@@ -33,7 +33,7 @@ import { Constants } from "../../../common/Constants";
33
33
 
34
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
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;
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;
37
37
  const localizedTexts = {
38
38
  ...defaultMiddlewareLocalizedTexts,
39
39
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -41,8 +41,8 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
41
41
  const disableNewLineMarkdownSupport = ((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.disableNewLineMarkdownSupport) ?? defaultWebChatContainerStatefulProps.disableNewLineMarkdownSupport;
42
42
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
43
43
  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;
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
46
 
47
47
  // Initialize Web Chat's redux store
48
48
  let webChatStore = WebChatStoreLoader.store;
@@ -64,16 +64,28 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
64
64
  }
65
65
  if (isPostChatEnabled === "true") {
66
66
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
67
- WebChatStoreLoader.store = null;
68
- dispatch({
69
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
70
- payload: ConversationState.PostchatLoading
71
- });
72
- await addDelayInMs(Constants.PostChatLoadingDurationInMs);
73
- const loadPostChatEvent = {
74
- eventName: BroadcastEvent.LoadPostChatSurvey
75
- };
76
- BroadcastService.postMessage(loadPostChatEvent);
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
+ }
77
89
  } else if (postChatSurveyMode === PostChatSurveyMode.Link) {
78
90
  dispatch({
79
91
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -9,6 +9,7 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
9
9
  const isHistoryMessage = isActivityMessage && ((activity === null || activity === void 0 ? void 0 : (_activity$channelData = activity.channelData) === null || _activity$channelData === void 0 ? void 0 : (_activity$channelData2 = _activity$channelData.tags) === null || _activity$channelData2 === void 0 ? void 0 : _activity$channelData2.includes(Constants.historyMessageTag)) || (activity === null || activity === void 0 ? void 0 : (_activity$channelData3 = activity.channelData) === null || _activity$channelData3 === void 0 ? void 0 : _activity$channelData3.fromList));
10
10
  raiseMessageEvent(activity, isHistoryMessage);
11
11
  };
12
+ let isHistoryMessageReceivedEventRasied = false;
12
13
  const raiseMessageEvent = (activity, isHistoryMessage) => {
13
14
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === Constants.message) {
14
15
  var _text, _text2, _activity$channelData4, _activity$from;
@@ -67,6 +68,15 @@ export const createOnNewAdapterActivityHandler = (chatId, userId) => {
67
68
  Description: "New message received",
68
69
  Data: payload
69
70
  });
71
+ } else {
72
+ if (!isHistoryMessageReceivedEventRasied) {
73
+ isHistoryMessageReceivedEventRasied = true;
74
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
75
+ Event: TelemetryEvent.HistoryMessageReceived,
76
+ Description: "History message received",
77
+ Data: payload
78
+ });
79
+ }
70
80
  }
71
81
  }
72
82
  }
@@ -161,6 +161,7 @@ export declare enum TelemetryEvent {
161
161
  MessageSent = "MessageSent",
162
162
  MessageReceived = "MessageReceived",
163
163
  SystemMessageReceived = "SystemMessageReceived",
164
+ HistoryMessageReceived = "HistoryMessageReceived",
164
165
  CustomContextReceived = "CustomContextReceived",
165
166
  NetworkDisconnected = "NetworkDisconnected",
166
167
  NetworkReconnected = "NetworkReconnected"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "0.1.0-main.c5ffed0",
3
+ "version": "0.1.0-main.c91fa67",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",