Webhook
Last updated
Last updated
A private webhook plugin is a user-defined logic whose executions is triggered by making an HTTP request to its HTTPS Endpoint URL:
As stated before, any private plugin, regardless of its type, and particularly in the case of a private webhook plugin, is composed by the file structure shown below:
This is a script, written either in Python or NodeJS. This can be thought of as a "set up" script, since it will only run once, at the moment of creating the plugin.
This is written in either Python or NodeJS and it holds the plugin's core logic. The script runs every time an HTTP request is made to the plugin's HTTPS Endpoint URL.
This is written either in Python or NodeJS.
If required, the plugin's developer can opt to offer its users a way to execute custom logic. Thus, this script empowers the user with an additional level of customization.
For instance, if a developer creates a webhook plugin to fetch data from an external API, they might want to allow users to further process or redirect that data without altering the core logic.
The user_code
script provides this flexibility, maintaining the plugin's encapsulation while offering a dedicated space for user-specific logic.
You must employ the names of all files and directories mentioned in the "required files" section, as the plugins engine specifically searches for these files and their extensions.
For instance:
If your plugin is using Python as runtime, the scripts' names should be control.py
, function.py
and user_code.py
If your plugin is using NodeJS as runtime, the scripts' names should be control.js
, function.js
and user_code.js
The language selected for the control
, function
and user_code
scripts must match with the value of theruntime
key in the manifest.toml file.
This file provides the developer with the capability of building and displaying a form that the plugin's users can use to input the parameters required by the plugin.
The contents of this form are displayed in the creation modal of the plugin.
For example, if we created a plugin to receive data from an LNS during device uplinks, we'd need the user's LNS and Ubidots credentials. A GUI for this widget could look like this:
This can be achieved using text fields in the form as shown below:
All of these parameters in the form are accessible to the function
, control
and user_code
scripts on each of its executions within the _parameters
key in the incoming JSON object.
For detailed information about the supported elements in the view.xml file, head to its dedicated section in the "Plugins development" page.
Refer to the Private Plugins page to get more information:
Private PluginsAside from the manifest components common to all types of plugin, the following ones are specific to webhook plugins:
[settings]
runtime
Any valid Python or NodeJS version.
Environment in which the plugin will run.
runtime = "python:3.7"
[settings.webhook]
default_http_method
A valid HTTP method.
Default HTTP method to be used by the plugin.
default_http_method = "POST"
[settings.webhook]
allowed_http_methods
A list of valid HTTP methods.
HTTP methods allowed by the plugin.
allowed_http_methods = ["POST"]
With that in mind, a typical manifest.toml file for a private webhook plugin looks like this:
All of these manifest's keys are mandatory.