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>;
/// <reference path="uiEventsFramework.d.ts"/>
const insightContext: IInsightContext = await recordContext.getInsightsContext();
const insightContext = await recordContext.getInsightsContext();
Functions
subscribe
Use this function to get response data for for Set FieldValue subscription.
subscribe: (payload: IEventSubscriptionPayload, callbackFunction: (response:IEventResponsePayload) => void) => ISubscriptionContext;
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. |
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());
});
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.
subscribeOnce: (payload: IEventSubscriptionPayload, callbackFunction: (response: IEventResponsePayload) => void => ISubscriptionContext;
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. |
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());
});
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.
ublish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
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());
});
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.
dispose:() => void;
getSupportedEvents
This method will return all the supported events on top of globalContext.
getSupportedEvents(): string[];
getSupportedActions
This method will return all the supported actions on top of GlobalContext.
getSupportedActions(): string[];