Created
March 27, 2019 10:28
-
-
Save ikishanoza/28c3330f7a99af39a4913317d6c6dedb to your computer and use it in GitHub Desktop.
fcm for nodejs
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
var request = require('request'); | |
function sendMessageToUser(deviceId, message) { | |
request({ | |
url: 'https://fcm.googleapis.com/fcm/send', | |
method: 'POST', | |
headers: { | |
'Content-Type' :' application/json', | |
'Authorization': 'key=AI...8o' | |
}, | |
body: JSON.stringify( | |
{ "data": { | |
"message": message | |
}, | |
"to" : deviceId | |
} | |
) | |
}, function(error, response, body) { | |
if (error) { | |
console.error(error, response, body); | |
} | |
else if (response.statusCode >= 400) { | |
console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage+'\n'+body); | |
} | |
else { | |
console.log('Done!') | |
} | |
}); | |
sendMessageToUser( | |
"d7x...KJQ", | |
{ message: 'Hello puf'} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment