forked from nandarustam/fcm-push
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added example file and updated documentation
- Loading branch information
Showing
3 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
/** | |||
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters