@microsoft/omnichannel-chat-widget 1.8.4-main.7bdb634 → 1.8.4-main.c687f88

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 (104) hide show
  1. package/README.md +27 -0
  2. package/lib/cjs/common/Constants.js +3 -0
  3. package/lib/cjs/common/telemetry/AppInsightsEvents.js +14 -9
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +15 -2
  5. package/lib/cjs/common/telemetry/TelemetryManager.js +10 -7
  6. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +29 -13
  7. package/lib/cjs/common/utils.js +14 -1
  8. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
  9. package/lib/cjs/components/citationpanestateful/CitationPaneStateful.js +20 -1
  10. package/lib/cjs/components/errorboundary/ErrorBoundary.js +2 -1
  11. package/lib/cjs/components/headerstateful/HeaderStateful.js +8 -2
  12. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +1 -1
  13. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +26 -20
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +1 -2
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +26 -9
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +9 -2
  17. package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +36 -4
  18. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
  19. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  20. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  21. package/lib/cjs/components/livechatwidget/common/startChat.js +5 -1
  22. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +24 -4
  23. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +124 -28
  24. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +37 -8
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +12 -3
  26. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +28 -30
  27. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +12 -12
  28. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  29. package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +1 -3
  30. package/lib/cjs/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +6 -7
  32. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +30 -1
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +21 -1
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +7 -2
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +3 -0
  36. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
  37. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
  38. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
  39. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
  40. package/lib/cjs/contexts/createReducer.js +15 -0
  41. package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  42. package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  43. package/lib/cjs/plugins/newMessageEventHandler.js +4 -1
  44. package/lib/esm/common/Constants.js +3 -0
  45. package/lib/esm/common/telemetry/AppInsightsEvents.js +14 -9
  46. package/lib/esm/common/telemetry/TelemetryConstants.js +13 -1
  47. package/lib/esm/common/telemetry/TelemetryManager.js +10 -7
  48. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +30 -14
  49. package/lib/esm/common/utils.js +11 -0
  50. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +17 -5
  51. package/lib/esm/components/citationpanestateful/CitationPaneStateful.js +20 -1
  52. package/lib/esm/components/errorboundary/ErrorBoundary.js +4 -2
  53. package/lib/esm/components/headerstateful/HeaderStateful.js +9 -3
  54. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +1 -1
  55. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +26 -20
  56. package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +1 -2
  57. package/lib/esm/components/livechatwidget/common/endChat.js +26 -9
  58. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +9 -2
  59. package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +33 -2
  60. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +3 -0
  61. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  62. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  63. package/lib/esm/components/livechatwidget/common/startChat.js +7 -3
  64. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +23 -4
  65. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +125 -29
  66. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +39 -10
  67. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +13 -4
  68. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +29 -34
  69. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +12 -12
  70. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  71. package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +1 -3
  72. package/lib/esm/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.js +1 -0
  73. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +6 -7
  74. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +30 -1
  75. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +21 -1
  76. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +7 -2
  77. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +3 -0
  78. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware.js +1 -0
  79. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +6 -1
  80. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.js +29 -7
  81. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
  82. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +7 -1
  83. package/lib/esm/contexts/createReducer.js +15 -0
  84. package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  85. package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  86. package/lib/esm/plugins/newMessageEventHandler.js +4 -1
  87. package/lib/types/common/Constants.d.ts +3 -0
  88. package/lib/types/common/telemetry/TelemetryConstants.d.ts +12 -1
  89. package/lib/types/common/telemetry/interfaces/IInternalTelemetryData.d.ts +1 -0
  90. package/lib/types/common/utils.d.ts +9 -1
  91. package/lib/types/components/errorboundary/ErrorBoundary.d.ts +1 -1
  92. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +1 -1
  93. package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +11 -0
  94. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
  95. package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +5 -1
  96. package/lib/types/components/webchatcontainerstateful/interfaces/IExtendedChatConffig.d.ts +15 -0
  97. package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +1 -2
  98. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +1 -1
  99. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +2 -1
  100. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/localizedStringsBotInitialsMiddleware.d.ts +1 -1
  101. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  102. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +5 -0
  103. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
  104. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
2
+ import { BroadcastEvent, ConversationStage, 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
5
  import { ConfirmationState, Constants, ConversationEndEntity, E2VVOptions, LiveWorkItemState, PrepareEndChatDescriptionConstants, StorageType, WidgetLoadCustomErrorString } from "../../../common/Constants";
@@ -54,14 +54,18 @@ import { startProactiveChat } from "../common/startProactiveChat";
54
54
  import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
55
55
  import useChatContextStore from "../../../hooks/useChatContextStore";
56
56
  import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
57
+ import { getPostChatContext, initiatePostChat } from "../common/renderSurveyHelpers";
57
58
  let uiTimer;
58
59
  export const LiveChatWidgetStateful = props => {
59
- var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$styleProps, _props$webChatContain10, _props$webChatContain11, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain15, _state$appStates14, _props$webChatContain17, _props$webChatContain18, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
60
+ var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _props$webChatContain5, _props$webChatContain6, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$styleProps, _props$webChatContain10, _props$webChatContain11, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain15, _state$appStates8, _props$webChatContain17, _props$webChatContain18, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
60
61
  useEffect(() => {
61
62
  uiTimer = createTimer();
62
63
  TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
63
64
  Event: TelemetryEvent.UXLiveChatWidgetStart,
64
- Description: "Live chat widget loading started."
65
+ Description: "Live chat widget loading started.",
66
+ CustomProperties: {
67
+ ConversationStage: ConversationStage.Initialization
68
+ }
65
69
  });
66
70
  }, []);
67
71
  const [state, dispatch] = useChatContextStore();
@@ -314,7 +318,7 @@ export const LiveChatWidgetStateful = props => {
314
318
  });
315
319
  });
316
320
  BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
317
- TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
321
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
318
322
  Event: TelemetryEvent.StartProactiveChatEventReceived,
319
323
  Description: "Start proactive chat event received."
320
324
  });
@@ -440,7 +444,7 @@ export const LiveChatWidgetStateful = props => {
440
444
  payload: msg === null || msg === void 0 ? void 0 : (_msg$payload8 = msg.payload) === null || _msg$payload8 === void 0 ? void 0 : _msg$payload8.customContext
441
445
  });
442
446
  }
443
- TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
447
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
444
448
  Event: TelemetryEvent.StartChatEventReceived,
445
449
  Description: "Start chat event received."
446
450
  });
@@ -487,18 +491,91 @@ export const LiveChatWidgetStateful = props => {
487
491
  return;
488
492
  }
489
493
  });
494
+ const handleInitiateEndChatForPersistentChat = async (msg, conversationDetails) => {
495
+ var _msg$payload10, _msg$payload11, _msg$payload12;
496
+ //If the payload does NOT include the skipSessionCloseForPersistentChat flag, default is false. Upon receiving the customer event, always ending session from C2.
497
+ const skipSessionCloseForPersistentChat = typeof (msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10[Constants.SkipSessionCloseForPersistentChatFlag]) === Constants.String && (msg === null || msg === void 0 ? void 0 : (_msg$payload11 = msg.payload) === null || _msg$payload11 === void 0 ? void 0 : _msg$payload11[Constants.SkipSessionCloseForPersistentChatFlag]).toLowerCase() === Constants.true || (msg === null || msg === void 0 ? void 0 : (_msg$payload12 = msg.payload) === null || _msg$payload12 === void 0 ? void 0 : _msg$payload12[Constants.SkipSessionCloseForPersistentChatFlag]) === true;
498
+ TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
499
+ Event: TelemetryEvent.EndChatEventReceived,
500
+ Description: "Processing initiateEndChat for persistent chat",
501
+ CustomProperties: {
502
+ conversationDetails
503
+ }
504
+ });
505
+ const conversationState = conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state;
506
+ if (conversationState !== LiveWorkItemState.Closed && conversationState !== LiveWorkItemState.WrapUp) {
507
+ if (skipSessionCloseForPersistentChat) {
508
+ var _conversationDetails$;
509
+ if (((_conversationDetails$ = conversationDetails.canRenderPostChat) === null || _conversationDetails$ === void 0 ? void 0 : _conversationDetails$.toLowerCase()) === "true") {
510
+ var _state$domainStates3;
511
+ TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
512
+ Event: TelemetryEvent.EndChatEventReceived,
513
+ Description: "Processing initiateEndChat, fetching postChatContext"
514
+ });
515
+ const postchatContext = (await getPostChatContext(facadeChatSDK, state, dispatch)) ?? (state === null || state === void 0 ? void 0 : (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : _state$domainStates3.postChatContext);
516
+ if (postchatContext) {
517
+ TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
518
+ Event: TelemetryEvent.EndChatEventReceived,
519
+ Description: "Processing initiateEndChat, initiatePostChat",
520
+ CustomProperties: {
521
+ postchatContext
522
+ }
523
+ });
524
+ await initiatePostChat(props, conversationDetails, state, dispatch, postchatContext);
525
+ }
526
+ }
527
+ } else {
528
+ const skipEndChatSDK = false;
529
+ const skipCloseChat = false;
530
+ TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
531
+ Event: TelemetryEvent.EndChatEventReceived,
532
+ Description: "Processing initiateEndChat, trigger endChat"
533
+ });
534
+ await endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
535
+ }
536
+ }
537
+ //if conversation already closed, it is safe to unmount it upon receiving the closeChat event
538
+ else {
539
+ BroadcastService.postMessage({
540
+ eventName: BroadcastEvent.CloseChat
541
+ });
542
+ }
543
+ };
490
544
 
491
545
  // End chat
492
- BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
546
+ BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async msg => {
493
547
  TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
494
548
  Event: TelemetryEvent.EndChatEventReceived,
495
- Description: "Received InitiateEndChat BroadcastEvent."
549
+ Description: "Received InitiateEndChat BroadcastEvent.",
550
+ CustomProperties: {
551
+ ConversationStage: ConversationStage.ConversationEnd,
552
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
553
+ }
496
554
  });
497
-
498
- // This is to ensure to get latest state from cache in multitab
555
+ const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
556
+ const {
557
+ chatConfig
558
+ } = props;
559
+ const isPersistent = isPersistentEnabled(chatConfig);
560
+ TelemetryHelper.logSDKEventToAllTelemetry(LogLevel.INFO, {
561
+ Event: TelemetryEvent.EndChatEventReceived,
562
+ Description: "Processing initiateEndChat, fetched conversation details",
563
+ CustomProperties: {
564
+ conversationDetails,
565
+ isPersistent
566
+ }
567
+ });
568
+ if (isPersistent && conversationDetails) {
569
+ await handleInitiateEndChatForPersistentChat(msg, conversationDetails);
570
+ return;
571
+ }
499
572
  const persistedState = getStateFromCache(getWidgetCacheIdfromProps(props));
500
573
  if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
501
- // We need to simulate states for closing chat, in order to messup with close confirmation pane.
574
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
575
+ Event: TelemetryEvent.PrepareEndChat,
576
+ Description: PrepareEndChatDescriptionConstants.InitiateEndChatReceivedActiveChat
577
+ });
578
+ //We need to simulate states for closing chat, in order to messup with close confirmation pane.
502
579
  dispatch({
503
580
  type: LiveChatWidgetActionType.SET_CONFIRMATION_STATE,
504
581
  payload: ConfirmationState.Ok
@@ -518,11 +595,8 @@ export const LiveChatWidgetStateful = props => {
518
595
  Event: TelemetryEvent.PrepareEndChat,
519
596
  Description: PrepareEndChatDescriptionConstants.InitiateEndChatReceived
520
597
  });
521
- endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
598
+ await endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
522
599
  }
523
- BroadcastService.postMessage({
524
- eventName: BroadcastEvent.CloseChat
525
- });
526
600
  });
527
601
 
528
602
  // End chat on browser unload
@@ -533,8 +607,8 @@ export const LiveChatWidgetStateful = props => {
533
607
  // Listen to end chat event from other tabs
534
608
  const endChatEventName = getWidgetEndChatEventName((_facadeChatSDK$getCha3 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha3 === void 0 ? void 0 : (_facadeChatSDK$getCha4 = _facadeChatSDK$getCha3.omnichannelConfig) === null || _facadeChatSDK$getCha4 === void 0 ? void 0 : _facadeChatSDK$getCha4.orgId, (_facadeChatSDK$getCha5 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha5 === void 0 ? void 0 : (_facadeChatSDK$getCha6 = _facadeChatSDK$getCha5.omnichannelConfig) === null || _facadeChatSDK$getCha6 === void 0 ? void 0 : _facadeChatSDK$getCha6.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
535
609
  BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
536
- var _msg$payload10;
537
- if ((msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
610
+ var _msg$payload13;
611
+ if ((msg === null || msg === void 0 ? void 0 : (_msg$payload13 = msg.payload) === null || _msg$payload13 === void 0 ? void 0 : _msg$payload13.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
538
612
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
539
613
  Event: TelemetryEvent.PrepareEndChat,
540
614
  Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
@@ -576,8 +650,8 @@ export const LiveChatWidgetStateful = props => {
576
650
 
577
651
  // Retrieve convId
578
652
  BroadcastService.getMessageByEventName(BroadcastEvent.UpdateConversationDataForTelemetry).subscribe(msg => {
579
- var _msg$payload11, _msg$payload11$liveWo;
580
- if ((_msg$payload11 = msg.payload) !== null && _msg$payload11 !== void 0 && (_msg$payload11$liveWo = _msg$payload11.liveWorkItem) !== null && _msg$payload11$liveWo !== void 0 && _msg$payload11$liveWo.conversationId) {
653
+ var _msg$payload14, _msg$payload14$liveWo;
654
+ if ((_msg$payload14 = msg.payload) !== null && _msg$payload14 !== void 0 && (_msg$payload14$liveWo = _msg$payload14.liveWorkItem) !== null && _msg$payload14$liveWo !== void 0 && _msg$payload14$liveWo.conversationId) {
581
655
  setConversationId(msg.payload.liveWorkItem.conversationId);
582
656
  }
583
657
  });
@@ -695,14 +769,22 @@ export const LiveChatWidgetStateful = props => {
695
769
  }
696
770
  }, [state.domainStates.confirmationState]);
697
771
  useEffect(() => {
698
- var _state$appStates8, _state$appStates9, _state$appStates10, _state$appStates11, _state$appStates12, _state$appStates13;
772
+ var _inMemoryState$appSta7, _inMemoryState$appSta8, _inMemoryState$appSta9, _inMemoryState$appSta10, _inMemoryState$appSta11, _inMemoryState$appSta12, _inMemoryState$appSta13;
773
+ const inMemoryState = executeReducer(state, {
774
+ type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
775
+ payload: null
776
+ });
699
777
  // Do not process anything during initialization
700
- if ((state === null || state === void 0 ? void 0 : (_state$appStates8 = state.appStates) === null || _state$appStates8 === void 0 ? void 0 : _state$appStates8.conversationEndedBy) === ConversationEndEntity.NotSet) {
778
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta7 = inMemoryState.appStates) === null || _inMemoryState$appSta7 === void 0 ? void 0 : _inMemoryState$appSta7.conversationEndedBy) === ConversationEndEntity.NotSet) {
779
+ TelemetryHelper.logSDKEvent(LogLevel.INFO, {
780
+ Event: TelemetryEvent.PrepareEndChat,
781
+ Description: "conversationEndedBy is not set"
782
+ });
701
783
  return;
702
784
  }
703
785
 
704
786
  // If start chat failed, and C2 is trying to close chat widget
705
- 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) {
787
+ if (inMemoryState !== null && inMemoryState !== void 0 && (_inMemoryState$appSta8 = inMemoryState.appStates) !== null && _inMemoryState$appSta8 !== void 0 && _inMemoryState$appSta8.startChatFailed || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta9 = inMemoryState.appStates) === null || _inMemoryState$appSta9 === void 0 ? void 0 : _inMemoryState$appSta9.conversationState) === ConversationState.Postchat) {
706
788
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
707
789
  Event: TelemetryEvent.PrepareEndChat,
708
790
  Description: PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
@@ -712,7 +794,7 @@ export const LiveChatWidgetStateful = props => {
712
794
  }
713
795
 
714
796
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
715
- if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === ConversationState.InActive) {
797
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta10 = inMemoryState.appStates) === null || _inMemoryState$appSta10 === void 0 ? void 0 : _inMemoryState$appSta10.conversationState) === ConversationState.InActive) {
716
798
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
717
799
  Event: TelemetryEvent.PrepareEndChat,
718
800
  Description: PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
@@ -720,11 +802,11 @@ export const LiveChatWidgetStateful = props => {
720
802
  endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
721
803
  return;
722
804
  }
723
- const isConversationalSurveyEnabled = state.appStates.isConversationalSurveyEnabled;
805
+ const isConversationalSurveyEnabled = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta11 = inMemoryState.appStates) === null || _inMemoryState$appSta11 === void 0 ? void 0 : _inMemoryState$appSta11.isConversationalSurveyEnabled;
724
806
 
725
807
  // In conversational survey, we need to check post chat survey logics before we set ConversationState to InActive
726
808
  // Hence setting ConversationState to InActive will be done later in the post chat flows
727
- if (!isConversationalSurveyEnabled && ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === ConversationEndEntity.Bot)) {
809
+ if (!isConversationalSurveyEnabled && ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta12 = inMemoryState.appStates) === null || _inMemoryState$appSta12 === void 0 ? void 0 : _inMemoryState$appSta12.conversationEndedBy) === ConversationEndEntity.Agent || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta13 = inMemoryState.appStates) === null || _inMemoryState$appSta13 === void 0 ? void 0 : _inMemoryState$appSta13.conversationEndedBy) === ConversationEndEntity.Bot)) {
728
810
  dispatch({
729
811
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
730
812
  payload: ConversationState.InActive
@@ -732,8 +814,8 @@ export const LiveChatWidgetStateful = props => {
732
814
  }
733
815
 
734
816
  // All other cases
735
- prepareEndChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
736
- }, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
817
+ prepareEndChat(props, facadeChatSDK, inMemoryState, dispatch, setAdapter, setWebChatStyles, adapter);
818
+ }, [state === null || state === void 0 ? void 0 : (_state$appStates8 = state.appStates) === null || _state$appStates8 === void 0 ? void 0 : _state$appStates8.conversationEndedBy]);
737
819
 
738
820
  // Publish chat widget state
739
821
  useEffect(() => {
@@ -765,13 +847,13 @@ export const LiveChatWidgetStateful = props => {
765
847
 
766
848
  // Handle Chat disconnect cases
767
849
  useEffect(() => {
768
- var _inMemoryState$appSta7;
850
+ var _inMemoryState$appSta14;
769
851
  const inMemoryState = executeReducer(state, {
770
852
  type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
771
853
  payload: null
772
854
  });
773
855
  handleChatDisconnect(props, inMemoryState, setWebChatStyles);
774
- const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta7 = inMemoryState.appStates) === null || _inMemoryState$appSta7 === void 0 ? void 0 : _inMemoryState$appSta7.chatDisconnectEventReceived;
856
+ const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta14 = inMemoryState.appStates) === null || _inMemoryState$appSta14 === void 0 ? void 0 : _inMemoryState$appSta14.chatDisconnectEventReceived;
775
857
  if (chatDisconnectState && adapter) {
776
858
  try {
777
859
  adapter.end();
@@ -797,7 +879,10 @@ export const LiveChatWidgetStateful = props => {
797
879
  TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
798
880
  Event: TelemetryEvent.UXLiveChatWidgetCompleted,
799
881
  Description: "Live chat widget loading completed.",
800
- ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed
882
+ ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed,
883
+ CustomProperties: {
884
+ ConversationStage: ConversationStage.Initialization
885
+ }
801
886
  });
802
887
  }, []);
803
888
  const initiateEndChatOnBrowserUnload = () => {
@@ -867,6 +952,17 @@ export const LiveChatWidgetStateful = props => {
867
952
  bubbleTextColor
868
953
  }), [webChatStyles, bubbleBackground, bubbleTextColor]);
869
954
 
955
+ // React to dynamic bot avatar initials updates from context
956
+ useEffect(() => {
957
+ if (state.domainStates.botAvatarInitials && state.domainStates.botAvatarInitials !== webChatStyles.botAvatarInitials) {
958
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
959
+ setWebChatStyles(styles => ({
960
+ ...styles,
961
+ botAvatarInitials: state.domainStates.botAvatarInitials
962
+ }));
963
+ }
964
+ }, [state.domainStates.botAvatarInitials]);
965
+
870
966
  // WebChat's Composer can only be rendered if a directLine object is defined
871
967
  return directLine && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("style", null, `
872
968
  #oc-lcw .webchat__basic-transcript__scrollable::-webkit-scrollbar {
@@ -1,4 +1,4 @@
1
- import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
1
+ import { ConversationStage, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
2
  import React, { useEffect } from "react";
3
3
  import { ParticipantType } from "../../common/Constants";
4
4
  import { CustomerVoiceEvents } from "./enums/CustomerVoiceEvents";
@@ -6,9 +6,10 @@ import { PostChatSurveyMode } from "./enums/PostChatSurveyMode";
6
6
  import { PostChatSurveyPane } from "@microsoft/omnichannel-chat-components";
7
7
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
8
8
  import { defaultGeneralPostChatSurveyPaneStyleProps } from "./common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps";
9
- import { findAllFocusableElement } from "../../common/utils";
9
+ import { createTimer, findAllFocusableElement } from "../../common/utils";
10
10
  import useChatContextStore from "../../hooks/useChatContextStore";
11
11
  import isValidSurveyUrl from "./common/isValidSurveyUrl";
12
+ let uiTimer;
12
13
  const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, compact, customerVoiceSurveyCorrelationId) {
13
14
  let showMultiLingual = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
14
15
  const surveyLinkParams = new URLSearchParams({
@@ -21,20 +22,32 @@ const generateSurveyInviteLink = function (surveyInviteLink, isEmbed, locale, co
21
22
  return `${surveyInviteLink}&${surveyLinkParams.toString()}`;
22
23
  };
23
24
  export const PostChatSurveyPaneStateful = props => {
24
- var _props$styleProps, _state$appStates, _props$controlProps;
25
+ var _props$styleProps, _state$appStates, _state$domainStates$p, _props$controlProps;
26
+ useEffect(() => {
27
+ uiTimer = createTimer();
28
+ TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
29
+ Event: TelemetryEvent.UXPostChatPaneStarted,
30
+ Description: "Postchat survey pane loading started.",
31
+ CustomProperties: {
32
+ ConversationStage: ConversationStage.ConversationEnd
33
+ }
34
+ });
35
+ }, []);
25
36
  const [state] = useChatContextStore();
26
37
  const generalStyleProps = Object.assign({}, defaultGeneralPostChatSurveyPaneStyleProps, (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyleProps, {
27
38
  display: state.appStates.isMinimized ? "none" : "contents"
28
39
  });
29
40
  let surveyInviteLink = "";
30
41
  const surveyMode = (state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.selectedSurveyMode) === PostChatSurveyMode.Embed;
31
- if (state.domainStates.postChatContext.botSurveyInviteLink &&
42
+ if ((_state$domainStates$p = state.domainStates.postChatContext) !== null && _state$domainStates$p !== void 0 && _state$domainStates$p.botSurveyInviteLink &&
32
43
  // Bot survey enabled
33
44
  state.appStates.postChatParticipantType === ParticipantType.Bot) {
45
+ var _state$domainStates$p2, _state$domainStates$p3;
34
46
  // Only Bot has engaged
35
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.botSurveyInviteLink, surveyMode, state.domainStates.postChatContext.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
47
+ surveyInviteLink = generateSurveyInviteLink((_state$domainStates$p2 = state.domainStates.postChatContext) === null || _state$domainStates$p2 === void 0 ? void 0 : _state$domainStates$p2.botSurveyInviteLink, surveyMode, (_state$domainStates$p3 = state.domainStates.postChatContext) === null || _state$domainStates$p3 === void 0 ? void 0 : _state$domainStates$p3.botFormsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
36
48
  } else {
37
- surveyInviteLink = generateSurveyInviteLink(state.domainStates.postChatContext.surveyInviteLink, surveyMode, state.domainStates.postChatContext.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
49
+ var _state$domainStates$p4, _state$domainStates$p5;
50
+ surveyInviteLink = generateSurveyInviteLink((_state$domainStates$p4 = state.domainStates.postChatContext) === null || _state$domainStates$p4 === void 0 ? void 0 : _state$domainStates$p4.surveyInviteLink, surveyMode, (_state$domainStates$p5 = state.domainStates.postChatContext) === null || _state$domainStates$p5 === void 0 ? void 0 : _state$domainStates$p5.formsProLocale, props.isCustomerVoiceSurveyCompact ?? true, props.customerVoiceSurveyCorrelationId || "");
38
51
  }
39
52
  if (props.copilotSurveyContext) {
40
53
  surveyInviteLink = `${surveyInviteLink}&mcs_additionalcontext=${JSON.stringify(props.copilotSurveyContext)}`;
@@ -72,7 +85,14 @@ export const PostChatSurveyPaneStateful = props => {
72
85
  TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
73
86
  Event: TelemetryEvent.PostChatSurveyLoaded
74
87
  });
75
-
88
+ TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
89
+ Event: TelemetryEvent.UXPostChatPaneCompleted,
90
+ ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed,
91
+ Description: "Postchat survey pane loading completed.",
92
+ CustomProperties: {
93
+ ConversationStage: ConversationStage.ConversationEnd
94
+ }
95
+ });
76
96
  //Customer Voice Telemetry Events
77
97
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
98
  window.addEventListener("message", message => {
@@ -85,16 +105,22 @@ export const PostChatSurveyPaneStateful = props => {
85
105
  Event: TelemetryEvent.CustomerVoiceResponsePageLoaded
86
106
  });
87
107
  } else if (data === CustomerVoiceEvents.FormResponseSubmitted) {
88
- TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
108
+ TelemetryHelper.logActionEvent(LogLevel.INFO, {
89
109
  Event: TelemetryEvent.CustomerVoiceFormResponseSubmitted,
90
- Description: "Customer Voice form response submitted."
110
+ Description: "Customer Voice form response submitted.",
111
+ CustomProperties: {
112
+ ConversationStage: ConversationStage.ConversationEnd
113
+ }
91
114
  });
92
115
  } else if (data === CustomerVoiceEvents.FormResponseError) {
93
- TelemetryHelper.logActionEventToAllTelemetry(LogLevel.ERROR, {
116
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
94
117
  Event: TelemetryEvent.CustomerVoiceFormResponseError,
95
118
  Description: "Customer Voice form response error.",
96
119
  ExceptionDetails: {
97
120
  message: "Customer Voice form response error."
121
+ },
122
+ CustomProperties: {
123
+ ConversationStage: ConversationStage.ConversationEnd
98
124
  }
99
125
  });
100
126
  } else if (typeof data === "string" && data.startsWith(CustomerVoiceEvents.FormsError)) {
@@ -103,6 +129,9 @@ export const PostChatSurveyPaneStateful = props => {
103
129
  Description: "Customer Voice failed to load with forms error.",
104
130
  ExceptionDetails: {
105
131
  message: `Customer Voice forms error details: ${data}`
132
+ },
133
+ CustomProperties: {
134
+ ConversationStage: ConversationStage.ConversationEnd
106
135
  }
107
136
  });
108
137
  }
@@ -1,5 +1,5 @@
1
1
  import { HtmlAttributeNames, Regex } from "../../common/Constants";
2
- import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
2
+ import { ConversationStage, LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
3
3
  import React, { useEffect } from "react";
4
4
  import { createTimer, extractPreChatSurveyResponseValues, findAllFocusableElement, getStateFromCache, getWidgetCacheId, isUndefinedOrEmpty, parseAdaptiveCardPayload } from "../../common/utils";
5
5
  import { ConversationState } from "../../contexts/common/ConversationState";
@@ -19,7 +19,10 @@ export const PreChatSurveyPaneStateful = props => {
19
19
  uiTimer = createTimer();
20
20
  TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
21
21
  Event: TelemetryEvent.UXPrechatPaneStart,
22
- Description: "Prechat survey pane loading started."
22
+ Description: "Prechat survey pane loading started.",
23
+ CustomProperties: {
24
+ ConversationStage: ConversationStage.Initialization
25
+ }
23
26
  });
24
27
  }, []);
25
28
 
@@ -70,7 +73,10 @@ export const PreChatSurveyPaneStateful = props => {
70
73
  onSubmit: async values => {
71
74
  TelemetryHelper.logActionEventToAllTelemetry(LogLevel.INFO, {
72
75
  Event: TelemetryEvent.PrechatSubmitted,
73
- Description: "Prechat survey submitted."
76
+ Description: "Prechat survey submitted.",
77
+ CustomProperties: {
78
+ ConversationStage: ConversationStage.Initialization
79
+ }
74
80
  });
75
81
  dispatch({
76
82
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -144,7 +150,10 @@ export const PreChatSurveyPaneStateful = props => {
144
150
  TelemetryHelper.logLoadingEventToAllTelemetry(LogLevel.INFO, {
145
151
  Event: TelemetryEvent.UXPrechatPaneCompleted,
146
152
  ElapsedTimeInMilliseconds: uiTimer.milliSecondsElapsed,
147
- Description: "Prechat survey pane loading completed."
153
+ Description: "Prechat survey pane loading completed.",
154
+ CustomProperties: {
155
+ ConversationStage: ConversationStage.Initialization
156
+ }
148
157
  });
149
158
  }, []);
150
159