# Event webhooks

Percher POSTs signed JSON payloads to your webhook URL when events happen: useful for Discord/Slack bots, on-call pagers, or custom dashboards. Account-level: one URL per user, all events go there.

Events:
- `deploy.succeeded`: a deploy reached live (data: deployId, url, durationMs, kind "live"|"preview"). For "live" it fires only after the post-swap canary closes cleanly, so it's never contradicted by a deploy.failed for the same deployId. For live publishes, `url` is the auto-assigned `<app>.percher.run` domain; preview URLs use `<app>--p-<slug>.percher.run` (stable app previews use `<app>-preview.percher.run`). Custom domains are looked up separately.
- `deploy.failed`: any deploy fails (build, health, or canary).
- `app.crashed`: the watchdog detects a process exit or OOM.
- `app.unhealthy`: external uptime probe failed 3 times in a row (Starter and up).
- `app.recovered`: app responds again after an unhealthy window (pairs with a delivered unhealthy event).
- `domain.expiring`: a custom-domain SSL cert is within 7 days of expiry.
- `security.finding`: a security scan first finds a red-tier fixable/exploitable vulnerability in a live app (data: tier "red", findings[] with cve, component, severity, fixedIn, tier, deadlineAt). Yellow findings remain visible in the dashboard but do not trigger the automatic webhook. Each red finding is sent once, not on every re-scan.

`app.crashed` is container-level (process exited); `app.unhealthy` is reachability (DNS/Caddy/TLS/5xx). They're independent and both can fire for one incident. `app.unhealthy` has a 15-minute cooldown to avoid pager spam.

Setup: Account → Overview → Notifications, paste your receiver URL into the Webhook URL field. A signing secret is shown once; copy it into your receiver's `PERCHER_WEBHOOK_SECRET`. Changing the URL rotates the secret; clearing it clears the secret.

Example delivery — every event uses the same envelope (`data` carries the per-event fields plus `appId`/`appName` when the event concerns an app):
```
POST /your-receiver HTTP/1.1
Content-Type: application/json
X-Percher-Event: deploy.succeeded
X-Percher-Delivery: wh_k3v9x2m8q4za
X-Percher-Timestamp: 1782950400000
X-Percher-Signature: sha256=8f3a…

{
  "type": "deploy.succeeded",
  "id": "wh_k3v9x2m8q4za",
  "timestamp": 1782950400000,
  "data": {
    "deployId": "dep_a1b2c3",
    "url": "https://my-app.percher.run",
    "durationMs": 18400,
    "kind": "live",
    "appId": "app_x9y8z7",
    "appName": "my-app"
  }
}
```

Verify signatures: every delivery carries `X-Percher-Signature: sha256=<hex>`, an HMAC-SHA256 of `${timestamp}.${body}`. Reject anything older than a few minutes for replay protection.

```js
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(secret, req, body) {
  const sig = req.headers.get("X-Percher-Signature") ?? "";
  const ts = req.headers.get("X-Percher-Timestamp") ?? "";
  const expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");
  const provided = sig.replace(/^sha256=/, "");
  if (expected.length !== provided.length) return false;
  return timingSafeEqual(Buffer.from(expected), Buffer.from(provided));
}
```

Deliveries are best-effort with a 5-second timeout; redirects are not followed and failed responses are not retried. Use the final HTTPS receiver URL, return a 2xx response directly, and queue events in your receiver if you need retries or ordering.

Full guide: https://percher.app/docs/webhooks
