A plugin for implementing incoming webhooks for fastify applications.
npm i @autotelic/fastify-webhooks
'use strict'
const fastifyWebhooks = require('@autotelic/fastify-webhooks')
const webhooks = [
{
plugin: async (fastify) => fastify.post('/webhook', (req, res) => {
// do something with the event payload
res.send('ok')
}),
},
]
const verification = async (fastify, opts) => {
// Define a plugin that registers a hook here that verifies the request.
fastify.addHook('preValidation', async (request, response) => {
// Signature verification should happen inside this hook.
})
}
const app = require('fastify')()
app.register(fastifyWebhook, { webhooks, verification })
await app.ready()
app.listen((err, address) => { console.log(`listening at ${address}`)})
We provide the following usage examples and recipes:
The configuration object accepts the following fields":
An array of webhook configuration objects. Each entry must contain the following fields:
A fastify plugin that will be registered to handle the webhook route.
A fastify plugin that will encapsulate the webhooks plugins. Typically a plugin that registers a preValidation hook which is used to verify a request signature.
- Trigger the release workflow via release tag
git checkout main && git pull npm version { minor | major | path } git push --follow-tags
This project is covered under the MIT license.