## Callback: template.status

`POST <your callback URL>`

Meta reviewed or changed one of the business's templates (approved, rejected with a reason, paused...).

### 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.waba_id` | string |  |
| `data.name` | string |  |
| `data.language` | string |  |
| `data.status` | string |  |
| `data.previous_status` | string | null |  |
| `data.reason` | string | null |  |

### Example

```json
{
  "id": "9a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d",
  "event": "template.status",
  "occurred_at": "2026-09-30T19:02:10+00:00",
  "business": {"external_id": "presec"},
  "sandbox": false,
  "data": {
    "waba_id": "102290129340398",
    "name": "fees_reminder",
    "language": "en_US",
    "status": "REJECTED",
    "previous_status": "PENDING",
    "reason": "INCORRECT_CATEGORY"
  }
}
```

### 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'] === 'template.status') {
        Cache::forget('paalchat:templates:'.$event['business']['external_id']);
    }

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