## Callback: notification.updated

`POST <your callback URL>`

A notification was delivered on one of its channels, or every channel failed (`attempts` says what happened on each).

### Headers

| Name | Description |
|---|---|
| `X-PaalChat-Event` |  |
| `X-PaalChat-Delivery` | Unique per event (equals body `id`). De-duplicate on it. |
| `X-PaalChat-Signature` | `t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>`. Reject if invalid or older than 300 seconds. |

### Body

| Field | Type | Description |
|---|---|---|
| `id` | string | Equals X-PaalChat-Delivery. |
| `sandbox` | boolean | true for sandbox businesses (test keys) - nothing reached WhatsApp. |
| `event` | any |  |
| `occurred_at` | string |  |
| `business` | object |  |
| `business.external_id` | string |  |
| `data` | object |  |
| `data.notification_id` | integer |  |
| `data.reference` | string | null |  |
| `data.status` | string |  |
| `data.channel` | string | null |  |
| `data.attempts` | array of objects |  |

### Example

```json
{
  "id": "3f4a5b6c-7d8e-4f9a-0b1c-2d3e4f5a6b7c",
  "event": "notification.updated",
  "occurred_at": "2026-10-02T11:04:20+00:00",
  "business": {"external_id": "presec"},
  "sandbox": false,
  "data": {
    "notification_id": 77,
    "reference": "closing-2026-10-02",
    "status": "delivered",
    "channel": "sms",
    "attempts": [
      {
        "channel": "whatsapp",
        "outcome": "failed: 131026",
        "message_id": 901,
        "at": "2026-10-02T11:00:02+00:00"
      },
      {
        "channel": "sms",
        "outcome": "sent",
        "message_id": 902,
        "at": "2026-10-02T11:00:03+00:00"
      }
    ]
  }
}
```

### Verify and handle (PHP)

```php
// routes/api.php: Route::post('/paalchat/callback', PaalChatCallbackController::class);
public function __invoke(Request $request)
{
    $header = (string) $request->header('X-PaalChat-Signature');
    $raw = $request->getContent();

    if (! preg_match('/^t=(\d+),v1=([a-f0-9]{64})$/', $header, $m)
        || abs(time() - (int) $m[1]) > 300
        || ! hash_equals(hash_hmac('sha256', $m[1].'.'.$raw, config('services.paalchat.callback_secret')), $m[2])) {
        abort(401);
    }

    // Process each delivery once.
    if (! Cache::add('paalchat:'.$request->header('X-PaalChat-Delivery'), true, now()->addDays(2))) {
        return response()->noContent();
    }

    $event = json_decode($raw, true);

    if ($event['event'] === 'notification.updated') {
        Alert::where('reference', $event['data']['reference'])->update(['status' => $event['data']['status'], 'channel' => $event['data']['channel']]);
    }

    return response()->noContent();
}
```
