🧩Extensions

Learn how to write your own extensions.

Writing extensions for WrangleBot is very simple and only requires a text editor to get started.

We recommend using an IDE such as Visual Studio Code, WebStorm or at the very least a text editor with syntax highlighting such as Sublime.

Choosing your Extension

WrangleBot supports two extension types: hooks and endpoints

Hook

Whenever WrangleBot does something, it fires events, these events contain data, that you can act on.

Example Use Cases:

  • You want to send information to a third party whenver a MetaFile is ingested.

  • You want to copy or transcode files directly after a Copy Task was completed.

  • You want to send reports to a Slack channel.

Endpoint

An endpoint acts as any other endpoint on the API, you can call it via /api/v1/your-endpoint/ using any curl or http request.

Example Use Cases:

  • You want to post or modify data that is coming from another source of truth.

  • You want to run custom workflows, but don't want to have the logic on your side.

  • You want to add custom functionality, i.e. Business Logic.

Adding your Extension

Start by creating a folder called custom in your wranglebot folder in your user home folder, i.e. /Users/axelrothe/wranglebot/

Within this folder, create another folder and give it a unique name. This will be your extension root folder.

Create one or both folders, for hooks and endpoints and create a .js file, the name should reflect the script functionality, i.e. create-new-project.js

Hook

Hooks are written in NodeJS using the CommonJS dialect.

module.exports = {
  name: "example-external-hook",
  description: "An example hook that is external to the bot",
  version: "0.0.1",
  events: ["notification"],
  handler: async (event, data, wranglebot) => {
    const libs = await wranglebot.query.library.many().fetch();

    console.log(`There are currently ${libs.length} libraries loaded.`);
  },
};

Endpoints

Endpoints are written in NodeJS using the CommonJS dialect.

module.exports = {
  method: "get",
  requiredRole: ["admin", "maintainer", "contributor"],
  url: "/example/01",
  handler: async (request, result, wranglebot, server) => {
  
    const libs = await wranglebot.query.library.many().fetch();
 
    return {
      status: 200, 
      result: `There are currently ${libs.length} libraries loaded.`
    }
  },
};

Importing Third Party Libraries

WrangleBot extensions currently do not support automatic importing of libraries via the node_module folder. You will need to directly require the script.

//instead of 
const thirdparty = require('mythirdpartylib');
// do
const thirdparty = require('./node_modules/mythirdpartylib/dist/index.js')

Sharing your Creations

Last updated