# Evento de Instagram (/api/instagramEvents)

**Webhook** `POST` a la URL configurada en la conexión (evento `instagramEvents`)

Mismo endpoint, cabeceras y política de reintentos que Messenger. El
campo `type` discrimina dos eventos:

- `message`: mensaje directo recibido. Hoy solo texto,
  `message.attachment` siempre es `null`.
- `comment`: comentario nuevo en un post o reel. `comment.igCommentId`
  es el valor que se pasa como `commentId` a los endpoints de
  respuesta.

## Autenticación

- **WebhookSignature**: header `resender-signature`. Presente solo si la conexión tiene secreto de firma (`whsec_…`). `v1=` + HMAC-SHA256 en hex de `"<resender-event-id>.<resender-timestamp>.<cuerpo crudo>"`. Verificá sobre el cuerpo crudo, en tiempo constante y con una tolerancia de ±300 s sobre `resender-timestamp`. Si tu receptor no verifica HMAC y pide un header propio (por ejemplo `Authorization: Bearer …`), configuralo en la conexión: desde `Conexiones` o con `webhookHeaders` en `PATCH /api/meta/connections/{id}`. Se manda en cada evento de los tres canales, además de las cabeceras de firma.

- También puede llegar sin autenticación.

## Parámetros

| Nombre | En | Tipo | Requerido | Descripción |
| --- | --- | --- | --- | --- |
| `resender-event-id` | header | string | No | Id determinista del evento. El mismo evento reingerido trae el mismo id; usalo para deduplicar. (pattern: `^evt_[0-9a-f]{32}$`) |
| `resender-timestamp` | header | string | No | Epoch en segundos del momento de la firma. (pattern: `^[0-9]+$`) |
| `resender-signature` | header | string | No | `v1=` + HMAC-SHA256 hex. Ver `WebhookSignature`. (pattern: `^v1=[0-9a-f]{64}$`) |

## Cuerpo del evento

`application/json` (requerido)

Una de estas variantes:

**Variante 1**

| Campo | Tipo | Requerido | Descripción |
| --- | --- | --- | --- |
| `type` | `"message"` | Sí |  |
| `tenant` | object | Sí |  |
| `tenant.id` | string (uuid) | Sí |  |
| `page` | object | Sí |  |
| `page.id` | string (uuid) | Sí | Id de la conexión en Pontiun. |
| `page.channel` | `"messenger"` \| `"instagram"` \| `"whatsapp"` | Sí |  |
| `page.metaPageId` | string | Sí | Page id en Messenger; IG user id de la cuenta profesional en Instagram; `phone_number_id` en WhatsApp. Es el `pageId` de los endpoints de envío. |
| `page.name` | string | Sí |  |
| `page.username` | string \| null | Sí | @handle. Solo Instagram; `null` en Messenger y WhatsApp. |
| `page.phoneNumberId` | string | No | Solo WhatsApp. El mismo valor que `metaPageId`. |
| `page.wabaId` | string \| null | No | Solo WhatsApp. Cuenta de WhatsApp Business del número. |
| `page.onboardingMode` | `"standard"` \| `"coexistence"` \| null | No | Solo WhatsApp. `coexistence` si el número también se usa desde la app de WhatsApp Business. |
| `conversation` | object | Sí |  |
| `conversation.id` | string (uuid) | Sí | Usable como `conversationId` en los endpoints de envío. |
| `conversation.contactId` | string | Sí | PSID (Messenger), IGSID (Instagram) o `wa_id` (WhatsApp) del contacto. Es el `recipientId` de los endpoints de envío. |
| `message` | object | Sí |  |
| `message.id` | string (uuid) | Sí |  |
| `message.metaMessageId` | string \| null | Sí |  |
| `message.eventType` | `"message"` \| `"postback"` | Sí |  |
| `message.postbackPayload` | string \| null | Sí | Payload del botón cuando `eventType` es `postback`. |
| `message.direction` | `"inbound"` \| `"outbound"` | Sí |  |
| `message.status` | `"received"` \| `"sent"` \| `"failed"` | Sí |  |
| `message.text` | string | Sí | `""` cuando el mensaje no trajo texto. |
| `message.attachment` | object \| null | Sí | Siempre presente; `null` cuando no hubo adjunto. En Instagram es siempre `null` por ahora. |
| `message.createdAt` | string (date-time) | Sí | Hora del mensaje según Meta. Es el orden de la conversación. |
| `message.origin` | `"customer"` \| `"resender_api"` \| `"business_app"` \| `"history"` \| `"system"` | No | Solo WhatsApp. Quién produjo el mensaje; `business_app` es un eco escrito desde la app de WhatsApp Business. |
| `message.historical` | boolean | No | Solo WhatsApp. Siempre `false` en el webhook (el historial no se reenvía). |
| `message.replyToProviderMessageId` | string \| null | No | Solo WhatsApp. `wamid` del mensaje al que responde. |
| `message.deliveryStatus` | `"accepted"` \| `"sent"` \| `"delivered"` \| `"read"` \| `"failed"` \| `"deleted"` \| null | No | Solo WhatsApp. Estado que reportó Meta para un saliente. |

**Variante 2**

| Campo | Tipo | Requerido | Descripción |
| --- | --- | --- | --- |
| `type` | `"comment"` | Sí |  |
| `tenant` | object | Sí |  |
| `tenant.id` | string (uuid) | Sí |  |
| `page` | object | Sí |  |
| `page.id` | string (uuid) | Sí | Id de la conexión en Pontiun. |
| `page.channel` | `"messenger"` \| `"instagram"` \| `"whatsapp"` | Sí |  |
| `page.metaPageId` | string | Sí | Page id en Messenger; IG user id de la cuenta profesional en Instagram; `phone_number_id` en WhatsApp. Es el `pageId` de los endpoints de envío. |
| `page.name` | string | Sí |  |
| `page.username` | string \| null | Sí | @handle. Solo Instagram; `null` en Messenger y WhatsApp. |
| `page.phoneNumberId` | string | No | Solo WhatsApp. El mismo valor que `metaPageId`. |
| `page.wabaId` | string \| null | No | Solo WhatsApp. Cuenta de WhatsApp Business del número. |
| `page.onboardingMode` | `"standard"` \| `"coexistence"` \| null | No | Solo WhatsApp. `coexistence` si el número también se usa desde la app de WhatsApp Business. |
| `comment` | object | Sí |  |
| `comment.id` | string (uuid) | Sí | uuid del comentario en Pontiun. |
| `comment.igCommentId` | string \| null | Sí | Id de Meta. Es el `commentId` de los endpoints de respuesta. |
| `comment.parentIgCommentId` | string \| null | Sí | Informado cuando el comentario responde a otro. |
| `comment.mediaId` | string | Sí |  |
| `comment.mediaProductType` | string \| null | Sí | Por ejemplo `FEED` o `REELS`. |
| `comment.from` | object | Sí |  |
| `comment.from.igId` | string | Sí | IGSID de quien comentó. |
| `comment.from.username` | string \| null | Sí |  |
| `comment.direction` | `"inbound"` | Sí |  |
| `comment.status` | `"received"` | Sí |  |
| `comment.text` | string | Sí |  |
| `comment.createdAt` | string (date-time) | Sí |  |

### Ejemplos

Ejemplo `mensaje` — Mensaje directo:

```json
{
  "type": "message",
  "tenant": {
    "id": "2b7f2a1c-0d3e-4f5a-9b6c-7d8e9f0a1b2c"
  },
  "page": {
    "id": "7a6b5c4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d",
    "channel": "instagram",
    "metaPageId": "17841400000000000",
    "name": "Tienda Demo",
    "username": "tiendademo"
  },
  "conversation": {
    "id": "9a8b7c6d-5e4f-4a3b-2c1d-0e9f8a7b6c5d",
    "contactId": "1234567890123456"
  },
  "message": {
    "id": "1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e",
    "metaMessageId": "aWdfZG1faXRlbToxOklHTWVzc2FnZUlEOjE3ODQxNDAwMDAwMDAwMDAw",
    "eventType": "message",
    "postbackPayload": null,
    "direction": "inbound",
    "status": "received",
    "text": "Hola, ¿tienen talle 38?",
    "attachment": null,
    "createdAt": "2026-09-10T14:03:21.000Z"
  }
}
```

Ejemplo `comentario` — Comentario en un post:

```json
{
  "type": "comment",
  "tenant": {
    "id": "2b7f2a1c-0d3e-4f5a-9b6c-7d8e9f0a1b2c"
  },
  "page": {
    "id": "7a6b5c4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d",
    "channel": "instagram",
    "metaPageId": "17841400000000000",
    "name": "Tienda Demo",
    "username": "tiendademo"
  },
  "comment": {
    "id": "8f1c2d3e-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
    "igCommentId": "17900000000000000",
    "parentIgCommentId": null,
    "mediaId": "17850000000000000",
    "mediaProductType": "FEED",
    "from": {
      "igId": "1234567890123456",
      "username": "cliente_demo"
    },
    "direction": "inbound",
    "status": "received",
    "text": "¿Precio?",
    "createdAt": "2026-09-10T14:03:21.000Z"
  }
}
```

## Respuestas esperadas de tu webhook

### 408

Se reintenta.

### 429

Se reintenta.

### 2XX

Entrega aceptada. El cuerpo se ignora.

### 4XX

Fallo permanente. No se reintenta.

### 5XX

Se reintenta.