Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Promise = require("bluebird");
- var https = require('https');
- var util = require('util');
- var options = {
- host: "onesignal.com",
- port: 443,
- path: "/api/v1/notifications",
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "Authorization": "xxx"
- }
- };
- module.exports = {
- sendNotification: function (cfg) {
- return new Promise(function (resolve, reject) {
- var data = {
- isIos: true,
- isAndroid: true,
- app_id: cfg.appid,
- include_player_ids: cfg.userids,
- contents: {
- en: cfg.title
- },
- data: cfg
- };
- console.log("Sending:");
- console.log(util.inspect(data));
- var req = https.request(options, function (res) {
- res.on('data', function (data) {
- console.log("Response:");
- console.log(util.inspect(JSON.parse(data), false, null));
- resolve(JSON.parse(data));
- });
- });
- req.on('error', function (e) {
- console.log("ERROR:");
- console.log(util.inspect(e));
- reject(e);
- });
- req.write(JSON.stringify(data));
- req.end();
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement