IInsightsContext

IInsightsContext is available in the recordContext. IInsightsContext and provides the ability to listen to agent insights within the Composite Component Architecture (CCA) events and perform operations. For example, Publish new insights, Listening to Insights action trigger event and so on.

To get the reference to IInsightsContext, users can use the getInsightsContext function from recordContext. This function provides a reference to the insights.

Here's the syntax:

getInsightsContext(): Promise<IInsightsContext>;
Here's an example in Typescript:
/// <reference path="uiEventsFramework.d.ts"/> 
const insightContext: IInsightContext = await recordContext.getInsightsContext();
Here's an example in JavaScript:
const insightContext = await recordContext.getInsightsContext();

Functions

subscribe

Use this function to get response data for for Set FieldValue subscription.

This API can be used to subscribe to events on insights CCA.
subscribe: (payload: IEventSubscriptionPayload, callbackFunction: (response:IEventResponsePayload) => void) => ISubscriptionContext;

Parameters

Parameter Name Required? Description
payload Yes The request object for the event to be subscribed to.
callbackFunction Yes A callback function, where we get the event response as its arguments.
The following code sample shows an example in Typescript to listen to the dismissal event from Insights, considering recordContext as current browser tabs active record:
let recordContext: IRecordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext: IInsightContext = await recordContext.getInsightsContext();
const payload: IInsightsSubscriptionRequest = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent');
payload.setId('insightsId1');
insightContext.subscribe(requestObject, (response: IInsightsDismissActionEventResponse ) => { 
	console.log((response.getResponseData() as IInsightsDismissActionData).getInsightsId());
	console.log((response.getResponseData() as IInsightsDismissActionData).getReason()); 
}); 
The following code sample shows an example in JavaScript to listen to the dismissal event from Insights, considering recordContext as current browser tabs active record:
let recordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext = await recordContext.getInsightsContext();
const payload = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent');
payload.setId('insightsId1');
insightContext.subscribe(requestObject, (response ) => { 
	console.log(response.getResponseData().getInsightsId());
	console.log(response.getResponseData().getReason()); 
});

subscribeOnce

This API can be used to subscribe to a Fusion event just once. Using this API, external applications can listen to the application level events from the the Fusion application. But this subscription will be disposed of automatically after the first notification.

Here's the syntax:
subscribeOnce: (payload: IEventSubscriptionPayload, callbackFunction: (response: IEventResponsePayload) => void => ISubscriptionContext;

Parameters

Parameter Name Required? Description
payload Yes The request object for the event to be subscribed to.
callbackFunction Yes A callback function, where we get the event response as its arguments.
Here's a Typescript example:
let recordContext: IRecordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext: IInsightContext = await recordContext.getInsightsContext();
const payload: IInsightsSubscriptionRequest = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent');
payload.setId('insightsId1');
insightContext.subscribeOnce(requestObject, (response: IInsightsDismissActionEventResponse ) => { 
	console.log((response.getResponseData() as IInsightsDismissActionData).getInsightsId());
	console.log((response.getResponseData() as IInsightsDismissActionData).getReason()); 
});
Here's a JavaScript example:
let recordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext = await recordContext.getInsightsContext();
const payload = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusOnInsightsDismissActionEvent');
payload.setId('insightsId1');
insightContext.subscribeOnce(requestObject, (response ) => { 
	console.log(response.getResponseData().getInsightsId());
	console.log(response.getResponseData().getReason()); 
});

publish

This API can inform the Insights CCA to operate an action. The API will return a promise to which we can add a then-catch block. The then block would return the operation's status and any data returned after the process is completed.

Here's the syntax:
ublish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
Here's a Typescript example for the publish API used to publish the insight. Considering recordContext as current browser tabs active record:
let recordContext: IRecordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext: IInsightContext = await recordContext.getInsightsContext();
const payload: IShowInsightsRequest = uiEventsFrameworkInstance.requestHelper.createPublishRequest('ShowInsights');
payload.setId('insightsId1');
payload.setTitle('Custom title');
insightContext.publish(payload).then((response: IInsightsOperationResponse) => {
  console.log((response.getResponseData() as IInsightsOperationResponseData).getInsightsId());
}); 
Here's a JavaScript example:
let recordContext = await uiEventsFrameworkInstance.getCurrentBrowserTabContext().getActiveRecord();         
let insightContext = await recordContext.getInsightsContext();
const payload = uiEventsFrameworkInstance.requestHelper.createPublishRequest('ShowInsights');
payload.setId('insightsId1');
payload.setTitle('Custom title');
insightContext.publish(payload).then((response) => {
  console.log(response.getResponseData().getInsightsId());
});  

dispose

This API can dispose or unregister any subscriptions that's added for an event. By disposing the subscription, the API will not trigger any further notifications to the client side receiver.

Here's the syntax:
dispose:() => void;

getSupportedEvents

This method will return all the supported events on top of globalContext.

Here's the syntax:
getSupportedEvents(): string[];

getSupportedActions

This method will return all the supported actions on top of GlobalContext.

Here's the syntax:
getSupportedActions(): string[];