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 https = require('https'); | |
let DEBUG = true; | |
let customPayload = {}; | |
let requestOptions = { | |
"hostname": "api.batch.com", | |
"port": 443, | |
"method": "POST", | |
"path": "/1.0/" + "<your app api key>" + "/transactional/send", | |
"headers": { | |
"Content-Type": "application/json", | |
"User-Agent": "BatchPushSender 1.0", | |
"X-Authorization": "rest key" | |
} | |
}; | |
let apiPayload = { | |
"group_id": "batch_push_sender", | |
"push_time": "now", | |
"message": { | |
"body": "<your message body here>" | |
}, | |
"recipients": { | |
"tokens": ["<token>"] | |
}, | |
"sandbox": false, // Only for iOS | |
"deeplink": "http://google.fr", | |
"custom_payload": JSON.stringify(customPayload) | |
}; | |
let request = https.request(requestOptions, (res) => { | |
let data = ""; | |
res.setEncoding("utf8"); | |
res.on("data", (chunk) => { | |
data += chunk; | |
}); | |
res.on("end", (chunk) => { | |
if (DEBUG) { | |
console.log("[BatchPushSender] Batch API Request response: %j", data); | |
} | |
}); | |
}); | |
request.on("error", (e) => { | |
if (DEBUG) { | |
console.log("[BatchPushSender] Batch API Request error: %j", e); | |
} | |
}); | |
request.write(JSON.stringify(apiPayload)); | |
request.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 55 should read 'request.write(JSON.stringify(apiPayload));'
As it's missing the ')'