1. Miscellaneous
  2. Triggering and Responding to Push Notifications

Miscellaneous

Triggering and Responding to Push Notifications

INFO

Push notifications are not enabled by default for all apps. If you want us to enable them in your app then email us at [email protected].

Start a push notifications service

To start the push notifications service all you need is a sender ID.

        import { pushNotifications } from '@todesktop/client-core';

pushNotifications.start('12345678901');

      

Respond to push notification "start" events

Triggered when the push notifications service is started successfully and an FCM registration token has been received.

        import { pushNotifications } from '@todesktop/client-core';

pushNotifications.on('start', (e, token) => {
  console.log(`Your FCM token is: ${token}`);
});

      

Respond to push notification "receive" events

Triggered when a push notifications service is received.

        import { pushNotifications } from '@todesktop/client-core';

pushNotifications.on('receive', (e, notification) => {
  console.log(notification);
  /**
   * {
   * 	"from": "14017693762",
   * 	"priority": "normal",
   * 	"notification": {
   * 		"title": "Hello World",
   * 		"body": "FooBar"
   * 	},
   * 	"collapse_key": "do_not_collapse"
   * }
   **/
});

      

Respond to push notification "error" events

Triggered when the push notifications service is started successfully and an FCM registration token has been received.

        import { pushNotifications } from '@todesktop/client-core';

pushNotifications.on('error', (e, error) => {
  // Notify user of error
});

      

Respond to push notification "tokenUpdate" events

Triggered when the FCM registration token has been updated.

        import { pushNotifications } from '@todesktop/client-core';

pushNotifications.on('tokenUpdate', (e, token) => {
  console.log(`Your FCM token has been updated to: ${token}`);
});