Comments (2)
Hi, I got "ONESIGNAL Responce Error" message even though config success App ID nad REST API KEY.
Can you please tell me what is wrong with me ?
Thanks
Hi. I have the same problem. Probably something changed on OneSignal API and this was not updated. Did you solved your problem?
from node-red-contrib-onesignal.
Hi @therealhugocosta
Yes, I solved it by edit some code on node-red config file:
sudo nano .node-red/node_modules/node-red-contrib-onesignal/onesignal/onesignal.js
Replace all contents on onesignal.js file by below script:
var https = require('https');
module.exports = function (RED) {
function OneSignalNode(config) {
RED.nodes.createNode(this, config);
var oneSignalConfig = RED.nodes.getNode(config.config);
var [web, android, ios, segment, targetType] = [config.web, config.android, config.ios, config.segments, config.targetType];
var node = this;
var headers = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Basic " + oneSignalConfig.restApiKey
};
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
method: "POST",
headers: headers
};
this.on('input', function (msg) {
var req = https.request(options, function (res) {
res.on('data', function (data) {
var response = JSON.parse(data);
if (response.errors) {
response.errors.forEach(function (err) {
console.log("ONESIGNAL Responce Error:", err);
node.error("ONESIGNAL Responce Error->"+ err);
})
node.status({ fill: "red", shape: "ring", text: "OneSignal ERROR" });
} else {
node.log("Notification SENT SUCCESSFULLY");
node.status({ fill: "green", shape: "ring", text: "SENT!" });
}
});
req.on('error', function (e) {
console.log("ONE SIGNAL ERROR:", e);
node.error("ONE SIGNAL ERROR", e);
node.status({ fill: "red", shape: "ring", text: "OneSignal ERROR" });
});
});
var title = msg.payload.title || config.title;
var text = msg.payload.content || config.message;
var playerId = [];
playerId = msg.payload.playerId || config.player;
var messageJson = {
app_id: oneSignalConfig.appId,
headings: { "en": title },
contents: { "en": text },
included_segments: ["All"]
};
console.log('OneSignal Message:- ', messageJson);
req.write(JSON.stringify(messageJson));
req.end();
});
}
RED.nodes.registerType("onesignal", OneSignalNode);
}
from node-red-contrib-onesignal.
Related Issues (2)
- doesn't install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-contrib-onesignal.