-
-
Save AlexisLeon/1ffb7c26a07c3831cd5b19bad601990c to your computer and use it in GitHub Desktop.
Send a push notification in node with OneSignal
This file contains hidden or 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'); | |
var sendMessage = function(device, message){ | |
var restKey = '****'; | |
var appID = '****'; | |
request( | |
{ | |
method:'POST', | |
uri:'https://onesignal.com/api/v1/notifications', | |
headers: { | |
"authorization": "Basic "+restKey, | |
"content-type": "application/json" | |
}, | |
json: true, | |
body:{ | |
'app_id': appID, | |
'contents': {en: message}, | |
'include_player_ids': Array.isArray(device) ? device : [device] | |
} | |
}, | |
function(error, response, body) { | |
if(!body.errors){ | |
console.log(body); | |
}else{ | |
console.error('Error:', body.errors); | |
} | |
} | |
); | |
} | |
sendMessage('a9fb63b1-b5cc-4ee9-92f0-5be15eb300c0', 'Hello!'); | |
// Also accepts an array of devices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment