Webhooks
Signed events for alert changes, and how to verify them.
Webhooks push events to your server when something happens to an alert: use them to update a status page, post to your own chat, or kick off remediation when someone acknowledges.
#Set one up
const { webhook, secret } = await treason.webhookEndpoints.create({
url: "https://example.com/hooks/treason",
events: ["alert.created", "alert.acknowledged", "alert.closed"],
});
// `secret` is shown once. Store it next to your service's other secrets.or in the dashboard under Integrations → Webhooks. The URL must be https, and cannot point at a private address.
#Events
| Event | When |
|---|---|
alert.created | a new alert opened (a de-duplicated repeat does not send one) |
alert.acknowledged | someone acknowledged it, from any channel (data.acknowledgedBy says who) |
alert.closed | it was closed |
alert.exhausted | every escalation step ran and nobody answered |
approval.requested | an approval was asked for (data.approval) |
approval.decided | an approval was approved, denied, expired or cancelled (data.approval) |
coverage.requested, coverage.accepted, coverage.cancelled | someone asked for cover, it was taken, or it was withdrawn (data.coverage; no data.alert) |
handoff.note | a handoff note was left for a team (data.handoff; no data.alert) |
notification.failed | a push, text or call could not be delivered |
#The payload
{
"id": "0a1b2c3d-...",
"type": "alert.acknowledged",
"occurredAt": "2026-10-11T20:52:45.000Z",
"data": {
"alert": {
"id": "5b0f0c5e-...", "alias": "api-errors", "tinyId": 4821, "status": "acknowledged", "priority": "P1",
"message": "API error rate above 5%", "createdAt": "2026-10-11T20:50:04.000Z", "acknowledgedAt": "2026-10-11T20:52:45.000Z"
}
}
}data.alert has the same shape as Alert in the API reference. Some events add more fields next to alert.
alert.acknowledged adds acknowledgedBy: { "actor": "sms:<user id>", "userId": "<user id>", "name": "Adam" }. userId and name are null when an API key or an integration acknowledged rather than a person. The same object is on the alert as acknowledgedBy (null until someone acknowledges).
Headers on every delivery:
| Header | Value |
|---|---|
X-Treason-Event | the event type |
X-Treason-Delivery | a unique id for this event (also id in the body) |
X-Treason-Signature | t=<unix seconds>,v1=<hex> |
Content-Type | application/json |
#Verify the signature
Always verify. Anyone can POST to your URL. The signature is an HMAC-SHA256, keyed with your endpoint's secret, of the string "<t>.<raw body>". You must use the raw body bytes, before any JSON parsing, and you should reject timestamps more than five minutes old so a captured request cannot be replayed.
import { webhooks } from "@treason/sdk";
app.post("/hooks/treason", express.raw({ type: "application/json" }), (req, res) => {
try {
const event = webhooks.constructEvent(req.body, req.headers["x-treason-signature"], process.env.TREASON_WEBHOOK_SECRET!);
handle(event);
res.sendStatus(204);
} catch {
res.sendStatus(400);
}
});import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(secret: string, header: string, rawBody: string) {
const [t, v1] = header.split(",").map((p) => p.split("=")[1]!);
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
return v1!.length === expected.length && timingSafeEqual(Buffer.from(v1!), Buffer.from(expected));
}import hmac, hashlib, time
def verify(secret: str, header: str, raw_body: bytes) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False
expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(parts["v1"], expected)func Verify(secret, header string, raw []byte) bool {
var t, v1 string
for _, p := range strings.Split(header, ",") {
kv := strings.SplitN(p, "=", 2)
if kv[0] == "t" { t = kv[1] } else if kv[0] == "v1" { v1 = kv[1] }
}
ts, _ := strconv.ParseInt(t, 10, 64)
if math.Abs(float64(time.Now().Unix()-ts)) > 300 { return false }
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(t + "."))
mac.Write(raw)
return hmac.Equal([]byte(v1), []byte(hex.EncodeToString(mac.Sum(nil))))
}# debug a captured delivery offline
treason webhook verify --secret "$SECRET" --signature "t=1790000000,v1=..." body.json#Delivery, retries, and idempotency
- We expect a
2xxwithin 10 seconds. Anything else, including a timeout, is retried with exponential backoff. - Redirects are not followed.
- Deliveries are at least once. Use
X-Treason-Delivery(the eventid) to ignore a duplicate. - Order is not guaranteed across events. Each payload carries the alert's state at the time we sent it; if you need the truth now, call
GET /v1/alerts/{id}. - Respond fast and work later: acknowledge with
204, then do the slow thing in a queue.
#Testing your receiver
Sign a payload yourself with the helper the SDK exports, and post it to your handler:
import { webhooks } from "@treason/sdk";
const body = JSON.stringify({ id: "test-1", type: "alert.created", occurredAt: new Date().toISOString(), data: { alert: { id: "a", message: "test" } } });
await fetch("http://localhost:4100/hooks/treason", {
method: "POST",
headers: { "content-type": "application/json", "x-treason-signature": webhooks.signPayload("my-secret", body) },
body,
});Webhook URLs must be public https, so to receive real events on a laptop use a tunnel (any tool that gives you an https URL).