Triggers - Kaholo


1. Triggers

Triggers are also a kind of a plugin, but instead of using it’s methods inside the pipelines, triggers methods are executed when a request is sent to the trigger’s matching URL, and then triggers\executes all connected pipelines. The URL of the trigger is called a Webhook, and you will likely encounter it while configuring integrations between different software.

2. Trigger Structure

The default file structure for triggers is the same as for plugins, except the content inside of the files.

2.1. config.json

In the config.json file Triggers have slightly different fields and values than other plugins. Here is an example of a trigger’s config.json file:

The main difference between a trigger’s config files and other plugins is in triggers, each method needs to have a route as well, and the field type should have the value of “trigger” instead of “executer”. It’s recommended to also put the trigger keyword in the name of the plugin.

3. Trigger Parameters

Trigger parameters are declared in the same format as other parameters or settings. The main difference is that the user can’t pass values to it from the code, or use autocomplete parameters with triggers. And so you don’t need to support receiving arrays or objects from the trigger parameters, when using triggers.

4. Trigger Code

The code for implementing triggers should be written in JavaScript like for any other Kaholo plugin. Trigger methods get 4 inputs: An express http request object, response object, Settings (like with plugin methods), and the trigger objects themselves. 

Usually, the trigger method parses the data from the request, goes over all triggers, parses each trigger parameter, checks if the request should trigger each of the triggers, and executes the connected pipeline in case the trigger passed.

The triggers are passed as an array of objects, and you can execute the related pipeline of the trigger using trigger.execute (eventTitle, reqPayload). Here you can see some example code for a trigger:

Most webhook requests expect a response back from the trigger, whether it succeeded or an error occurred. Usually, most services expect a 200 status code for successful operations and a 4** status code for an error.

With trigger methods, you need to export the methods from the main code file as well for it to reach the Kaholo UI, as is the case with plugin methods.

Close Menu