DockerERTFF/extensions/server_connect/modules/onesignal_getnotification.js

29 lines
1.0 KiB
JavaScript

// Node integration with wappler.io
// v1.0.0
exports.onesignal_getnotification = async function (options) {
// get appid parsed as options.appid, throw error is missing
const appid = this.parseRequired(options.appid, '*', 'No app ID entered')
// log before and after vlaues
console.log(options.appid + " => " + appid)
// get limit, if omitted set default of 50
var notification_id = this.parseRequired(options.notification_id, '*', 'Notification ID not specified')
const fetch = require('node-fetch');
const url = `https://api.onesignal.com/notifications/${notification_id}?app_id=${appid}`;
const os_options = {
method: 'GET',
headers: { accept: 'application/json', Authorization: `Basic ${process.env.ONESIGNAL_REST_API_KEY}` }
};
return fetch(url, os_options)
.then(res => {
return res.json().then(json => {
json.status = res.status; // Add status to json response
return json;
});
})
.catch(err => console.error('Error:', err));
}