Signed Webhooks
Sign requests to a mapped webhookA URL that turns signed JSON into a Discord message with HMAC-SHA-256, so the bot accepts them and posts the message to Discord.
Why Use Signed Webhooks?
- Proves that each request came from a service holding the signing secretShared secret that proves a webhook request is yours, so nobody else can post through your route.
- Rejects requests whose timestamp is more than five minutes away from the server's clock, so a captured request can't be sent again later.
- Queues each accepted message in the database, so the workerBackground service that runs schedules and deliveries still posts it after a busy moment or a restart.
Requirements
- A mapped webhookA URL that turns signed JSON into a Discord message route — Configure a path, a channel, a message, and a signing secretShared secret that proves a webhook request is yours in Web Applications.
- The signing secretShared secret that proves a webhook request is yours — At least 32 characters, with the same value saved in the route's Signing secret field and in your sender.
- A running bot — Requests get HTTP 503 while the bot is stopped or no Bot TokenThe bot's password for Discord, from the Developer Portal is saved.
- A reachable address — The route is served on the control panel's port, so senders need a path through your reverse proxy.
Endpoint and Headers
Send a POST request to the exact path you configured, with the raw JSON body and two headers.
POST /webhooks/price-alert HTTP/1.1
Host: bot.example.com
Content-Type: application/json
X-Stonker-Timestamp: 1792684800
X-Stonker-Signature: sha256=15d6b9d6363377cdc90373d41faab297a3d14be396656dd3431cda8b0f748e1f
{"alert":{"symbol":"TEST","price":123.45}}
X-Stonker-Timestamp— The current Unix time in seconds, as 10 digits.X-Stonker-Signature— The hex HMAC-SHA-256 of the timestamp, a period, and the raw body, with an optionalsha256=prefix and either letter case.- Body — A JSON object of up to 128 KiB, sent exactly as signed.
Compute the Signature
Sign the string <timestamp>.<raw body> with the signing secretShared secret that proves a webhook request is yours, using the same bytes you send as the body.
To check your code, sign the body {"alert":{"symbol":"TEST","price":123.45}} with the timestamp 1792684800 and the secret a-webhook-signing-secret-with-at-least-32-characters. The result is 15d6b9d6363377cdc90373d41faab297a3d14be396656dd3431cda8b0f748e1f, the signature shown above.
Map JSON Fields to Variables
Each webhook variableAn @PLACEHOLDER@ filled from the webhook's JSON has an ID, a path into the JSON body, and a type, and the message uses it as @ID@.
- ID — Uppercase letters and digits, starting with a letter, with single underscores between parts, such as
SYMBOLorPRICE_2. - Path — Up to 10 dot-separated keys, such as
alert.symbol, and arrays aren't supported. - Missing values — A missing field, or a value of the wrong kind, shows as "Unavailable".
| Type | Accepts | Shows |
|---|---|---|
string | Text, a number, or true/false | The value as text, with Markdown characters escaped, up to 500 characters |
boolean | true or false | "Yes" or "No" |
ts-seconds | A Unix time in seconds | A Discord timestamp in each reader's time zoneThe zone a schedule's times are read in; UTC by default |
ts-millis | A Unix time in milliseconds | A Discord timestamp in each reader's time zoneThe zone a schedule's times are read in; UTC by default |
usd-dollars | A number of dollars | A US dollar amount, such as $123.45 |
usd-cents | A number of cents | A US dollar amount, such as $123.45 for 12345 |
The message is the route's content, then its footer on a second line, with %YEAR% filled in as the current year in UTC. After the variables are filled in, it has to be 1 to 2,000 characters.
Responses
| Status | Body | Meaning |
|---|---|---|
| 202 | {"accepted":true,"duplicate":false} | The message was queued. |
| 200 | {"accepted":true,"duplicate":true} | The same request was already queued. |
| 400 | "Webhook body must be valid JSON." or "Webhook body must be a JSON object." | The body isn't a JSON object. |
| 401 | "Invalid or expired webhook signature." | The signature, the timestamp, or the secret doesn't match. |
| 404 | "Not found." | No route matches the path, the feature is off, or its settings fail their checks, such as a missing signing secret. |
| 405 | "Method not allowed." | The request wasn't a POST. |
| 503 | "Discord delivery is not available while the bot is stopped or unconfigured." | The bot is stopped or has no Bot TokenThe bot's password for Discord, from the Developer Portal. |
| 413 | {"error":{"code":"payload_too_large","message":"The request body is too large."}} | The body is over 128 KiB. |
| 415 | {"error":{"code":"unsupported_encoding","message":"Send the request body as UTF-8 JSON."}} | The request used a Content-Encoding the web service can't read. |
| 422 | "Rendered webhook content must contain between 1 and 2000 characters." | The message is empty or over 2,000 characters after the variables are filled in. |
Replay Protection
- Freshness windowSigned requests must be under five minutes old — The timestamp has to be within 300 seconds of the server's clock, in either direction.
- Duplicate detection — The bot builds a deduplication keyStops the same job from being queued twice from the path, the timestamp, and the normalized signature value, so sending the same request again returns HTTP 200 with
"duplicate":trueeven if the hexadecimal letters or optionalsha256=prefix use different case.
Troubleshooting
- HTTP 401 — Check that the server's clock is correct, that the timestamp is in seconds, and that the body wasn't reformatted after you signed it.
- HTTP 404 on a configured path — The path has to match exactly, including a trailing slash, and the Web applications feature has to be on with settings that pass their checks.
- HTTP 503 — Start the bot, or save a Bot TokenThe bot's password for Discord, from the Developer Portal.
- "Unavailable" in the message — A variable's path or type doesn't match the JSON you sent.