Skip to content

Instantly share code, notes, and snippets.

@friederbluemle
Created February 5, 2016 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friederbluemle/9cec42cd3482894d410c to your computer and use it in GitHub Desktop.
Save friederbluemle/9cec42cd3482894d410c to your computer and use it in GitHub Desktop.
var request = require('request');
var apiKey = "API_KEY";
var regId = "REG_ID";
var args = process.argv.slice(2);
if (args[0] == 'show_offers') {
var data = {
id: Math.floor(Date.now() / 1000),
type: "show_offers",
title: "PaySense",
text: "You have offers waiting. Check them now!"
};
} else if (args[0] == 'create_loan') {
var data = {
id: Math.floor(Date.now() / 1000),
type: "create_loan",
title: "PaySense",
text: "Do you want to EMI your transaction?"
};
} else {
var data = {
id: Math.floor(Date.now() / 1000),
title: "PaySense",
text: "Your application has been approved."
};
}
var requestData = {
data: data,
registration_ids: [regId]
}
console.log(JSON.stringify(requestData));
request({
url: 'https://android.googleapis.com/gcm/send',
method: 'POST',
headers: {
'Authorization': 'key=' + apiKey,
'Content-Type': 'application/json'
},
json: requestData
}, function (error, response, body) {
if (error) {
console.log(error);
} else if (response.statusCode != 200) {
console.log(response.statusCode, body);
} else {
console.log(body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment