Created
September 1, 2017 15:00
-
-
Save antonyalkmim/05b36bb67e6ca1c6b04d854e6b868405 to your computer and use it in GitHub Desktop.
NodeJS script for send OneSignal notifications
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 sendNotification = function(data) { | |
var headers = { | |
"Content-Type": "application/json; charset=utf-8", | |
"Authorization": "Basic Token" | |
}; | |
var options = { | |
host: "onesignal.com", | |
port: 443, | |
path: "/api/v1/notifications", | |
method: "POST", | |
headers: headers | |
}; | |
var https = require('https'); | |
var req = https.request(options, function(res) { | |
res.on('data', function(data) { | |
console.log("Response:"); | |
console.log(JSON.parse(data)); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log("ERROR:"); | |
console.log(e); | |
}); | |
req.write(JSON.stringify(data)); | |
req.end(); | |
}; | |
// all registered device | |
var message = { | |
app_id: "1a2s3d-1a2s3d-1a2s3d-1a2s3d-1a2s3d", | |
contents: {"en": "English Message"}, | |
included_segments: ["All"] | |
}; | |
//specific person | |
// var message = { | |
// app_id: "1a2s3d-1a2s3d-1a2s3d-1a2s3d-1a2s3d", | |
// contents: {"en": "English Message"}, | |
// include_player_ids: ["1a2s3d-1a2s3d-1a2s3d-1a2s3d-1a2s3d"] | |
// }; | |
sendNotification(message); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment