This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including @chandrashekar998/fcm-notify
with all npm
packages installed. Try it out:
/**
* Created by Leonardo on 02/08/2016.
*/
FCM = require('fcm-node');
var SERVER_API_KEY='your_api_key';//put your api key here
var validDeviceRegistrationToken = 'c1m7I:A ... bjj4SK-'; //put a valid device token here
var fcmCli= new FCM(SERVER_API_KEY);
var payloadOK = {
to: validDeviceRegistrationToken,
data: { //some data object (optional)
url: 'news',
foo:'fooooooooooooo',
bar:'bar bar bar'
},
priority: 'high',
content_available: true,
notification: { //notification object
title: 'HELLO', body: 'World!', sound : "default", badge: "1"
}
};
var payloadError = {
to: "4564654654654654", //invalid registration token
data: {
url: "news"
},
priority: 'high',
content_available: true,
notification: { title: 'TEST HELLO', body: '123', sound : "default", badge: "1" }
};
var payloadMulticast = {
registration_ids:["4564654654654654",
'123123123',
validDeviceRegistrationToken, //valid token among invalid tokens to see the error and ok response
'123133213123123'],
data: {
url: "news"
},
priority: 'high',
content_available: true,
notification: { title: 'Hello', body: 'Multicast', sound : "default", badge: "1" }
};
var callbackLog = function (sender, err, res) {
console.log("\n__________________________________")
console.log("\t"+sender);
console.log("----------------------------------")
console.log("err="+err);
console.log("res="+res);
console.log("----------------------------------\n>>>");
};
function sendOK()
{
fcmCli.send(payloadOK,function(err,res){
callbackLog('sendOK',err,res);
});
}
function sendError() {
fcmCli.send(payloadError,function(err,res){
callbackLog('sendError',err,res);
});
}
function sendMulticast(){
fcmCli.send(payloadMulticast,function(err,res){
callbackLog('sendMulticast',err,res);
});
}
sendOK();
sendMulticast();
sendError();
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.