Serverhooks with external platform



  • Ok I have been slamming my head against this for a few days now since I am fairly new to socket.io and the nodebb framework. Hoping I can get some ideas.

    Basically all I am trying to do is get a nodebb serverhook to work with another platforms hook. The hook I am using is action:post.save.

    I have my plugin.json serverhook calling to my library.js fine. The problem is trying to pass the data to the other platform.

    I can do it all day long client side with something like:
    $.post( url, embed2 );

    I guess my question really is, how the heck can I "post (socket.io equivalent?)" from my plugin in a serverside script?

    I have been searching for hours and I bet I missed something. Any help is appreciated.



  • Or is there a hook that I am missing that fires clientside when the user posts a new message? I have tried "action:composer.post.new" which fires when you click new or reply not submit.


  • Global Moderator

    Can you post your existing code? It's difficult to understand what you're trying to do without some kind of example.

    Maybe a pseudo-code example would also be helpful.



  • My code is extremely mangled at the moment.

    Basically what I am attempting to do is whenever a user posts I want an update to be pushed to a Discord channel. I have the Discord hooks working perfect. But sending the data through the nodebb hook is becoming a task.

    The only information I require is how to push the data to Discord from the nodebb server side.

    Should I be using nodejs http to send the data?



  • Example:

    plugin.json

    {
      "id": "nodebb-plugin-nubhook",
      "name": "nubHook",
      "description": "blablabla",
      "url": "removed for priv",
      "library": "./library.js",
      "hooks": [
        { "hook": "action:post.save", "method": "discordHooker" },
        { "hook": "static:app.load", "method": "init" }
      ],
      "scripts": [
        "lib/main.js"
      ]
    }
    

    library.js

    var NubHook = {
           discordHooker: function(postData) {
    //send to discord plox
           }
       };
    
    
    
    module.exports = NubHook;

  • Global Moderator

    @Cepheus If you need to make a post request, I'd suggest using the request library.

    So in your plugin you have something like:

    var request = require('request');
    
    function onPostSave(params) {
      var post = params.post;
      var data = {
        url: 'https://discord.com/route/to/thing',
        // extract data from post to send to discord
      };
      
      request.post(data, function (err, res, body) {
        // do stuff with the response
      });
    }
    


  • Alright, thanks for the help!


  • Admin

    Seconding the recommendation to use request. That's the server side equivalent to making an xhr on the client side.


Log in to reply
 


Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.