Last active
July 10, 2016 20:52
-
-
Save randymxj/d000341be053425a4c243bf3b73e5e90 to your computer and use it in GitHub Desktop.
Node.js request sending downstream POST with Google Firebase Cloud Message
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
/* | |
Example of Node.JS to send downstream cloud message with Firebase | |
NPM package request is needed in this code gist | |
*/ | |
// Firebase auth key | |
var serverKey = "Firebase Server Key"; | |
var clientToken= "Client Device Token" | |
// Payload message data | |
var deviceId = req.query.deviceId; | |
var eventName = req.query.eventName; | |
var value = req.query.value; | |
var options = { | |
url: 'https://fcm.googleapis.com/fcm/send', | |
headers: { | |
'Authorization': 'key=' + serverKey | |
}, | |
json: { | |
"to": clientToken, | |
"data": { | |
deviceId: deviceId, | |
eventName: eventName, | |
value: value | |
} | |
} | |
}; | |
request.post(options, function optionalCallback(err, httpResponse, body) { | |
if (err) { | |
return console.error('ERROR - FIREBASE POST failed:', err); | |
} | |
// Success | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment