Skip to content

Instantly share code, notes, and snippets.

@duynhm
Last active October 25, 2016 08:30
Show Gist options
  • Save duynhm/5d6a652a57f95dfdf886a6c02d23b492 to your computer and use it in GitHub Desktop.
Save duynhm/5d6a652a57f95dfdf886a6c02d23b492 to your computer and use it in GitHub Desktop.
FCM
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
//send multi topics
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"condition": "'dogs' in topics || 'cats' in topics",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
//HTTP Response
//Success example:
{
"message_id": "1023456"
}
//failure example:
{
"error": "TopicsMessageRateExceeded"
}
pushNotificationAPPTopic: function (param) {
var request = require('request');
var full_url = "https://fcm.googleapis.com/fcm/send";
param = {
"to": "/topics/news",
"data": {
'Subject': param.subject,
'Image': param.image,
'Content': param.content
}
};
console.log("url:" + full_url);
console.dir(param);
request.post({
uri: full_url,
body: param,
headers: {
'content-type': 'application/json',
'Authorization': 'key=AIzaSyAVwjj...otJUrI'
},
json: true
}, function (err, response, body) {
if (err) {
console.log(err)
} else {
console.log(body);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment