# Webhooks

Rassilo calls your server on every event: delivery, failure, inbound message, wallet balance.

> Webhooks are coming soon: they are not available in the API yet. Today, `POST /v1/messages` answers `submitted`.

## Events

| Event | When |
| --- | --- |
| `message.submitted` | The message was handed to the operator. |
| `message.delivered` | The operator confirms delivery. |
| `message.failed` | The message could not be delivered; `error` gives the reason. |
| `message.read` | The recipient read the message (WhatsApp, push). |
| `inbound.received` | A customer wrote to you. |
| `wallet.low_balance` | The wallet balance fell below your alert threshold. |
| `wallet.topup_confirmed` | The payment provider confirmed a top-up. |

## Payload

*Request your server receives*

```http
POST /hooks/rassilo HTTP/1.1
Host: api.karampay.example
Content-Type: application/json
Rassilo-Signature: t=1792929604,v1=5f2b…c81e

{
  "id": "evt_0001",
  "type": "message.delivered",
  "created_at": "2026-10-25T12:00:04Z",
  "data": {
    "provisionalId": "msg_provisoire_0001",
    "channel": "sms",
    "to": "+22200000000",
    "status": "delivered"
  }
}
```

## Verify the signature

Every call carries the `Rassilo-Signature` header: a timestamp `t` and an HMAC-SHA256 signature `v1` of the raw body, computed with the webhook secret. Reject any call whose signature does not match.

**Node.js**

```node
import crypto from 'node:crypto';

export function verify(rawBody, header, secret) {
  const { t, v1 } = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${t}.${rawBody}`)
    .digest('hex');
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1));
}
```

**Python**

```python
import hashlib, hmac

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    signed = f"{parts['t']}.".encode() + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])
```

**PHP**

```php
<?php
function verify(string $rawBody, string $header, string $secret): bool {
    parse_str(str_replace(',', '&', $header), $parts);
    $expected = hash_hmac('sha256', $parts['t'] . '.' . $rawBody, $secret);
    return hash_equals($expected, $parts['v1']);
}
```

## Responses and retries

- Answer `2xx` within 10 seconds; process the event afterwards.
- Otherwise Rassilo retries with a growing delay. Each delivery’s history and the « Retry » button are in the dashboard.
- The same event can arrive twice: de-duplicate on `id`.
