This is a simple plugin that lets you configure custom webhooks. Webhooks are trigged by kirby hook events.
Alternative:
https://github.com/pju-/kirby-webhook-field
Download and copy this repository to /site/plugins/webhooks
.
git submodule add https://github.com/errnesto/kirby-plugin-webhooks.git site/plugins/webhooks
composer require errnesto/kirby-plugin-webhooks
This plugin looks for webhook configurations in the kirby site
object.
So to create a webhook you could just edit the content/site.txt
file:
Webhooks:
-
url: >
https://webhook.site/74a7ed53-7091-4871-a1d7-749417b24269
payload: '{"secret":"123"}'
triggers: page.create:after, page.update:after
The config must be stored under the key Webhooks
as yaml array.
Every webhook needs the following options:
url
: The URL to post to when a kirby hook is triggeredpayload
: The body of the post requesttriggers
: A comma seperated list of kirby hooks
A blueprint to edit the webhooks in the panel could look like this:
webhooks:
label: Webhooks
type: structure
fields:
url:
label: URL
type: url
payload:
label: Payload
type: text
triggers:
label: Triggers
type: tags
You can customize the requests the plugin sends with your own functions.
Every function gets the following parameters:
$trigger
: The name of the hook that caused the webhook to be called$webhook
: The webhook read from the site object. (This will include any field you define)...$params
: All the params from the kirby hook.
You can set all of the following options by returning them in your /site/config/config.php
:
// default:
return [
'errnesto.webhooks.getURL' => function ($trigger, $webhook, ...$params) {
return $webhook['url'];
}
];
return [
// default:
'errnesto.webhooks.getHeader' => function ($trigger, $webhook, ...$params) {
return "Content-type: application/json\r\n";
}
];
return [
// default:
'errnesto.webhooks.getMethod' => function ($trigger, $webhook, ...$params) {
return "POST";
}
];
return [
// default
'errnesto.webhooks.getPayload' => function ($trigger, $webhook, ...$params) {
return $webhook['payload'];
},
];
- Add custom panel view and store webhooks somewhere else?
- Returning null from
getURL
should skip a hook and not cause an error - Option to make hook non blocking?
MIT