A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages
Via npm:
$ npm install fcm-node
var FCM = require('fcm-node');
var serverKey = '';
var fcm = new FCM(serverKey);
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: 'registration_token',
collapse_key: 'your_collapse_key',
notification: {
title: 'Title of your push notification',
body: 'Body of your push notification'
},
data: { //you can send only notification or only data(or include both)
my_key: 'my value',
my_another_key: 'my another value'
}
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response: ", response);
}
});
- See FCM documentation for general details.
- See Firebase Cloud Messaging HTTP Protocol for details about the HTTP syntax used and JSON fields, notification and data objects. (STRONGLY RECOMMENDED)
- On iOS, set content_available when the app server needs to send a Send-to-Sync message. An inactive client app executes your logic in the background, while an app in the foreground passes the message to didReceiveRemoteNotification. (As seen in FCM Docs)
- Some iOS users report a delay receiving the notifications and even a 'not receive at all' scenario if the priority field is not set. This is due to a delivery policy with APN (See APNs Provider API for a more detailed info)
Extended by Leonardo Pereira. 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
GNU LESSER GENERAL PUBLIC LICENSE v3
1.0.10 - <FIX> send function return only error object when multicast messages returned both error and success keys on response message
1.0.9 - Updated Documentation
1.0.8 - <FIX> 'icon' field no longer required in notification
1.0.7 - renaming repository
1.0.6 - bugfix: send function was always returning an error object for multicast messages (multiple registration ids)
1.0.5 - bugfix with UTF-8 enconding and chunk-encoded transfers
1.0.1 - forked from fcm-push and extended to accept topic messages without errors