## Callback: campaign.updated

`POST <your callback URL>`

A campaign was scheduled, started sending, paused, resumed, completed or cancelled. Final `counts` arrive with completed and cancelled; read results with Get campaign.

### 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.campaign_id` | integer |  |
| `data.parent_id` | integer | null |  |
| `data.name` | string |  |
| `data.status` | string |  |
| `data.counts` | object | null |  |
| `data.started_at` | string | null |  |
| `data.completed_at` | string | null |  |

### Example

```json
{
  "id": "1d2e3f4a-5b6c-4d7e-8f9a-0b1c2d3e4f5a",
  "event": "campaign.updated",
  "occurred_at": "2026-10-06T08:41:10+00:00",
  "business": {"external_id": "presec"},
  "sandbox": false,
  "data": {
    "campaign_id": 12,
    "parent_id": null,
    "name": "October fee reminders",
    "status": "completed",
    "counts": {"audience": 412, "queued": 398, "skipped": 14, "cancelled": 0},
    "started_at": "2026-10-06T08:00:01+00:00",
    "completed_at": "2026-10-06T08:41:10+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'] === 'campaign.updated') {
        Broadcast::where('paalchat_campaign_id', $event['data']['campaign_id'])->update(['status' => $event['data']['status']]);
    }

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