fcm-push-notif

1.2.1 • Public • Published

fcm-push-notif

A Node.JS simple interface to Firebase Cloud Messaging (FCM) for Android and iOS

Installation

Via npm:

$ npm install fcm-push-notif

Usage

var FCM = require('fcm-push-notif');

var serverKey = 'your_own_server_key';
var fcm = new FCM(serverKey);

var message = {
    to: 'registration_token_or_topics', // required fill with device token or topics
    collapse_key: 'your_collapse_key', 
    data: {
        your_custom_data_key: 'your_custom_data_value'
    },
    notification: {
        title: 'Title of your push notification',
        body: 'Body of your push notification'
    }
};

//callback style
fcm.send(message, function(err, response){
    if (err) {
        console.log("Something has gone wrong!");
    } else {
        console.log("Successfully sent with response: ", response);
    }
});

//promise style
fcm.send(message)
    .then(function(response){
        console.log("Successfully sent with response: ", response);
    })
    .catch(function(err){
        console.log("Something has gone wrong!");
        console.error(err);
    })

See FCM documentation for details.

Credits

Extended by ans4175. Based on the great work on fcm-push by Rasmunandar Rustam cloned and modified from there, which in its turn, was cloned and modified from Changshin Lee's node-gcm

License

The MIT License

Copyright (c) 2016 eFishery

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Changelog

1.1.1

  • Remove unused dependency

1.1.0

  • Add ability to send topic (by @ans-4175)
  • Multicast, now using promise style bluebirdjs (by @misugijunz)
  • Support callback on promise (by @misugijunz)
  • Fixed NotRegistered bug (credit to Saber-Technologies solution)

1.0.7

  • Fixed calling the inherits function before declaring .prototype.send function instead of after (thanks to @dnunes)

1.0.6:

  • Fixed the length calculation for strings with special UTF-8 characters (ie. german umlauts) which caused FCM errors (by @denisu)

1.0.5:

  • Major yet silly bug fix in index.js

1.0.3:

  • README updated

1.0.1:

  • README added

1.0.0:

  • Initial release

Package Sidebar

Install

npm i fcm-push-notif

Weekly Downloads

1

Version

1.2.1

License

MIT

Last publish

Collaborators

  • ans4175