Listen to actions given in the notification
Here's a Typescript example to listen to the action triggered in the notification. Below code contains code to listen action of already opened notification with id notificationId007:
const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
let notificationContext: INotificationContext = await frameworkProvider.getNotificationContext('notificationId007');
const requestObject:IEventRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnNotificationActionEvent') as IEventRequest;
notificationContext.subscribe(requestObject, (response) => {
const resp: INotificationActionEventResponse = response as INotificationActionEventResponse;
console.log(resp.getResponseData().getNotificationId())
console.log(resp.getResponseData().getActionId())
console.log(resp.getResponseData().getActionName())
});
Here's a Typescript. The first part is to open a notification with id, notificationId007.
Once it's opened and the result is success, we can add the code to listen actions
triggered in the notification. In this example, 2 actions are added, Join call and
reject call. These two actions will show as buttons in the notification. Once any of
this buttons clicked, can listen to that particular action triggered with details
including action id and action name. :
const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
let notificationContext: INotificationContext = await frameworkProvider.getNotificationContext('notificationId007');
const requestObject: IShowNotificationRequest = frameworkProvider.requestHelper.createPublishRequest('ShowNotification') as IShowNotificationRequest;
requestObject.setTitle('title');
requestObject.setActions([{id: 'join', name: 'Join Call'}, {id: 'reject', name: 'Reject Call'}]);
notificationContext.publish(requestObject).then((message) => {
const response: INotificationOperationResponse = message as INotificationOperationResponse;
//given below is the code to listen to actions triggered in the notification of this notification
const requestObject:IEventRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnNotificationActionEvent') as IEventRequest;
notificationContext.subscribe(requestObject, (response) => {
const resp: INotificationCloseActionEventResponse = response as INotificationCloseActionEventResponse;
console.log(resp.getResponseData().getNotificationId());
console.log(resp.getResponseData().getActionId());
console.log(resp.getResponseData().getActionName());
});
});
Here's a JavaScript example to listen to the action triggered in the notification. Below
code contains code to listen action of already opened notification with id
notificationId007:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
let notificationContext = await frameworkProvider.getNotificationContext('notificationId007');
const requestObject = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnNotificationActionEvent');
notificationContext.subscribe(requestObject, (response) => {
console.log(response.getResponseData().getNotificationId())
console.log(response.getResponseData().getActionId())
console.log(response.getResponseData().getActionName())
});
Here's a JavaScript example to listen to to open a notification with id,
notificationId007. Once it's opened and the result is success, we can add the code to
listen actions triggered in the notification. In this example, 2 actions are added, Join
call and reject call. These two actions will show as buttons in the notification. Once
any of this buttons clicked, we can listen to that particular action triggered with
details including action id and action name. :
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID', 'v1');
let notificationContext = await frameworkProvider.getNotificationContext('notificationId007');
const requestObject = frameworkProvider.requestHelper.createPublishRequest('ShowNotification');
requestObject.setTitle('title');
requestObject.setActions([{id: 'join', name: 'Join Call'}, {id: 'reject', name: 'Reject Call'}]);
notificationContext.publish(requestObject).then((message) => {
//given below is the code to listen to actions triggered in the notification of this notification
const requestObject = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusOnNotificationActionEvent');
notificationContext.subscribe(requestObject, (response) => {
console.log(response.getResponseData().getNotificationId());
console.log(response.getResponseData().getActionId());
console.log(response.getResponseData().getActionName());
});
});