Receive notification of GCM submission in node.js application

I am creating a command line application in node.js and would like to receive GCM push notifications (the application from the command line will interact with the same set of services as iOS / Android applications, so it requires using the same notification service).

Given that GCM can be used on iOS (and therefore does not depend on Android), I hope that it can be used from node.js.

I saw a lot of articles about sending push notifications from node.js, but could not find anything about using node.js on the receiving side.

+4
source share
4 answers

, push-, ios andriod, fcm , gcm,

router.post('/pushmessage', function (req, res) {
    var serverKey = '';//put server key here
    var fcm = new FCM(serverKey);
    var token = "";// put token here which user you have to send push notification
    var message = {
        to: token,
        collapse_key: 'your_collapse_key',
        notification: {title: 'hello', body: 'test'},
        data: {my_key: 'my value', contents: "abcv/"}
    };
    fcm.send(message, function (err, response) {
        if (err) {
            res.json({status: 0, message: err});
        } else {
            res.json({status: 1, message: response});
        }
    });
});
+9

, ( )...

Android/iOS , GCM...

CLI, (Linux, Windows Mac), .

+1

GCM , iOS/Android, push-. , .

+1

, .

Push , . , push- ( , , ), , . , . , , push .

, , push .

Push , API: push , ; - - script, .

self.addEventListener('push', function(event) {
  const promiseChain = getData(event.data)
  .then(data => {
    return self.registration.getNotifications({tag: data.tag});
  })
  .then(notifications => {
    //Do something with the notifications.
  });
  event.waitUntil(promiseChain);
});

https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/handling-messages

0
source

Source: https://habr.com/ru/post/1663543/


All Articles