# Webhooks, email and notifications

> Get told when a deployment fails, a budget is reached or an attack starts: in the dashboard’s bell, by email through your own provider, or as signed webhooks.

- Category: Monitor
- URL: https://www.forkrail.com/docs/notifications

## Events

| Event | When |
| --- | --- |
| `deployment.created` | A deployment starts. |
| `deployment.succeeded` | A deployment is ready. |
| `deployment.error` | A deployment failed. |
| `deployment.canceled` | A deployment was canceled. |
| `deployment.promoted` | Production moved to a deployment. |
| `deployment.rollback` | Production rolled back to a deployment. |
| `budget.reached` | Spend reached 50, 75 or 100% of a budget. |
| `budget.raised` | The default team budget grew for next month. |
| `spend.paused` | A project was paused at its budget. |
| `spend.fast` | A project spent over 10% of its monthly budget in an hour. |
| `attack.detected` | The system mitigations are refusing an attack. |
| `domain.certificate.renew.failed` | A custom domain’s certificate failed to renew. |

## Webhooks

1. **Add a webhook**

   Team **Settings → Webhooks** (owners): an HTTPS URL, the events it wants, and all projects or chosen ones. Up to 20 per install.

2. **Keep the secret**

   It’s shown once, when the webhook is made. Use it to check signatures.

3. **Send a test**

   **Send test event** posts a `webhook.test` so you can check your endpoint.

Each event is one POST with Vercel’s body shape: `{ "id", "type", "createdAt", "payload", "region" }`, where `payload` has the deployment, its links, its target and the project. Check the `x-forkrail-signature` header, the hex HMAC-SHA1 of the raw body with your secret:

**api/forkrail-webhook.ts**

```ts
import crypto from 'node:crypto'

export async function POST(request: Request) {
  const body = await request.text()
  const expected = crypto.createHmac('sha1', process.env.WEBHOOK_SECRET!).update(body).digest('hex')
  const given = request.headers.get('x-forkrail-signature') ?? ''
  if (given.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
    return new Response('bad signature', { status: 401 })
  }
  const event = JSON.parse(body)
  console.log(event.type, event.payload.deployment?.url)
  return new Response('ok')
}
```

- An answer other than 2xx within 30 seconds is retried after 1, 5 and 15 minutes, then 1, 2, 4, 8 and 12 hours, for up to a day. Each try is listed with the webhook for 30 days.
- `x-forkrail-event` names the event and `x-forkrail-delivery` the try.
- Webhooks reach public addresses only, and redirects aren’t followed.

## Email

Email is off until an owner sets it up under team **Settings → Email**. It goes through your own provider; forkrail sends nothing itself.

| Provider | Setup |
| --- | --- |
| Amazon SES | In your install’s account. The dashboard can add the From domain and lists its three DKIM records for your DNS. A new AWS account starts in SES’s sandbox (mail reaches only verified addresses) until you request production access in the SES console. |
| SMTP | Any other provider (Resend, Postmark, SendGrid, Mailgun, Google Workspace, your own server): host, port 587 (STARTTLS) or 465 (TLS), user name and password. Port 25 is blocked by Lambda. |

**Send test email** shows what the provider answered. SES costs $0.10 per 1,000 emails.

## The bell, and who hears what

- A **failed deployment** goes to whoever made it, if they’re a member (the GitHub user who pushed or who pressed the button), else to the owners.
- A **certificate renewal failure**, an **attack** and **budget alerts** go to the owners.
- Each person chooses, under **My notifications**, which kinds reach their bell and their email, and confirms their email address there.
- Notifications are kept for a year.
