Relay agent lets executing any commands or scripts on a host machine when webhooks are received. To use this functionality, use
--relayer exec option together with
--command python (or any other command such as
node) followed by optional arguments. For example to execute python script in a file called
- –bucket specifies which bucket to subscribe to
- –relayer specifies
execrelayer (by default it would forward to an HTTP endpoint)
- –command is the main command to execute, for bash scripts you would use
- my-script.py is the optional script/application file
This script will receive webhook data through standard input (stdin). You can read this data and optionally return a response. Response will be visible in the webhook log through the Webhook Relay web interface.
Executed script will always be marked with status code 200 even though it will not be forwarded to a destination by the relay agent. When running in a
--relayer execmode, agent will only execute commands without forwarding webhooks. To also forward webhooks, launch a second agent.
Here is a simple Python script that will read from standard input and save the webhook payload into a file with a timestamp.
By default relay agent only sends request body through the stdin into the script:
Now, send a webhook:
File contents will be:
Launching relay agent you should see that it’s now executing commands instead of forwarding webhooks:
Let’s send another webhook:
You should now see a file created with contents:
To execute commands when running in a background service mode add additional ‘relayer’ section:
To debug your commands you can use standard shell pipes. For example to try the previous Python example without Webhook Relay:
Or, if your test data is in a file: