How to send Push Notifications in OpenFin?

414 Views Asked by At

I have to Push Notifications to all the users who are using OpenFin for my site. As per OpenFin documentation, they have provided API to send a Desktop Notification on an event like button click. But if the OpenFin App is Idle and we need send notifications then how can I achieve that?

I went through the example on this site provided by OpenFin.

Can anyone help with sample code for push Notification in javascript ?

2

There are 2 best solutions below

0
Varun Goel On

The example provided in the link is outdated as it uses old Openfin API. I suggest you to use latest API for notifications Openfin Notification API

fin.Notification.create({
    url: 'https://cdn.openfin.co/docs/javascript/stable/tutorial-Notification.create.html',
    timeout: 3000
}).show().then(() => console.log('Notification created')).catch(err => console.log(err));
0
Harsh Phoujdar On

You will need to install openfin-notifications using npm i openfin-notifications. Once it is installed, import it and use it like Varun mentioned

import {create} from 'openfin-notifications';

create({
    title : 'my-title',
    body : 'Any additional content',
    category : 'Event',
    buttons : [
        {
            title : 'Accept'
            onClick : {
            task : 'click-me'
            }
        }
    ]
});