@microsoft/omnichannel-chat-widget 1.5.1-main.6b98130 → 1.5.1-main.7897747

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 (33) hide show
  1. package/lib/cjs/common/Constants.js +14 -2
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
  3. package/lib/cjs/components/livechatwidget/common/endChat.js +25 -3
  4. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -4
  5. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +6 -5
  6. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +34 -0
  7. package/lib/esm/common/Constants.js +12 -1
  8. package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
  9. package/lib/esm/components/livechatwidget/common/endChat.js +26 -4
  10. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -4
  11. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -6
  12. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +35 -1
  13. package/lib/types/common/Constants.d.ts +12 -0
  14. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  15. package/package.json +3 -3
  16. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -71
  17. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -56
  18. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -300
  19. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -190
  20. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -82
  21. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -342
  22. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -69
  23. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -54
  24. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -298
  25. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -188
  26. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -80
  27. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -338
  28. package/lib/types/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.d.ts +0 -1
  29. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.d.ts +0 -1
  30. package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +0 -1
  31. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +0 -1
  32. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +0 -1
  33. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +0 -1
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WidgetLoadTelemetryMessage = exports.WidgetLoadCustomErrorString = exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.StartChatErrorPaneConstants = exports.Regex = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
6
+ exports.WidgetLoadTelemetryMessage = exports.WidgetLoadCustomErrorString = exports.WebChatMiddlewareConstants = exports.TranscriptConstants = exports.StorageType = exports.StartChatErrorPaneConstants = exports.Regex = exports.PrepareEndChatDescriptionConstants = exports.ParticipantType = exports.NotificationPaneConstants = exports.MimeTypes = exports.LocaleConstants = exports.LiveWorkItemState = exports.HtmlIdNames = exports.HtmlElementSelectors = exports.HtmlClassNames = exports.HtmlAttributeNames = exports.EnvironmentVersion = exports.ElementType = exports.E2VVOptions = exports.ConversationMode = exports.ConversationEndEntity = exports.Constants = exports.ConfirmationState = exports.AriaTelemetryConstants = exports.AMSConstants = void 0;
7
7
  var _class;
8
8
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
@@ -305,4 +305,16 @@ _defineProperty(WidgetLoadTelemetryMessage, "PersistedStateRetrievedMessage", "P
305
305
  class WidgetLoadCustomErrorString {}
306
306
  exports.WidgetLoadCustomErrorString = WidgetLoadCustomErrorString;
307
307
  _defineProperty(WidgetLoadCustomErrorString, "AuthenticationFailedErrorString", "Authentication was not successful");
308
- _defineProperty(WidgetLoadCustomErrorString, "NetworkErrorString", "Network Error");
308
+ _defineProperty(WidgetLoadCustomErrorString, "NetworkErrorString", "Network Error");
309
+ class PrepareEndChatDescriptionConstants {}
310
+ exports.PrepareEndChatDescriptionConstants = PrepareEndChatDescriptionConstants;
311
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedByCustomerWithoutPostChat", "Conversation ended by customer. Post chat not configured or should not show.");
312
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedByCustomerWithInvalidPostChat", "Conversation ended by customer. Post chat context is invalid.");
313
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedBy", "Conversation ended by");
314
+ _defineProperty(PrepareEndChatDescriptionConstants, "PrepareEndChatError", "There's an error while preparing to end chat. Closing chat widget.");
315
+ _defineProperty(PrepareEndChatDescriptionConstants, "WidgetLoadFailedAfterSessionInit", "SessionInit was successful, but widget load failed. Ending chat to avoid ghost chats in OC.");
316
+ _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceived", "Received InitiateEndChat BroadcastEvent while conversation state is not Active. Ending chat.");
317
+ _defineProperty(PrepareEndChatDescriptionConstants, "EndChatReceivedFromOtherTabs", "Received EndChat BroadcastEvent from other tabs. Closing this chat.");
318
+ _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseChatOnFailureOrPostChat", "Customer is trying to close chat widget on start chat failure or post chat pane.");
319
+ _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseInactiveChat", "Chat was Inactive and customer is trying to close chat widget or refreshing the page.");
320
+ _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
@@ -123,6 +123,7 @@ exports.TelemetryEvent = TelemetryEvent;
123
123
  TelemetryEvent["StartChatSDKCall"] = "StartChatCall";
124
124
  TelemetryEvent["StartChatEventRecevied"] = "StartChatEventReceived";
125
125
  TelemetryEvent["EndChatSDKCall"] = "EndChatSDKCall";
126
+ TelemetryEvent["PrepareEndChat"] = "PrepareEndChat";
126
127
  TelemetryEvent["EndChatEventReceived"] = "EndChatEventReceived";
127
128
  TelemetryEvent["WindowClosed"] = "WindowClosed";
128
129
  TelemetryEvent["OnNewMessageFailed"] = "OnNewMessageFailed";
@@ -290,6 +291,7 @@ class TelemetryConstants {
290
291
  case TelemetryEvent.PostChatContextCallFailed:
291
292
  case TelemetryEvent.PostChatContextCallSucceed:
292
293
  case TelemetryEvent.GetConversationDetailsException:
294
+ case TelemetryEvent.PrepareEndChat:
293
295
  return ScenarioType.SDK;
294
296
  case TelemetryEvent.VideoCallAcceptButtonClick:
295
297
  case TelemetryEvent.CallAdded:
@@ -20,7 +20,7 @@ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
20
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
21
  const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
22
22
  try {
23
- var _conversationDetails$, _state$domainStates;
23
+ var _conversationDetails$, _state$domainStates, _state$appStates3;
24
24
  // Use Case: If call is ongoing, end the call by simulating end call button click
25
25
  endVoiceVideoCallIfOngoing(chatSDK, dispatch);
26
26
  const conversationDetails = await (0, _utils.getConversationDetailsCall)(chatSDK);
@@ -30,8 +30,13 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
30
30
  var _state$appStates;
31
31
  // If ended by customer, just close chat
32
32
  if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
33
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
34
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
35
+ Description: _Constants.PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithoutPostChat
36
+ });
33
37
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
34
38
  }
39
+
35
40
  // Use Case: If ended by Agent, stay chat in InActive state
36
41
  return;
37
42
  }
@@ -51,6 +56,10 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
51
56
  var _state$appStates2;
52
57
  // For Customer intiated conversations, just close chat widget
53
58
  if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
59
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
60
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
61
+ Description: _Constants.PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat
62
+ });
54
63
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
55
64
  return;
56
65
  }
@@ -62,6 +71,15 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
62
71
  });
63
72
  return;
64
73
  }
74
+
75
+ // Log PrepareEndChat if conversation ended by customer (bot and agent cases are handled in LiveChatWidgetStateful.tsx)
76
+ if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.conversationEndedBy) {
77
+ var _state$appStates4;
78
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
79
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
80
+ Description: `${_Constants.PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat} ${state === null || state === void 0 ? void 0 : (_state$appStates4 = state.appStates) === null || _state$appStates4 === void 0 ? void 0 : _state$appStates4.conversationEndedBy}.`
81
+ });
82
+ }
65
83
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true);
66
84
 
67
85
  // Initiate post chat render
@@ -80,6 +98,10 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
80
98
 
81
99
  //Close chat widget for any failure in embedded to allow to show start chat button
82
100
  if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
101
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
102
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
103
+ Description: _Constants.PrepareEndChatDescriptionConstants.PrepareEndChatError
104
+ });
83
105
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
84
106
  }
85
107
  } finally {
@@ -265,8 +287,8 @@ const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
265
287
  };
266
288
  exports.endVoiceVideoCallIfOngoing = endVoiceVideoCallIfOngoing;
267
289
  const closeChatWidget = (dispatch, props, state) => {
268
- var _state$appStates3;
269
- if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.hideStartChatButton) {
290
+ var _state$appStates5;
291
+ if (state !== null && state !== void 0 && (_state$appStates5 = state.appStates) !== null && _state$appStates5 !== void 0 && _state$appStates5.hideStartChatButton) {
270
292
  var _props$controlProps2, _props$controlProps3;
271
293
  // Only close chat if header is enabled for popout
272
294
  // TODO : This condition needs to be removed eventually when the filler UX is ready for popout, removing this condition would show a blank screen for OOB Widget
@@ -59,11 +59,19 @@ const initWebChatComposer = (props, state, dispatch, chatSDK, endChat) => {
59
59
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
60
  const conversationDetails = await (0, _utils.getConversationDetailsCall)(chatSDK);
61
61
  if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === _Constants.ParticipantType.Bot) {
62
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
63
+ Event: _TelemetryConstants.TelemetryEvent.ConversationEndedThreadEventReceived,
64
+ Description: "Conversation end by bot or timeout event received."
65
+ });
62
66
  dispatch({
63
67
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
64
68
  payload: _Constants.ConversationEndEntity.Bot
65
69
  });
66
70
  } else {
71
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
72
+ Event: _TelemetryConstants.TelemetryEvent.ConversationEndedThreadEventReceived,
73
+ Description: "Conversation end by agent or timeout event received."
74
+ });
67
75
  dispatch({
68
76
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
69
77
  payload: _Constants.ConversationEndEntity.Agent
@@ -75,10 +83,6 @@ const initWebChatComposer = (props, state, dispatch, chatSDK, endChat) => {
75
83
  payload: conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType
76
84
  });
77
85
  }
78
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
79
- Event: _TelemetryConstants.TelemetryEvent.ConversationEndedThreadEventReceived,
80
- Description: "Conversation end by agent side or by timeout event received."
81
- });
82
86
  };
83
87
  webChatStore = (0, _botframeworkWebchat.createStore)({},
84
88
  //initial state
@@ -141,11 +141,12 @@ const logWidgetLoadCompleteWithError = ex => {
141
141
 
142
142
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
143
  const forceEndChat = chatSDK => {
144
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.ERROR, {
145
- Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
146
- ExceptionDetails: {
147
- Exception: "SessionInit was successful, but widget load failed."
148
- }
144
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
145
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
146
+ Description: _Constants.PrepareEndChatDescriptionConstants.WidgetLoadFailedAfterSessionInit
147
+ });
148
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
149
+ Event: _TelemetryConstants.TelemetryEvent.EndChatSDKCall
149
150
  });
150
151
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
151
152
  };
@@ -413,9 +413,23 @@ const LiveChatWidgetStateful = props => {
413
413
 
414
414
  // End chat
415
415
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async () => {
416
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
417
+ Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
418
+ Description: "Received InitiateEndChat BroadcastEvent."
419
+ });
420
+
416
421
  // This is to ensure to get latest state from cache in multitab
417
422
  const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
418
423
  if (persistedState && persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
424
+ // We need to simulate states for closing chat, in order to messup with close confirmation pane.
425
+ dispatch({
426
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONFIRMATION_STATE,
427
+ payload: _Constants.ConfirmationState.Ok
428
+ });
429
+ dispatch({
430
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOW_CONFIRMATION,
431
+ payload: false
432
+ });
419
433
  dispatch({
420
434
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
421
435
  payload: _Constants.ConversationEndEntity.Customer
@@ -423,6 +437,10 @@ const LiveChatWidgetStateful = props => {
423
437
  } else {
424
438
  const skipEndChatSDK = true;
425
439
  const skipCloseChat = false;
440
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
441
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
442
+ Description: _Constants.PrepareEndChatDescriptionConstants.InitiateEndChatReceived
443
+ });
426
444
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
427
445
  }
428
446
  _omnichannelChatComponents.BroadcastService.postMessage({
@@ -440,6 +458,10 @@ const LiveChatWidgetStateful = props => {
440
458
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
441
459
  var _msg$payload9;
442
460
  if ((msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
461
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
462
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
463
+ Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
464
+ });
443
465
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
444
466
  (0, _endChat.endChatStateCleanUp)(dispatch);
445
467
  (0, _endChat.chatSDKStateCleanUp)(chatSDK);
@@ -570,12 +592,20 @@ const LiveChatWidgetStateful = props => {
570
592
 
571
593
  // If start chat failed, and C2 is trying to close chat widget
572
594
  if (state !== null && state !== void 0 && (_state$appStates9 = state.appStates) !== null && _state$appStates9 !== void 0 && _state$appStates9.startChatFailed || (state === null || state === void 0 ? void 0 : (_state$appStates10 = state.appStates) === null || _state$appStates10 === void 0 ? void 0 : _state$appStates10.conversationState) === _ConversationState.ConversationState.Postchat) {
595
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
596
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
597
+ Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
598
+ });
573
599
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
574
600
  return;
575
601
  }
576
602
 
577
603
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
578
604
  if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === _ConversationState.ConversationState.InActive) {
605
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
606
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
607
+ Description: _Constants.PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
608
+ });
579
609
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
580
610
  return;
581
611
  }
@@ -628,6 +658,10 @@ const LiveChatWidgetStateful = props => {
628
658
  Event: _TelemetryConstants.TelemetryEvent.BrowserUnloadEventStarted,
629
659
  Description: "Browser unload event received."
630
660
  });
661
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
662
+ Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,
663
+ Description: _Constants.PrepareEndChatDescriptionConstants.BrowserUnload
664
+ });
631
665
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, false);
632
666
  // Clean local storage
633
667
  (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventId);
@@ -274,4 +274,15 @@ _defineProperty(WidgetLoadTelemetryMessage, "OOOHMessage", "Widget is OOOH");
274
274
  _defineProperty(WidgetLoadTelemetryMessage, "PersistedStateRetrievedMessage", "Persisted state retrieved");
275
275
  export class WidgetLoadCustomErrorString {}
276
276
  _defineProperty(WidgetLoadCustomErrorString, "AuthenticationFailedErrorString", "Authentication was not successful");
277
- _defineProperty(WidgetLoadCustomErrorString, "NetworkErrorString", "Network Error");
277
+ _defineProperty(WidgetLoadCustomErrorString, "NetworkErrorString", "Network Error");
278
+ export class PrepareEndChatDescriptionConstants {}
279
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedByCustomerWithoutPostChat", "Conversation ended by customer. Post chat not configured or should not show.");
280
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedByCustomerWithInvalidPostChat", "Conversation ended by customer. Post chat context is invalid.");
281
+ _defineProperty(PrepareEndChatDescriptionConstants, "ConversationEndedBy", "Conversation ended by");
282
+ _defineProperty(PrepareEndChatDescriptionConstants, "PrepareEndChatError", "There's an error while preparing to end chat. Closing chat widget.");
283
+ _defineProperty(PrepareEndChatDescriptionConstants, "WidgetLoadFailedAfterSessionInit", "SessionInit was successful, but widget load failed. Ending chat to avoid ghost chats in OC.");
284
+ _defineProperty(PrepareEndChatDescriptionConstants, "InitiateEndChatReceived", "Received InitiateEndChat BroadcastEvent while conversation state is not Active. Ending chat.");
285
+ _defineProperty(PrepareEndChatDescriptionConstants, "EndChatReceivedFromOtherTabs", "Received EndChat BroadcastEvent from other tabs. Closing this chat.");
286
+ _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseChatOnFailureOrPostChat", "Customer is trying to close chat widget on start chat failure or post chat pane.");
287
+ _defineProperty(PrepareEndChatDescriptionConstants, "CustomerCloseInactiveChat", "Chat was Inactive and customer is trying to close chat widget or refreshing the page.");
288
+ _defineProperty(PrepareEndChatDescriptionConstants, "BrowserUnload", "Browser unload event received. Ending chat.");
@@ -117,6 +117,7 @@ export let TelemetryEvent;
117
117
  TelemetryEvent["StartChatSDKCall"] = "StartChatCall";
118
118
  TelemetryEvent["StartChatEventRecevied"] = "StartChatEventReceived";
119
119
  TelemetryEvent["EndChatSDKCall"] = "EndChatSDKCall";
120
+ TelemetryEvent["PrepareEndChat"] = "PrepareEndChat";
120
121
  TelemetryEvent["EndChatEventReceived"] = "EndChatEventReceived";
121
122
  TelemetryEvent["WindowClosed"] = "WindowClosed";
122
123
  TelemetryEvent["OnNewMessageFailed"] = "OnNewMessageFailed";
@@ -284,6 +285,7 @@ export class TelemetryConstants {
284
285
  case TelemetryEvent.PostChatContextCallFailed:
285
286
  case TelemetryEvent.PostChatContextCallSucceed:
286
287
  case TelemetryEvent.GetConversationDetailsException:
288
+ case TelemetryEvent.PrepareEndChat:
287
289
  return ScenarioType.SDK;
288
290
  case TelemetryEvent.VideoCallAcceptButtonClick:
289
291
  case TelemetryEvent.CallAdded:
@@ -1,4 +1,4 @@
1
- import { ConfirmationState, Constants, ConversationEndEntity, ParticipantType } from "../../../common/Constants";
1
+ import { ConfirmationState, Constants, ConversationEndEntity, ParticipantType, PrepareEndChatDescriptionConstants } from "../../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { getAuthClientFunction, handleAuthentication } from "./authHelper";
4
4
  import { getConversationDetailsCall, getWidgetEndChatEventName } from "../../../common/utils";
@@ -15,7 +15,7 @@ import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
15
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
16
  const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
17
17
  try {
18
- var _conversationDetails$, _state$domainStates;
18
+ var _conversationDetails$, _state$domainStates, _state$appStates3;
19
19
  // Use Case: If call is ongoing, end the call by simulating end call button click
20
20
  endVoiceVideoCallIfOngoing(chatSDK, dispatch);
21
21
  const conversationDetails = await getConversationDetailsCall(chatSDK);
@@ -25,8 +25,13 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
25
25
  var _state$appStates;
26
26
  // If ended by customer, just close chat
27
27
  if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === ConversationEndEntity.Customer) {
28
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
29
+ Event: TelemetryEvent.PrepareEndChat,
30
+ Description: PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithoutPostChat
31
+ });
28
32
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
29
33
  }
34
+
30
35
  // Use Case: If ended by Agent, stay chat in InActive state
31
36
  return;
32
37
  }
@@ -46,6 +51,10 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
46
51
  var _state$appStates2;
47
52
  // For Customer intiated conversations, just close chat widget
48
53
  if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === ConversationEndEntity.Customer) {
54
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
55
+ Event: TelemetryEvent.PrepareEndChat,
56
+ Description: PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat
57
+ });
49
58
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
50
59
  return;
51
60
  }
@@ -57,6 +66,15 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
57
66
  });
58
67
  return;
59
68
  }
69
+
70
+ // Log PrepareEndChat if conversation ended by customer (bot and agent cases are handled in LiveChatWidgetStateful.tsx)
71
+ if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.conversationEndedBy) {
72
+ var _state$appStates4;
73
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
74
+ Event: TelemetryEvent.PrepareEndChat,
75
+ Description: `${PrepareEndChatDescriptionConstants.ConversationEndedByCustomerWithInvalidPostChat} ${state === null || state === void 0 ? void 0 : (_state$appStates4 = state.appStates) === null || _state$appStates4 === void 0 ? void 0 : _state$appStates4.conversationEndedBy}.`
76
+ });
77
+ }
60
78
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true);
61
79
 
62
80
  // Initiate post chat render
@@ -75,6 +93,10 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
75
93
 
76
94
  //Close chat widget for any failure in embedded to allow to show start chat button
77
95
  if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
96
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
97
+ Event: TelemetryEvent.PrepareEndChat,
98
+ Description: PrepareEndChatDescriptionConstants.PrepareEndChatError
99
+ });
78
100
  await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
79
101
  }
80
102
  } finally {
@@ -253,8 +275,8 @@ export const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
253
275
  }
254
276
  };
255
277
  const closeChatWidget = (dispatch, props, state) => {
256
- var _state$appStates3;
257
- if (state !== null && state !== void 0 && (_state$appStates3 = state.appStates) !== null && _state$appStates3 !== void 0 && _state$appStates3.hideStartChatButton) {
278
+ var _state$appStates5;
279
+ if (state !== null && state !== void 0 && (_state$appStates5 = state.appStates) !== null && _state$appStates5 !== void 0 && _state$appStates5.hideStartChatButton) {
258
280
  var _props$controlProps2, _props$controlProps3;
259
281
  // Only close chat if header is enabled for popout
260
282
  // TODO : This condition needs to be removed eventually when the filler UX is ready for popout, removing this condition would show a blank screen for OOB Widget
@@ -53,11 +53,19 @@ export const initWebChatComposer = (props, state, dispatch, chatSDK, endChat) =>
53
53
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
54
  const conversationDetails = await getConversationDetailsCall(chatSDK);
55
55
  if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType) === ParticipantType.Bot) {
56
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
57
+ Event: TelemetryEvent.ConversationEndedThreadEventReceived,
58
+ Description: "Conversation end by bot or timeout event received."
59
+ });
56
60
  dispatch({
57
61
  type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
58
62
  payload: ConversationEndEntity.Bot
59
63
  });
60
64
  } else {
65
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
66
+ Event: TelemetryEvent.ConversationEndedThreadEventReceived,
67
+ Description: "Conversation end by agent or timeout event received."
68
+ });
61
69
  dispatch({
62
70
  type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
63
71
  payload: ConversationEndEntity.Agent
@@ -69,10 +77,6 @@ export const initWebChatComposer = (props, state, dispatch, chatSDK, endChat) =>
69
77
  payload: conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.participantType
70
78
  });
71
79
  }
72
- TelemetryHelper.logActionEvent(LogLevel.INFO, {
73
- Event: TelemetryEvent.ConversationEndedThreadEventReceived,
74
- Description: "Conversation end by agent side or by timeout event received."
75
- });
76
80
  };
77
81
  webChatStore = createStore({},
78
82
  //initial state
@@ -7,7 +7,7 @@ import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidge
7
7
  import { callingStateCleanUp, endChatStateCleanUp, closeChatStateCleanUp, chatSDKStateCleanUp } from "./endChat";
8
8
  import { DataStoreManager } from "../../../common/contextDataStore/DataStoreManager";
9
9
  import { getWidgetCacheIdfromProps } from "../../../common/utils";
10
- import { WidgetLoadCustomErrorString, WidgetLoadTelemetryMessage } from "../../../common/Constants";
10
+ import { PrepareEndChatDescriptionConstants, WidgetLoadCustomErrorString, WidgetLoadTelemetryMessage } from "../../../common/Constants";
11
11
  import { StartChatFailureType } from "../../../contexts/common/StartChatFailureType";
12
12
 
13
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -134,11 +134,12 @@ const logWidgetLoadCompleteWithError = ex => {
134
134
 
135
135
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
136
  const forceEndChat = chatSDK => {
137
- TelemetryHelper.logLoadingEvent(LogLevel.ERROR, {
138
- Event: TelemetryEvent.WidgetLoadFailed,
139
- ExceptionDetails: {
140
- Exception: "SessionInit was successful, but widget load failed."
141
- }
137
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
138
+ Event: TelemetryEvent.PrepareEndChat,
139
+ Description: PrepareEndChatDescriptionConstants.WidgetLoadFailedAfterSessionInit
140
+ });
141
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
142
+ Event: TelemetryEvent.EndChatSDKCall
142
143
  });
143
144
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
144
145
  };
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { BroadcastService, BroadcastServiceInitialize, decodeComponentString } from "@microsoft/omnichannel-chat-components";
4
4
  import { Components } from "botframework-webchat";
5
- import { ConfirmationState, Constants, ConversationEndEntity, E2VVOptions, LiveWorkItemState, StorageType } from "../../../common/Constants";
5
+ import { ConfirmationState, Constants, ConversationEndEntity, E2VVOptions, LiveWorkItemState, PrepareEndChatDescriptionConstants, StorageType } from "../../../common/Constants";
6
6
  import { Stack } from "@fluentui/react";
7
7
  import React, { useEffect, useRef, useState } from "react";
8
8
  import { checkIfConversationStillValid, initStartChat, prepareStartChat, setPreChatAndInitiateChat } from "../common/startChat";
@@ -405,9 +405,23 @@ export const LiveChatWidgetStateful = props => {
405
405
 
406
406
  // End chat
407
407
  BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
408
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
409
+ Event: TelemetryEvent.EndChatEventReceived,
410
+ Description: "Received InitiateEndChat BroadcastEvent."
411
+ });
412
+
408
413
  // This is to ensure to get latest state from cache in multitab
409
414
  const persistedState = getStateFromCache(getWidgetCacheIdfromProps(props));
410
415
  if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
416
+ // We need to simulate states for closing chat, in order to messup with close confirmation pane.
417
+ dispatch({
418
+ type: LiveChatWidgetActionType.SET_CONFIRMATION_STATE,
419
+ payload: ConfirmationState.Ok
420
+ });
421
+ dispatch({
422
+ type: LiveChatWidgetActionType.SET_SHOW_CONFIRMATION,
423
+ payload: false
424
+ });
411
425
  dispatch({
412
426
  type: LiveChatWidgetActionType.SET_CONVERSATION_ENDED_BY,
413
427
  payload: ConversationEndEntity.Customer
@@ -415,6 +429,10 @@ export const LiveChatWidgetStateful = props => {
415
429
  } else {
416
430
  const skipEndChatSDK = true;
417
431
  const skipCloseChat = false;
432
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
433
+ Event: TelemetryEvent.PrepareEndChat,
434
+ Description: PrepareEndChatDescriptionConstants.InitiateEndChatReceived
435
+ });
418
436
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
419
437
  }
420
438
  BroadcastService.postMessage({
@@ -432,6 +450,10 @@ export const LiveChatWidgetStateful = props => {
432
450
  BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
433
451
  var _msg$payload9;
434
452
  if ((msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
453
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
454
+ Event: TelemetryEvent.PrepareEndChat,
455
+ Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
456
+ });
435
457
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
436
458
  endChatStateCleanUp(dispatch);
437
459
  chatSDKStateCleanUp(chatSDK);
@@ -562,12 +584,20 @@ export const LiveChatWidgetStateful = props => {
562
584
 
563
585
  // If start chat failed, and C2 is trying to close chat widget
564
586
  if (state !== null && state !== void 0 && (_state$appStates9 = state.appStates) !== null && _state$appStates9 !== void 0 && _state$appStates9.startChatFailed || (state === null || state === void 0 ? void 0 : (_state$appStates10 = state.appStates) === null || _state$appStates10 === void 0 ? void 0 : _state$appStates10.conversationState) === ConversationState.Postchat) {
587
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
588
+ Event: TelemetryEvent.PrepareEndChat,
589
+ Description: PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
590
+ });
565
591
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
566
592
  return;
567
593
  }
568
594
 
569
595
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
570
596
  if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === ConversationState.InActive) {
597
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
598
+ Event: TelemetryEvent.PrepareEndChat,
599
+ Description: PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
600
+ });
571
601
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
572
602
  return;
573
603
  }
@@ -620,6 +650,10 @@ export const LiveChatWidgetStateful = props => {
620
650
  Event: TelemetryEvent.BrowserUnloadEventStarted,
621
651
  Description: "Browser unload event received."
622
652
  });
653
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
654
+ Event: TelemetryEvent.PrepareEndChat,
655
+ Description: PrepareEndChatDescriptionConstants.BrowserUnload
656
+ });
623
657
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, false);
624
658
  // Clean local storage
625
659
  (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventId);
@@ -254,3 +254,15 @@ export declare class WidgetLoadCustomErrorString {
254
254
  static readonly AuthenticationFailedErrorString = "Authentication was not successful";
255
255
  static readonly NetworkErrorString = "Network Error";
256
256
  }
257
+ export declare class PrepareEndChatDescriptionConstants {
258
+ static readonly ConversationEndedByCustomerWithoutPostChat = "Conversation ended by customer. Post chat not configured or should not show.";
259
+ static readonly ConversationEndedByCustomerWithInvalidPostChat = "Conversation ended by customer. Post chat context is invalid.";
260
+ static readonly ConversationEndedBy = "Conversation ended by";
261
+ static readonly PrepareEndChatError = "There's an error while preparing to end chat. Closing chat widget.";
262
+ static readonly WidgetLoadFailedAfterSessionInit = "SessionInit was successful, but widget load failed. Ending chat to avoid ghost chats in OC.";
263
+ static readonly InitiateEndChatReceived = "Received InitiateEndChat BroadcastEvent while conversation state is not Active. Ending chat.";
264
+ static readonly EndChatReceivedFromOtherTabs = "Received EndChat BroadcastEvent from other tabs. Closing this chat.";
265
+ static readonly CustomerCloseChatOnFailureOrPostChat = "Customer is trying to close chat widget on start chat failure or post chat pane.";
266
+ static readonly CustomerCloseInactiveChat = "Chat was Inactive and customer is trying to close chat widget or refreshing the page.";
267
+ static readonly BrowserUnload = "Browser unload event received. Ending chat.";
268
+ }
@@ -110,6 +110,7 @@ export declare enum TelemetryEvent {
110
110
  StartChatSDKCall = "StartChatCall",
111
111
  StartChatEventRecevied = "StartChatEventReceived",
112
112
  EndChatSDKCall = "EndChatSDKCall",
113
+ PrepareEndChat = "PrepareEndChat",
113
114
  EndChatEventReceived = "EndChatEventReceived",
114
115
  WindowClosed = "WindowClosed",
115
116
  OnNewMessageFailed = "OnNewMessageFailed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.5.1-main.6b98130",
3
+ "version": "1.5.1-main.7897747",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -97,8 +97,8 @@
97
97
  "test:e2e:build": "yarn build-sample && cd automation_tests && yarn test",
98
98
  "test:visual": "jest -c jest.config.visual.cjs",
99
99
  "test:all": "yarn test:unit && yarn test:visual",
100
- "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx",
101
- "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx",
100
+ "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
101
+ "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
102
102
  "verify": "yarn install && yarn build-storybook && yarn test:all && yarn build && yarn storybook",
103
103
  "testpack": "yarn build && yarn pack",
104
104
  "build-sample": "yarn build && webpack --config ./webpack.config.cjs",
@@ -1,71 +0,0 @@
1
- "use strict";
2
-
3
- var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
4
- var _react = require("@testing-library/react");
5
- jest.mock("@microsoft/omnichannel-chat-sdk");
6
- describe("EmailTranscriptPaneStateful unit test", () => {
7
- afterEach(() => {
8
- _react.cleanup;
9
- jest.resetAllMocks();
10
- });
11
- it("Method emailLiveChatTranscript is called", async () => {
12
- const omnichannelConfig = {
13
- orgUrl: "",
14
- orgId: "",
15
- widgetId: ""
16
- };
17
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
18
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockResolvedValue(Promise.resolve());
19
- const chatTranscriptBody = {
20
- emailAddress: "sample@microsoft.com",
21
- attachmentMessage: "sample",
22
- locale: "sample"
23
- };
24
- try {
25
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
26
- expect(chatSDK.emailLiveChatTranscript).toHaveBeenCalledTimes(1);
27
- // eslint-disable-next-line no-empty
28
- } catch (ex) {}
29
- });
30
- it("Method emailLiveChatTranscript throws exception", async () => {
31
- const errorMessage = "Error";
32
- const omnichannelConfig = {
33
- orgUrl: "",
34
- orgId: "",
35
- widgetId: ""
36
- };
37
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
38
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockRejectedValue(new Error(errorMessage));
39
- const chatTranscriptBody = {
40
- emailAddress: "sample@microsoft.com",
41
- attachmentMessage: "sample",
42
- locale: "sample"
43
- };
44
- try {
45
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- } catch (ex) {
48
- expect(ex.message).toEqual(errorMessage);
49
- }
50
- });
51
- it("Method emailLiveChatTranscript undefined throws exception", async () => {
52
- const errorMessage = "Error";
53
- const omnichannelConfig = {
54
- orgUrl: "",
55
- orgId: "",
56
- widgetId: ""
57
- };
58
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
59
- const chatTranscriptBody = {
60
- emailAddress: "sample@microsoft.com",
61
- attachmentMessage: "sample",
62
- locale: "sample"
63
- };
64
- try {
65
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- } catch (ex) {
68
- expect(ex.message).toEqual(errorMessage);
69
- }
70
- });
71
- });