## Callback: contact.updated

`POST <your callback URL>`

A contact's details, custom fields or tags changed.

### 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.contact` | object |  |
| `data.contact.id` | integer |  |
| `data.contact.external_id` | string | null | Your own id for the person. |
| `data.contact.name` | string | null |  |
| `data.contact.phone` | string | null | WhatsApp number, digits. |
| `data.contact.email` | string | null |  |
| `data.contact.locale` | string | null |  |
| `data.contact.timezone` | string | null |  |
| `data.contact.status` | string |  |
| `data.contact.custom_fields` | object | The business's own fields (see List contact fields). |
| `data.contact.preferences` | object | What the contact wants to receive - false turns it off; missing means on. |
| `data.contact.preferences.channels` | object |  |
| `data.contact.preferences.topics` | object | fees, results, attendance, pta, marketing, system. |
| `data.contact.tags` | array of strings |  |
| `data.contact.identities` | array of objects |  |
| `data.contact.identities[].channel` | string |  |
| `data.contact.identities[].address` | string |  |
| `data.contact.identities[].profile_name` | string | null | The name the person shows on that channel. |
| `data.contact.identities[].last_seen_at` | string | null |  |
| `data.contact.created_at` | string |  |
| `data.contact.updated_at` | string |  |

### Example

```json
{
  "id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
  "event": "contact.updated",
  "occurred_at": "2026-10-01T09:12:01+00:00",
  "business": {"external_id": "presec"},
  "sandbox": false,
  "data": {
    "contact": {
      "id": 41,
      "external_id": "parent-77",
      "name": "Ama Mensah",
      "phone": "233241234567",
      "email": null,
      "locale": null,
      "timezone": null,
      "status": "active",
      "custom_fields": {"class": "SHS 2"},
      "tags": ["parent"],
      "identities": [
        {
          "channel": "whatsapp",
          "address": "233241234567",
          "profile_name": "Ama Mensah",
          "last_seen_at": "2026-10-01T09:12:00+00:00"
        }
      ],
      "created_at": "2026-10-01T08:00:00+00:00",
      "updated_at": "2026-10-01T09:12:00+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'] === 'contact.updated') {
        Guardian::syncFromPaalChat($event['data']['contact']);
    }

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