# Webhooks

> Get an HTTP call when rooms start and finish and when players join or leave.

Source: https://syncverse.aqaddoura.com/docs/webhooks

## Events

| Event | When |
| --- | --- |
| `room_started` | The first player connected to a new room. |
| `room_finished` | The room was removed: empty for 30 seconds, closed from the dashboard, or its node went down. |
| `participant_joined` | A player joined a room. |
| `participant_left` | A player left, disconnected or was kicked, or the room closed with them in it. |
| `ping` | You pressed Send test in the dashboard. |

A room that was created but never joined sends no events.

## Add an endpoint

In the dashboard open **Webhooks**, add an HTTPS URL and pick events. The signing secret (`whsec_…`) is shown once; rotate it any time.

## Payload

Each delivery is a JSON POST:

```json
{
  "id": "4b0d2c1e-8f1a-4c39-9a52-5f3f0f6a9d10",
  "event": "participant_joined",
  "createdAt": 1793980000000,
  "projectId": "prj_k3f9x2",
  "room": { "id": "room-16kndpU9itz5", "name": "arena", "maxPlayers": 8, "players": 2 },
  "participant": { "id": 2, "name": "Ava" }
}
```

**Headers**

```http
X-SyncVerse-Event: participant_joined
X-SyncVerse-Delivery: dlv_...
X-SyncVerse-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">
```

## Verify the signature

Check the signature against the raw request body with your signing secret. Signatures older than 5 minutes are refused.

```ts
import express from "express";
import { verifyWebhook } from "@syncverse/server-sdk";

app.post("/syncverse-webhook", express.raw({ type: "application/json" }), (req, res) => {
    const check = verifyWebhook(req.body, req.get("X-SyncVerse-Signature"), process.env.SYNCVERSE_WEBHOOK_SECRET!);
    if (!check.ok) return res.status(400).send(check.reason);
    const event = JSON.parse(req.body.toString("utf-8"));
    // event.event, event.room, event.participant
    res.sendStatus(204);
});
```

## Retries

Answer with any 2xx status within 10 seconds. Other answers and timeouts are retried after 10 seconds, then with the wait doubling up to 6 hours, for 8 attempts in total. Redirects are not followed. Use `X-SyncVerse-Delivery` to ignore a delivery you already handled. The dashboard lists recent deliveries and can retry one by hand.

### Addresses

Endpoints must be public: private, loopback and link-local addresses are refused.
