OpenArtifacts

openartifacts.sh / templates / webhook-receiver

Webhook receiver

Python 3.11, standard library · size small · 3 files, 14.3 kB

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:

HeaderSenderSigned bytes
Stripe-Signature: t=<unix>,v1=<hex>Stripe<t>.<raw body>; t must be within 5 minutes
X-Hub-Signature-256: sha256=<hex>GitHubthe raw body
X-Signature: sha256=<hex>anything elsethe 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

VariableRequiredWhat it does
WEBHOOK_SECRETyesThe 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_TOKENnoThe bearer token for GET /events. Defaults to WEBHOOK_SECRET.
KEEP_EVENTSnoHow 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

What it costs

Prices for small, the size this template needs (current prices on openartifacts.sh):

Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.

Files

Every file, as JSON you can edit and publish: GET /v1/templates/webhook-receiver.


← all templates · openartifacts.sh · docs.md · skill.md