openartifacts.sh / templates / webhook-receiver
Webhook receiver
An endpoint for webhooks that checks each delivery's HMAC signature, stores the ones that verify in /data, and lists them back to you. It understands Stripe's and GitHub's signature headers and a generic one, in Python with only the standard library.
Deploy it
One call publishes it as-is and boots it. It needs no secret to boot; set WEBHOOK_SECRET before it can do its job. Files you send with the call replace the template's files of the same name, and fields you send override its oa.json. It is billed like any service.
With curl
# once: an account and its token
curl -sX POST "https://openartifacts.sh/v1/signup?ref=templates"
# the template, published and booted
curl -sX POST https://openartifacts.sh/v1/publish \
-H "Authorization: Bearer $OA_TOKEN" \
-F type=service -F template=webhook-receiver -F slug=my-hooks
From an MCP client
publish_artifact {"type": "service", "template": "webhook-receiver",
"slug": "my-hooks"}
With the CLI
npx @openartifacts/cli signup --ref templates # once
npx @openartifacts/cli deploy --template webhook-receiver --slug my-hooks
# or edit first: the files, here, then a normal deploy
npx @openartifacts/cli init webhook-receiver
npx @openartifacts/cli deploy ./webhook-receiver --slug my-hooks
Then: Set WEBHOOK_SECRET (oa env set my-hooks WEBHOOK_SECRET=..., or PUT /v1/artifacts/my-hooks/env), then point the sender at <url>/webhook. Read deliveries with curl <url>/events -H 'Authorization: Bearer <WEBHOOK_SECRET>'.
Call it
Point the sender at <url>/webhook (or <url>/webhook/<label>; the label is stored with each event, e.g. /webhook/stripe). The signature header picks the scheme, and every scheme is keyed with WEBHOOK_SECRET:
| Header | Sender | Signed bytes |
|---|---|---|
Stripe-Signature: t=<unix>,v1=<hex> | Stripe | <t>.<raw body>; t must be within 5 minutes |
X-Hub-Signature-256: sha256=<hex> | GitHub | the raw body |
X-Signature: sha256=<hex> | anything else | the raw body |
A verified delivery answers 200 {"ok":true,"id":"..."}; a missing or wrong signature answers 401 bad_signature and is not stored. To send a test delivery yourself:
body='{"type":"ping"}'
sig=$(printf %s "$body" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -r | cut -d' ' -f1)
curl -s -X POST <url>/webhook -H "X-Signature: sha256=$sig" -d "$body"
Read what arrived (newest first) with the secret as a bearer token:
curl -s "<url>/events?limit=20" -H "Authorization: Bearer $WEBHOOK_SECRET"
curl -s <url>/events/<id> -H "Authorization: Bearer $WEBHOOK_SECRET" # one event, with its body
Environment
| Variable | Required | What it does |
|---|---|---|
WEBHOOK_SECRET | yes | The secret shared with the sender: Stripe's whsec_... signing secret, the secret you typed into GitHub, or your own. Without it the service still boots, but every delivery is refused with 503. |
READ_TOKEN | no | The bearer token for GET /events. Defaults to WEBHOOK_SECRET. |
KEEP_EVENTS | no | How many deliveries to keep. Default 500. |
Set them with oa env set <slug> WEBHOOK_SECRET=... or PUT /v1/artifacts/<slug>/env {"env":{"WEBHOOK_SECRET":"..."}}.
Durability
Each delivery is written whole, as its own file (/data/events/<ms>-<id>.json), before the 200 goes back, and never modified afterwards. A sender that gets no 2xx (the service crashed, or was asleep and the wake took too long) retries, so nothing acknowledged is lost. The oldest files are pruned past KEEP_EVENTS.
Extend it
- Act on an event: after
store(event)indo_POST, look atevent["event_type"](checkout.session.completed,push, ...) and do the work. Keep it short, or queue it: senders time out after about 10 seconds. - Deduplicate: Stripe and GitHub retry with the same event id (
event["delivery_id"]); skip one you have already stored. - Another signature scheme: add a branch to
verify().
What it costs
Prices for small, the size this template needs (current prices on openartifacts.sh):
- Asleep: no runtime charge. The bundle and
/dataare stored at $0.05 per GB-month. - Awake: $0.03 per awake hour, billed per minute, plus $0.216 per vCPU-hour of CPU actually used. A delivery wakes it and it stays awake 600 seconds (
sleep_after_s) after the last one, so an occasional delivery costs about $0.005 plus a little CPU. - Busy all day: awake around the clock is $0.72 a day plus CPU.
Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.
Files
README.md3.3 kBapp.py11.0 kBoa.json53 B
Every file, as JSON you can edit and publish: GET /v1/templates/webhook-receiver.