Giter Site home page Giter Site logo

Comments (2)

therealhugocosta avatar therealhugocosta commented on June 4, 2024

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.

iotproductions avatar iotproductions commented on June 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.