Skip to content

Plugin Development

Have a question about building a plugin? Ask here
444 Topics 1.9k Posts
  • How do I pack javascript for the acp/ a widget into a single js file?

    Solved
    2
    0 Votes
    2 Posts
    495 Views
    V
    @v_risalab i figured it out. The acp code uses browserify and the widget code uses webpack!
  • Making ban history public

    2
    0 Votes
    2 Posts
    469 Views
    yariplusY
    @v_risalab You can use the hook filter:account/profile.build to add data to the page. https://github.com/NodeBB/NodeBB/blob/master/src/middleware/render.js#L36 You can use the same code from the info controller to get the ban data. https://github.com/NodeBB/NodeBB/blob/master/src/controllers/accounts/info.js#L22
  • Directing from gdpr page to another page

    2
    0 Votes
    2 Posts
    290 Views
    barisB
    If I am not mistaken this is the code that redirects the user after register/complete page. Maybe try modifying that?
  • 0 Votes
    3 Posts
    1k Views
    G
    @mana Thank you
  • How can I import custom files in libary.js?

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    dogsD
    @pitaj Many thanks for your effort Okay so I just npm link'ed my plugin again so I thought some file will be updated. But they weren't. Here is my full source code of libary.js: 'use strict'; /* NodeBB Basic Plugin Libraries */ const controllers = require('./lib/controllers'); const plugin = {}; /* Third Party Libraries */ const Discord = require("discord.js"); const fs = require("fs"); // Nodebb Discord Bot const config = JSON.parse(fs.readFileSync("./utils/config.json", "utf-8")); var client = new Discord.Client(); let debug = true; plugin.init = function (params, callback, client) { myDebug("nodebb-discord-bot-started"); callback(); }; function myDebug(msg){ if(debug){ console.log(msg); } } module.exports = plugin; 2021-01-12T10:46:19.318Z [4567/4689] - error: Error: ENOENT: no such file or directory, open './utils/config.json' at Object.openSync (fs.js:462:3) at Object.readFileSync (fs.js:364:35) at Object.<anonymous> (/home/ubuntu/nodebb-linked-modules/nodebb-plugin-makesmart-discord-bot/library.js:15:30) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.Plugins.requireLibrary (/home/ubuntu/nodebb/src/plugins/index.js:70:39) I tried it with path again: // Nodebb Discord Bot var configpath = path.join(__dirname, 'utils', 'config.json'); const config = JSON.parse(fs.readFileSync(configpath, "utf-8")); var client = new Discord.Client(); an suddenly ... it worked! o.O 2021-01-12T10:51:15.711Z [4567/4765] - info: [api] Adding 2 route(s) to `api/v3/plugins` 2021-01-12T10:51:15.889Z [4567/4765] - info: Routes added 2021-01-12T10:51:15.933Z [4567/4765] - info: NodeBB Ready 2021-01-12T10:51:15.943Z [4567/4765] - info: Enabling 'trust proxy' 2021-01-12T10:51:15.972Z [4567/4765] - info: NodeBB is now listening on: 0.0.0.0:4567 I think it was really because I ran npm link again. Funny.* I'm sorry. Most of the time, the problem is in front of the computer. But still a strange behavior in my opinion. Well ... Good to know for the future. @PitaJ as mentioned thank you for you effort. For any others having the same issue: Read the Stackoverflow Solution posted by @PitaJ right here If it still not work use npm link in ./nodebb again to refresh something in the plugin folder ...I dont know tbh ...
  • Hide category from feeds

    Unsolved
    1
    0 Votes
    1 Posts
    417 Views
    magnusvhendinM
    Is there some way to hide all topics within a category from all feeds (recent, popular, new, the digest)? I need the topics to be accessible (and usable) to all users directly, but not searchable or showing up at random.
  • How to use Third-Party libraries?

    Solved
    1
    2 Votes
    1 Posts
    547 Views
    dogsD
    Whats the right way to use third party libraries? I tried to do it descriped in the docs: https://docs.nodebb.org/development/plugins/libraries/ But it doenst work. I want to use Swiper in my Theme: https://swiperjs.com/get-started/ I tried it with "modules": { "swiper.js": "node_modules/swiper/swiper-bundle.min.js" } in client.js i used: require(['swiper'], function (Swiper) { var mySwiper = new Swiper('.swiper-container', { // Optional parameters direction: 'vertical', loop: true, // If we need pagination pagination: { el: '.swiper-pagination', }, // Navigation arrows navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // And if we need scrollbar scrollbar: { el: '.swiper-scrollbar', }, }) }); The Javascript from Swiper does not load. Can you help me? I also treid to import it directly via html <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css"> <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script> and I also copied the contents of: https://unpkg.com/[email protected]/swiper-bundle.js and createt a file unter /lib/swiper-bundle.min.js. Nothing worked for me. The JS is still not loading... Looking forward to your answers! I fixed it. I am sorry. In my development I use grunt. But it seems that I doesnt load new libraries if installen. So I determinated the process Ctrl+C and restarted it using grunt. The librariers are loaded and the third party library works well now using: "modules": { "swiper.js": "node_modules/swiper/swiper-bundle.min.js" } require(['swiper'], function (Swiper) { var mySwiper = new Swiper('.swiper-container', { ... ... ... }) }
  • reference to objects in benchpress

    10
    0 Votes
    10 Posts
    957 Views
    PitaJP
    @shayan woops actually it wasn't working for me. It looks like this is a bug. For some reason ./name in the inner loop refers to the name property of the value in the outer loop. I've created an issue: https://github.com/benchpressjs/benchpressjs/issues/97
  • 0 Votes
    2 Posts
    551 Views
    julianJ
    Hi @avan-sardar, welcome! find a topic based on uid and a custom session ID Is this a requirement? If your plugin is listening for something like action:post.save, then you can process the stripe payment. The action hook itself also sends the post data, which contains the pid and tid. Without more context, I am afraid I will not be able to help further.
  • Use Websockets in own Plugin

    Solved
    4
    0 Votes
    4 Posts
    1k Views
    dogsD
    I still have a question. Everything works fine at the moment. Send data from the client to the server isn't a problem now. But how can I emit a event to all connected clients serverside? Something e.g myPlugin.emit('plugins.publishMessage', {data: "Some data"}, function(err, result) { console.log(result); }); After one hour spending searching different topics and some code I found the solution. Besides the custom clientside Sockets const myPluginSockets = require.main.require('./src/socket.io/plugins'); you have to define the Server Sockets too const myPluginSockets = require.main.require('./src/socket.io/plugins'); const serverSockets = require.main.require('./src/socket.io'); Now you can emit events from server side to the clients: serverSockets.server.sockets.emit('messageReceive', data); to receive the event clientside, you can use following in ur main.js file: socket.on('messageReceive', function(data){ console.log(data); }); Client console output: {msg: "my message"} Maybe I'll write a little Tutorial on this because I am probably not the only one who does not understand it so easily.
  • Implementing custom sso into NodeBB

    7
    0 Votes
    7 Posts
    975 Views
    barisB
    @Maddoctor can you try setting Admin relogin duration to 0 in your ACP and try again. I created an issue for this https://github.com/NodeBB/NodeBB/issues/9063
  • Send invite without a user

    Unsolved
    4
    0 Votes
    4 Posts
    867 Views
    PitaJP
    Please report this issue on Github.
  • Hello, I want to get all the posts from a Topic

    3
    1 Votes
    3 Posts
    602 Views
    Aisar G.A
    @baris Thanks. It worked
  • This topic is deleted!

    1
    1 Votes
    1 Posts
    35 Views
  • How to change UID

    2
    0 Votes
    2 Posts
    384 Views
    PitaJP
    Not in any simple or easy way. Why do you want to?
  • How to deal with placeholder in URL?

    Solved
    2
    0 Votes
    2 Posts
    455 Views
    barisB
    req.params.tag will give you the parameter.
  • Add server side hooks listeners in runtime?

    Solved
    3
    0 Votes
    3 Posts
    447 Views
    magnusvhendinM
    @baris That's it! Thanks a lot.
  • How to push data from backend to frontend?

    Unsolved
    3
    0 Votes
    3 Posts
    876 Views
    dogsD
    @PitaJ I want to display it on a existing page e.g on users profile page. What do I have to to, to add it to an existing route? E.g /user/pasib Could you give me some links, or a little example how I cant add a simple backend variable to the frontend. Thank you
  • How to write new plugins and add it new routes

    2
    0 Votes
    2 Posts
    409 Views
    barisB
    These should help you get started. https://docs.nodebb.org/development/plugins/ https://github.com/NodeBB/nodebb-plugin-quickstart
  • Client script cannot be available in both main and admin?

    Solved
    6
    0 Votes
    6 Posts
    768 Views
    magnusvhendinM
    Thanks for the clarification @PitaJ! I did a lot of experimenting but I guess I didn't get the right combination. I think I never tried naming the module with its extension. That might have been it. For anyone who might be interested in the actual solution, here it is: In file-explorer.js: define('azure/file-explorer', ['components'], function (components) { const FileExplorer = {}; FileExplorer.init = function () { // Init stuff here }); return FileExplorer; }); In plugin.json: "modules": { "azure/file-explorer.js": "static/lib/file-explorer.js" }, In admin.js: define('admin/plugins/azure', ['settings', 'azure/file-explorer'], function (settings, fileExplorer) { fileExplorer.init(); }); In main.js: $(document).ready(function () { require(['azure/file-explorer'], (fileExplorer) => { fileExplorer.init(); }); });