Listen Insights dismiss event with reason

In the close response, you can get the reason of close from getReason function. It gives 3 reasons in response:

  1. PROGRAMMATIC if the insights closed by dismiss insights action from UEF
  2. MANUAL if the notification closed by clicking the dismiss link in the insights.
  3. ACTION if the notification closed by clicking the action given.

Here's a Typescript example:

const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'V1');
const tabContext: ITabContext = await frameworkProvider.getCurrentBrowserTabContext()
let recordContext: IRecordContext = await tabContext.getActiveRecord();         
let insightContext: IInsightsContext = await recordContext.getInsightsContext();
const payload: IInsightsSubscriptionRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent') as IInsightsSubscriptionRequest;
payload.setId('insightsId1');
insightContext.subscribe(payload, (response: IEventResponse ) => { 
    const insightsDismissActionEventResponse = response as IInsightsDismissActionEventResponse;
	console.log((insightsDismissActionEventResponse.getResponseData() as IInsightsDismissActionData).getInsightsId());
	console.log((insightsDismissActionEventResponse.getResponseData() as IInsightsDismissActionData).getReason()); 
});

Here's a JavaScript example:

const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'V1');
 const tabContext = await frameworkProvider.getCurrentBrowserTabContext();
 let recordContext = await tabContext.getActiveRecord();
 let insightContext = await recordContext.getInsightsContext();
 const payload = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent');
 payload.setId('insightsId1');
 insightContext.subscribe(payload, (response) => {
     const insightsDismissActionEventResponse = response;
     console.log(insightsDismissActionEventResponse.getResponseData().getInsightsId());
     console.log(insightsDismissActionEventResponse.getResponseData().getReason());
 });