{
  "openapi": "3.1.0",
  "info": {
    "title": "Abrachat API",
    "version": "1.0.0",
    "description": "\nLa API de Abrachat te da lo que pasa en tus conversaciones de WhatsApp, Instagram y el chat de tu web, y lo que la IA saca de cada una: personas, conversaciones, mensajes, el análisis de cada lead y campañas. Con los webhooks, tu sistema se entera en el momento.\n\n## Primeros pasos\n\n1. En Abrachat, entrá a **Configuración → API y webhooks** (hace falta permiso para editar integraciones).\n2. Creá una **API key**: ponele un nombre y elegí qué puede hacer. La key se muestra una sola vez: guardala en un lugar seguro.\n3. Probala:\n\n```bash\ncurl https://ai.abrachat.com/api/v1/me \\\n  -H \"Authorization: Bearer abk_live_TU_KEY\"\n```\n\n```json\n{ \"data\": { \"object\": \"account\", \"id\": 73, \"name\": \"Tu Inmobiliaria\", \"key\": { \"id\": 4, \"scopes\": [\"persons:read\"] } } }\n```\n\n## Autenticación\n\nCada pedido lleva la key en el header `Authorization: Bearer abk_live_…`. La key es de tu cuenta: todo lo que devuelve es de tu cuenta y de nadie más. Si se filtra, revocala en la misma pantalla y creá otra; deja de andar en el momento.\n\nUna key de una cuenta suspendida no anda.\n\n## Permisos\n\nCada key tiene sólo los permisos que le diste. Si un pedido necesita uno que no tiene, la respuesta es `403` con el permiso que falta.\n\n| Permiso | Para qué |\n|---|---|\n| `persons:read` | Contactos con sus datos, origen y lead score. |\n| `persons:write` | Alta (sin duplicar por teléfono o email) y cambios. |\n| `conversations:read` | Conversaciones y sus mensajes, con quién escribió cada uno. |\n| `conversations:write` | Asignar, pausar la IA, notas internas, etiquetas, cerrar. |\n| `leads:read` | Intención, urgencia, score, resumen, señales y tareas sugeridas. |\n| `campaigns:read` | Campañas de WhatsApp, plantillas y resultados. |\n| `campaigns:write` | Arma una campaña con una plantilla aprobada y la envía o agenda. |\n| `messages:write` | Envía una plantilla aprobada a un teléfono, sin armar una campaña. |\n| `webhooks:manage` | Suscripciones a eventos por API. |\n| `agents:read` | Agentes, capacidades, tools instaladas y prompts. |\n| `agents:write` | Editar prompts y configuración, activar/desactivar tools, borrar capacidades. |\n| `tools:read` | Las tools que creó la cuenta, con su manifiesto y su estado. |\n| `tools:write` | Guardar, probar contra la API real y publicar tools en la cuenta. |\n| `channels:read` | Canales conectados (WhatsApp, Instagram, Messenger) y su salud. |\n| `channels:manage` | Sincronizar plantillas, desconectar canales. |\n| `kb:read` | Fuentes y archivos del catálogo del agente. |\n| `kb:write` | Sync de fuentes externas, borrar archivos. |\n| `automations:read` | Listado, pasos, última corrida y acciones pendientes. |\n| `automations:write` | Crear, activar, pausar y correr automatizaciones a demanda. |\n| `automations:approve` | Aprobar o saltear las acciones que las automatizaciones dejan en revisión. |\n| `team:read` | Operadores, roles y departamentos del cliente. |\n| `team:manage` | Invitar, cambiar rol o desactivar operadores. |\n| `metrics:read` | Conversaciones, costos LLM, leads, campañas. |\n\n## Formato\n\nTodo es JSON en UTF-8. Las fechas van en ISO 8601 y en UTC (`2026-10-15T14:30:00.000Z`). Los nombres de los campos están en inglés y en `snake_case`; los textos que escribe la IA, en el idioma de la conversación.\n\nUna respuesta trae lo pedido en `data`. Las listas suman `has_more` y `next_cursor`.\n\n## Paginación\n\nLas listas vienen de a `limit` (default 50, hasta 100). Para la página siguiente, pasá el `next_cursor` como `?cursor=`. Cuando `has_more` es `false`, no hay más.\n\n```bash\ncurl \"https://ai.abrachat.com/api/v1/persons?limit=100&cursor=eyJpZCI6MTIzNH0\" \\\n  -H \"Authorization: Bearer abk_live_TU_KEY\"\n```\n\nPara sincronizar con tu sistema, pedí lo cambiado desde la última vez con `updated_since` (personas y conversaciones), o usá los webhooks.\n\n## Errores\n\nUn error trae el código HTTP que corresponde y este cuerpo:\n\n```json\n{ \"error\": { \"code\": \"INVALID_INPUT\", \"message\": \"phone: al menos 8 dígitos, con código de país.\", \"field\": \"phone\" }, \"request_id\": \"8c1d…\" }\n```\n\n| Código | Qué pasó |\n|---|---|\n| `400 INVALID_INPUT` | Un dato del pedido no sirve: `field` dice cuál. |\n| `401 UNAUTHORIZED` | Falta la key, o es inválida, está revocada o vencida. |\n| `403 FORBIDDEN` | A la key le falta un permiso, o la cuenta está suspendida. |\n| `404 NOT_FOUND` | No existe en tu cuenta. |\n| `409` | Choca con el estado actual: `CONFLICT`, o `WHATSAPP_BLOCKED` si tu número de WhatsApp tiene un bloqueo de Meta. |\n| `429 RATE_LIMITED` | Te pasaste del límite por key: esperá lo que dice `Retry-After`. |\n| `429 RATE_LIMITED_ORG` | Te pasaste del límite por cuenta (sumando todas tus keys): esperá lo que dice `Retry-After`. |\n| `500 INTERNAL_ERROR` | Falló de nuestro lado. Si se repite, escribinos con el `request_id`. |\n\n## Límites\n\nDos cupos independientes: **120 pedidos por minuto por key** y **600 por minuto sumando todas las keys de tu cuenta**. El segundo evita que repartir el tráfico en N keys burle el primero. Cada respuesta trae `X-RateLimit-Limit`, `X-RateLimit-Remaining` y `X-RateLimit-Reset` (por key) más `X-RateLimit-Org-Limit`, `X-RateLimit-Org-Remaining` y `X-RateLimit-Org-Reset` (por cuenta, segundos Unix). Para cargar muchas personas usá `POST /persons/batch` (100 por pedido). Si tu uso legítimo supera estos topes, escribinos.\n\n## Personas: una por teléfono, email o id externo\n\nCrear una persona que ya existe no la duplica: `POST /persons` busca primero por `external` (tu id), después por teléfono o email, y si la encuentra la devuelve con `created: false` y sólo completa los campos que tenía vacíos. Lo que alguien del equipo escribió en Abrachat no se pisa. Para cambiar un dato, usá `PATCH`.\n\nLos teléfonos van con código de país: `5491155551234` (Argentina, celular) o `+54 9 11 5555-1234`.\n\n## Campañas\n\nUna campaña envía una plantilla de WhatsApp aprobada por Meta a una lista de personas (`GET /templates` te dice cuáles tenés). Se crea como borrador; la lanzás con `launch: \"now\"`, con una fecha, o después con `POST /campaigns/{id}/launch`.\n\nSi la plantilla es de marketing, al enviarla Abrachat omite a quien se dio de baja de marketing y a quien recibió una plantilla de marketing en los últimos días, y lo deja registrado. Las de utilidad no tienen ese tope: una persona puede recibir varias seguidas. Enviá sólo a personas que te dieron su número para que les escribas: las reglas de WhatsApp son estrictas y los mensajes no pedidos pueden bloquear tu número.\n\n### Botón con un link distinto en cada envío\n\nWhatsApp no admite texto con un link adentro del mensaje: lo que se puede tocar es una URL escrita tal cual o un botón. Para que el botón abra una página distinta en cada envío, la URL del botón termina con `{{1}}` (`https://tusitio.com/cargas/{{1}}`): la parte fija la aprueba Meta y el final lo enviás vos. `GET /templates` lo dice en `url_buttons`, y el valor va en `button_variables` al crear la campaña:\n\n```json\n{\n  \"name\": \"Carga 8421\",\n  \"template\": { \"name\": \"carga_nueva\" },\n  \"variables\": [{ \"field\": \"name\" }, { \"value\": \"Posadas\" }, { \"value\": \"Oberá\" }, { \"value\": \"Camión\" }],\n  \"button_variables\": [{ \"value\": \"8421\" }],\n  \"person_ids\": [123],\n  \"launch\": \"now\"\n}\n```\n\n## Enviar un mensaje a una persona\n\nPara avisos de a uno (una carga nueva, un turno, un pedido listo) no hace falta una campaña: `POST /messages` envía una plantilla aprobada a un teléfono, o un texto libre si la persona te escribió en las últimas 24 horas. Necesita el permiso `messages:write`.\n\n```bash\ncurl https://ai.abrachat.com/api/v1/messages \\\n  -H \"Authorization: Bearer abk_live_TU_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"to\": \"5491155551234\",\n    \"name\": \"Juan\",\n    \"template\": { \"name\": \"carga_nueva\", \"language\": \"es_AR\" },\n    \"variables\": [\"Juan\", \"Posadas\", \"Oberá\"],\n    \"button_variables\": [\"8421\"]\n  }'\n```\n\n```json\n{ \"data\": { \"object\": \"message\", \"status\": \"sent\", \"to\": \"5491155551234\", \"conversation_id\": 812, \"conversation_created\": true, \"person_id\": 123, \"template\": { \"name\": \"carga_nueva\", \"language\": \"es_AR\", \"category\": \"UTILITY\" }, \"text\": \"Hola Juan, hay una carga de Posadas a Oberá.\", \"wa_message_id\": \"wamid.…\" } }\n```\n\n- **A quién**: `to` (un teléfono con código de país) o `person_id`. Si la persona no existe, se crea.\n- **Variables**: un texto por cada `{{n}}` del cuerpo, en orden. `button_variables`, uno por cada botón de link con variable.\n- **Sin tope de frecuencia**: la misma persona puede recibir varios mensajes seguidos. El tope de una por semana es sólo de las campañas de marketing.\n- **Bajas**: una plantilla de marketing no le sale a quien pidió no recibir promociones (`409 OPTED_OUT`). Una de utilidad sí.\n- **Cuando WhatsApp no lo acepta**: `422 WHATSAPP_REJECTED`, con el motivo de Meta en `message`.\n- **La respuesta de la persona** cae en `conversation_id` y la atiende el asistente, salvo que envíes `\"assistant_replies\": false`. Con el webhook `message.received` te enterás en el momento.\n- **Reintentos**: si tu pedido corta por tiempo sin respuesta, puede haber salido igual. Antes de reintentar, mirá los mensajes de la conversación.\n\n### Texto libre, dentro de las 24 horas\n\nWhatsApp deja enviar un mensaje con el texto que quieras sólo durante las 24 horas siguientes al último mensaje de la persona. Con esa ventana abierta, enviá `text` en vez de `template`:\n\n```json\n{ \"to\": \"5491155551234\", \"text\": \"Juan, la carga sale mañana a las 8 del depósito de Posadas.\" }\n```\n\nTambién podés apuntar a la conversación con `conversation_id` (el que llega en el webhook `message.received`). Si pasaron más de 24 horas, o la persona nunca te escribió, la respuesta es `409 WINDOW_CLOSED`: ahí va una plantilla. El mensaje queda en la conversación a nombre de \"API\".\n\nEl `201` dice que WhatsApp aceptó el mensaje, no que la persona lo recibió. Cada mensaje abre una conversación de tu plan si no había una en las últimas 24 horas.\n\n## Tools para el asistente\n\nUna tool es algo que el asistente puede hacer en medio de una conversación: consultar tu stock, crear un pedido, buscar un turno. Se escribe como un manifiesto en JSON, se prueba contra tu API y se publica en la cuenta, todo por esta API o por el MCP.\n\nEstá pensado para que lo haga tu agente de código (Claude Code, Cursor, Codex): la guía completa está en [/developers/tools](/developers/tools), y en Markdown para dársela al agente en [/developers/tools.md](/developers/tools.md).\n\n## Webhooks\n\nUn webhook le avisa a tu servidor cuando pasa algo. Lo creás en **Configuración → API y webhooks** o con `POST /webhooks`: una URL https pública y los eventos que te interesan.\n\n### Eventos\n\n| Evento | Cuándo |\n|---|---|\n| `message.received` | Una persona escribió en una conversación. |\n| `message.sent` | El asistente o alguien del equipo respondió. |\n| `lead.updated` | La IA actualizó el análisis de una conversación: intención, score, resumen, tareas. |\n| `conversation.handoff` | El asistente pasó la conversación a una persona del equipo. |\n| `person.created` | Se creó un contacto (por una conversación, a mano o por API). |\n\nCada entrega es un `POST` con este cuerpo:\n\n```json\n{\n  \"id\": \"evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1\",\n  \"type\": \"message.received\",\n  \"created_at\": \"2026-10-15T14:30:00.000Z\",\n  \"data\": { \"message\": { \"id\": 991, \"conversation_id\": 58615, \"sender\": \"person\", \"text\": \"Hola, ¿sigue disponible?\" }, \"conversation\": { \"id\": 58615, \"channel\": \"whatsapp\" } }\n}\n```\n\ny estos headers: `Abrachat-Event`, `Abrachat-Delivery` (id de la entrega) y `Abrachat-Signature`.\n\n### Verificar la firma\n\nCada webhook tiene un secreto (`whsec_…`, se muestra al crearlo). La firma es `t=<segundos Unix>,v1=<HMAC-SHA256 en hex>`, calculada sobre `<t>.<cuerpo crudo>` con el secreto. Verificala antes de confiar en el evento, con el cuerpo **tal como llegó** (sin volver a serializarlo), y rechazá las firmas de más de 5 minutos.\n\n```js\nimport crypto from \"node:crypto\";\n\nfunction verify(rawBody, header, secret) {\n  const parts = Object.fromEntries(header.split(\",\").map((p) => p.split(\"=\")));\n  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;\n  const expected = crypto.createHmac(\"sha256\", secret).update(`${parts.t}.${rawBody}`).digest(\"hex\");\n  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? \"\"));\n}\n```\n\n```python\nimport hmac, hashlib, time\n\ndef verify(raw_body: bytes, header: str, secret: str) -> bool:\n    parts = dict(p.split(\"=\", 1) for p in header.split(\",\"))\n    if abs(time.time() - int(parts[\"t\"])) > 300:\n        return False\n    expected = hmac.new(secret.encode(), f'{parts[\"t\"]}.'.encode() + raw_body, hashlib.sha256).hexdigest()\n    return hmac.compare_digest(expected, parts.get(\"v1\", \"\"))\n```\n\n```php\nfunction verify(string $rawBody, string $header, string $secret): bool {\n    parse_str(str_replace(',', '&', $header), $parts);\n    if (abs(time() - (int) $parts['t']) > 300) return false;\n    $expected = hash_hmac('sha256', $parts['t'] . '.' . $rawBody, $secret);\n    return hash_equals($expected, $parts['v1'] ?? '');\n}\n```\n\n### Reintentos\n\nRespondé con un `2xx` en menos de 10 segundos; procesá el evento después si lleva más. Cualquier otra respuesta se reintenta: al minuto, a los 5 minutos, a los 30, a las 2 horas, a las 6, a las 12 y a las 24. Un evento puede llegar más de una vez: usá `id` para no procesarlo dos veces. Tampoco hay orden garantizado entre eventos.\n\nSi un endpoint falla 50 entregas seguidas, el webhook se apaga solo y lo ves en la pantalla. Cuando lo arregles, prendelo de nuevo.\n\nPara probarlo, `POST /webhooks/{id}/test` (o el botón **Probar**) envía un evento `ping`.\n\n## Soporte\n\nEscribinos a **info@abrachat.com** con el `request_id` del pedido que falló.\n",
    "contact": {
      "name": "Abrachat",
      "email": "info@abrachat.com",
      "url": "https://abrachat.ai"
    }
  },
  "servers": [
    {
      "url": "https://ai.abrachat.com/api/v1",
      "description": "Producción"
    }
  ],
  "tags": [
    {
      "name": "Cuenta"
    },
    {
      "name": "Personas",
      "description": "Los contactos de tu cuenta. Uno por teléfono, email o id externo: crear dos veces la misma persona devuelve la que ya existe."
    },
    {
      "name": "Conversaciones",
      "description": "Cada conversación con sus mensajes, de cualquier canal."
    },
    {
      "name": "Leads",
      "description": "Lo que la IA saca de cada conversación: intención, urgencia, score, resumen, señales y tareas sugeridas."
    },
    {
      "name": "Campañas",
      "description": "Campañas de WhatsApp con plantillas aprobadas por Meta."
    },
    {
      "name": "Mensajes",
      "description": "Un mensaje de WhatsApp a una persona, con una plantilla aprobada por Meta."
    },
    {
      "name": "Tools",
      "description": "Lo que el asistente puede hacer además de hablar: llamar a tu API para consultar o cargar datos. Se escriben como un manifiesto en JSON, se prueban contra la API real y se publican en la cuenta. La guía completa, pensada para dársela a un agente de código, está en [/developers/tools](/developers/tools)."
    },
    {
      "name": "Administrar webhooks",
      "description": "Altas, cambios y pruebas de los webhooks de tu cuenta. Los eventos que envían están en la sección Webhooks."
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "Cuenta"
        ],
        "summary": "La cuenta de la key",
        "operationId": "getMe",
        "security": [
          {
            "apiKey": [
              "any"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Account"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      }
    },
    "/persons": {
      "get": {
        "tags": [
          "Personas"
        ],
        "summary": "Listar personas",
        "operationId": "listPersons",
        "security": [
          {
            "apiKey": [
              "persons:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Busca en nombre, email, teléfono y empresa.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "email",
            "in": "query",
            "required": false,
            "description": "Email exacto.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "phone",
            "in": "query",
            "required": false,
            "description": "Teléfono exacto (sólo dígitos, con código de país).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Cambiadas desde esta fecha (ISO 8601).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "include_archived",
            "in": "query",
            "required": false,
            "description": "Incluir archivadas.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Cuántos por página (1 a 100, default 50).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "El `next_cursor` de la respuesta anterior.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Person"
                      }
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "Hay más resultados: pedilos con `cursor`."
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Pasalo como `?cursor=` para la página siguiente."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      },
      "post": {
        "tags": [
          "Personas"
        ],
        "summary": "Crear una persona (o encontrar la que ya existe)",
        "description": "Hace falta `phone`, `email` o `external`. Si ya hay una persona con alguno de ellos, se devuelve esa (200, `created: false`) y sólo se completan sus campos vacíos.",
        "operationId": "createPerson",
        "security": [
          {
            "apiKey": [
              "persons:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "phone": {
                    "type": "string",
                    "description": "Con código de país, sólo dígitos o con +: 5491155551234. Identifica a la persona."
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Identifica a la persona."
                  },
                  "external": {
                    "type": "object",
                    "properties": {
                      "source": {
                        "type": "string",
                        "maxLength": 32
                      },
                      "id": {
                        "type": "string",
                        "maxLength": 128
                      }
                    },
                    "description": "Tu propio id (ej. el de tu CRM): identifica a la persona antes que el teléfono o el email."
                  },
                  "company": {
                    "type": "string"
                  },
                  "job_title": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  },
                  "city": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string"
                  },
                  "country": {
                    "type": "string"
                  },
                  "postal_code": {
                    "type": "string"
                  },
                  "website": {
                    "type": "string"
                  },
                  "linkedin": {
                    "type": "string"
                  },
                  "tax_id": {
                    "type": "string"
                  },
                  "birthday": {
                    "type": "string",
                    "format": "date"
                  },
                  "custom_fields": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Campos propios de la cuenta, por slug. Se mezclan con los que ya tiene: una clave en null la borra."
                  },
                  "utm": {
                    "type": "object",
                    "properties": {
                      "source": {
                        "type": "string"
                      },
                      "medium": {
                        "type": "string"
                      },
                      "campaign": {
                        "type": "string"
                      }
                    },
                    "description": "Sólo al crear: el primer origen de la persona."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ya existía",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    },
                    "created": {
                      "type": "boolean",
                      "const": false
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    },
                    "created": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/persons/batch": {
      "post": {
        "tags": [
          "Personas"
        ],
        "summary": "Crear varias personas",
        "description": "Hasta 100 por pedido, con las mismas reglas que una por una. Una que falla no frena a las demás.",
        "operationId": "batchPersons",
        "security": [
          {
            "apiKey": [
              "persons:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "persons"
                ],
                "properties": {
                  "persons": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "maxLength": 255
                        },
                        "phone": {
                          "type": "string",
                          "description": "Con código de país, sólo dígitos o con +: 5491155551234. Identifica a la persona."
                        },
                        "email": {
                          "type": "string",
                          "format": "email",
                          "description": "Identifica a la persona."
                        },
                        "external": {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "maxLength": 32
                            },
                            "id": {
                              "type": "string",
                              "maxLength": 128
                            }
                          },
                          "description": "Tu propio id (ej. el de tu CRM): identifica a la persona antes que el teléfono o el email."
                        },
                        "company": {
                          "type": "string"
                        },
                        "job_title": {
                          "type": "string"
                        },
                        "address": {
                          "type": "string"
                        },
                        "city": {
                          "type": "string"
                        },
                        "state": {
                          "type": "string"
                        },
                        "country": {
                          "type": "string"
                        },
                        "postal_code": {
                          "type": "string"
                        },
                        "website": {
                          "type": "string"
                        },
                        "linkedin": {
                          "type": "string"
                        },
                        "tax_id": {
                          "type": "string"
                        },
                        "birthday": {
                          "type": "string",
                          "format": "date"
                        },
                        "custom_fields": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Campos propios de la cuenta, por slug. Se mezclan con los que ya tiene: una clave en null la borra."
                        },
                        "utm": {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string"
                            },
                            "medium": {
                              "type": "string"
                            },
                            "campaign": {
                              "type": "string"
                            }
                          },
                          "description": "Sólo al crear: el primer origen de la persona."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "index": {
                            "type": "integer"
                          },
                          "ok": {
                            "type": "boolean"
                          },
                          "created": {
                            "type": "boolean"
                          },
                          "data": {
                            "$ref": "#/components/schemas/Person"
                          },
                          "error": {
                            "$ref": "#/components/schemas/ErrorBody"
                          }
                        }
                      }
                    },
                    "created": {
                      "type": "integer"
                    },
                    "matched": {
                      "type": "integer"
                    },
                    "failed": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/persons/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la persona",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Personas"
        ],
        "summary": "Una persona",
        "operationId": "getPerson",
        "security": [
          {
            "apiKey": [
              "persons:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "patch": {
        "tags": [
          "Personas"
        ],
        "summary": "Editar una persona",
        "description": "Cambian sólo los campos que enviás. `custom_fields` se mezcla con los que tiene. `archived: true` la archiva.",
        "operationId": "updatePerson",
        "security": [
          {
            "apiKey": [
              "persons:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "phone": {
                    "type": "string",
                    "description": "Con código de país, sólo dígitos o con +: 5491155551234. Identifica a la persona."
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Identifica a la persona."
                  },
                  "external": {
                    "type": "object",
                    "properties": {
                      "source": {
                        "type": "string",
                        "maxLength": 32
                      },
                      "id": {
                        "type": "string",
                        "maxLength": 128
                      }
                    },
                    "description": "Tu propio id (ej. el de tu CRM): identifica a la persona antes que el teléfono o el email."
                  },
                  "company": {
                    "type": "string"
                  },
                  "job_title": {
                    "type": "string"
                  },
                  "address": {
                    "type": "string"
                  },
                  "city": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string"
                  },
                  "country": {
                    "type": "string"
                  },
                  "postal_code": {
                    "type": "string"
                  },
                  "website": {
                    "type": "string"
                  },
                  "linkedin": {
                    "type": "string"
                  },
                  "tax_id": {
                    "type": "string"
                  },
                  "birthday": {
                    "type": "string",
                    "format": "date"
                  },
                  "custom_fields": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Campos propios de la cuenta, por slug. Se mezclan con los que ya tiene: una clave en null la borra."
                  },
                  "utm": {
                    "type": "object",
                    "properties": {
                      "source": {
                        "type": "string"
                      },
                      "medium": {
                        "type": "string"
                      },
                      "campaign": {
                        "type": "string"
                      }
                    },
                    "description": "Sólo al crear: el primer origen de la persona."
                  },
                  "archived": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          }
        }
      }
    },
    "/persons/{id}/lead": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la persona",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Leads"
        ],
        "summary": "El análisis de la IA sobre una persona",
        "operationId": "getPersonLead",
        "security": [
          {
            "apiKey": [
              "leads:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Lead"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/conversations": {
      "get": {
        "tags": [
          "Conversaciones"
        ],
        "summary": "Listar conversaciones",
        "description": "Ordenadas por el último mensaje, la más reciente primero. Sin las conversaciones de prueba.",
        "operationId": "listConversations",
        "security": [
          {
            "apiKey": [
              "conversations:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Con mensajes desde esta fecha (ISO 8601).",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "channel",
            "in": "query",
            "required": false,
            "description": "Canal.",
            "schema": {
              "type": "string",
              "enum": [
                "whatsapp",
                "instagram",
                "facebook",
                "widget-web",
                "postman"
              ]
            }
          },
          {
            "name": "person_id",
            "in": "query",
            "required": false,
            "description": "Sólo las de esta persona.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "include_tests",
            "in": "query",
            "required": false,
            "description": "Incluir las de prueba.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Cuántos por página (1 a 100, default 50).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "El `next_cursor` de la respuesta anterior.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Conversation"
                      }
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "Hay más resultados: pedilos con `cursor`."
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Pasalo como `?cursor=` para la página siguiente."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/conversations/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la conversación",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Conversaciones"
        ],
        "summary": "Una conversación",
        "operationId": "getConversation",
        "security": [
          {
            "apiKey": [
              "conversations:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Conversation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/conversations/{id}/messages": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la conversación",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Conversaciones"
        ],
        "summary": "Mensajes de una conversación",
        "description": "Del más viejo al más nuevo, hasta 200 por página.",
        "operationId": "listMessages",
        "security": [
          {
            "apiKey": [
              "conversations:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "include_internal",
            "in": "query",
            "required": false,
            "description": "Sumar las notas internas del equipo.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Cuántos por página (1 a 200, default 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "El `next_cursor` de la respuesta anterior.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "Hay más resultados: pedilos con `cursor`."
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Pasalo como `?cursor=` para la página siguiente."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/conversations/{id}/lead": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la conversación",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Leads"
        ],
        "summary": "El análisis de la IA sobre una conversación",
        "operationId": "getConversationLead",
        "security": [
          {
            "apiKey": [
              "leads:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Lead"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/templates": {
      "get": {
        "tags": [
          "Campañas"
        ],
        "summary": "Plantillas de WhatsApp",
        "operationId": "listTemplates",
        "security": [
          {
            "apiKey": [
              "campaigns:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "APPROVED (default), PENDING, REJECTED, PAUSED, DISABLED o all.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          }
        }
      }
    },
    "/messages": {
      "post": {
        "tags": [
          "Mensajes"
        ],
        "summary": "Enviar un mensaje a una persona",
        "description": "Dos formas, según lo que envíes. **`template`**: una plantilla aprobada, en cualquier momento. **`text`**: un mensaje con el texto que quieras, sólo durante las 24 horas siguientes al último mensaje de la persona (regla de WhatsApp); fuera de ese plazo responde 409 `WINDOW_CLOSED` y hay que usar una plantilla. Sirve para avisos de a uno: una carga nueva, un turno, un pedido. Si la persona nunca escribió, crea la conversación y la persona; cuando conteste, la respuesta cae en esa conversación. No tiene tope de frecuencia: la misma persona puede recibir varios mensajes seguidos. Una plantilla de marketing no le sale a quien se dio de baja de las promociones (409 `OPTED_OUT`); una de utilidad sí. La respuesta 201 dice que WhatsApp aceptó el mensaje; la entrega y la lectura llegan después.",
        "operationId": "sendMessage",
        "security": [
          {
            "apiKey": [
              "messages:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "Texto libre. Va `text` o `template`, no los dos. Sólo con la ventana de 24 horas abierta."
                  },
                  "conversation_id": {
                    "type": "integer",
                    "description": "Sólo con `text`: la conversación a la que va, en vez de `to` o `person_id`."
                  },
                  "to": {
                    "type": "string",
                    "description": "Teléfono con código de país. Va `to` o `person_id`.",
                    "example": "5491155551234"
                  },
                  "person_id": {
                    "type": "integer",
                    "description": "Una persona de tu cuenta que tenga teléfono."
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "Nombre de la persona, si es nueva."
                  },
                  "template": {
                    "type": "object",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "language": {
                        "type": "string",
                        "example": "es_AR"
                      }
                    }
                  },
                  "variables": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Un texto por cada {{n}} de la plantilla, en orden."
                  },
                  "button_variables": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Un texto por cada botón de link con variable (`url_buttons` en GET /templates), en ese orden: el final de la URL."
                  },
                  "assistant_replies": {
                    "type": "boolean",
                    "description": "Quién atiende la respuesta: `true` el asistente, `false` queda para el equipo. Sin el campo, una conversación nueva la atiende el asistente y una que ya existía queda como estaba."
                  }
                },
                "examples": [
                  {
                    "to": "5491155551234",
                    "name": "Juan",
                    "template": {
                      "name": "carga_nueva",
                      "language": "es_AR"
                    },
                    "variables": [
                      "Juan",
                      "Posadas",
                      "Oberá"
                    ],
                    "button_variables": [
                      "8421"
                    ]
                  },
                  {
                    "to": "5491155551234",
                    "text": "Juan, la carga sale mañana a las 8 del depósito de Posadas."
                  }
                ],
                "example": {
                  "to": "5491155551234",
                  "name": "Juan",
                  "template": {
                    "name": "carga_nueva",
                    "language": "es_AR"
                  },
                  "variables": [
                    "Juan",
                    "Posadas",
                    "Oberá"
                  ],
                  "button_variables": [
                    "8421"
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "WhatsApp aceptó el mensaje",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SentMessage"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "$ref": "#/components/responses/E422"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "tags": [
          "Campañas"
        ],
        "summary": "Listar campañas",
        "operationId": "listCampaigns",
        "security": [
          {
            "apiKey": [
              "campaigns:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Campaign"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          }
        }
      },
      "post": {
        "tags": [
          "Campañas"
        ],
        "summary": "Crear una campaña",
        "description": "Una plantilla aprobada para una lista de personas. Queda como borrador salvo `launch: \"now\"` o una fecha. Si la plantilla es de marketing, al enviarla se omiten, y quedan registradas, las personas que se dieron de baja de marketing y las que ya recibieron una plantilla de marketing en los últimos días. Las de utilidad no tienen ese tope.",
        "operationId": "createCampaign",
        "security": [
          {
            "apiKey": [
              "campaigns:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "template",
                  "person_ids"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "template": {
                    "type": "object",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "language": {
                        "type": "string",
                        "example": "es_AR"
                      }
                    }
                  },
                  "variables": {
                    "type": "array",
                    "description": "Una por cada {{n}} de la plantilla, en orden: un texto fijo o un dato de la persona.",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "required": [
                            "value"
                          ],
                          "properties": {
                            "value": {
                              "type": "string"
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "field"
                          ],
                          "properties": {
                            "field": {
                              "type": "string",
                              "example": "name"
                            },
                            "fallback": {
                              "type": "string"
                            }
                          }
                        }
                      ]
                    }
                  },
                  "button_variables": {
                    "type": "array",
                    "description": "Una por cada botón de link con variable de la plantilla (`url_buttons` en GET /templates), en ese orden: el final de la URL. Para `https://tusitio.com/cargas/{{1}}`, `{ \"value\": \"8421\" }` abre https://tusitio.com/cargas/8421.",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "required": [
                            "value"
                          ],
                          "properties": {
                            "value": {
                              "type": "string"
                            }
                          }
                        },
                        {
                          "type": "object",
                          "required": [
                            "field"
                          ],
                          "properties": {
                            "field": {
                              "type": "string"
                            },
                            "fallback": {
                              "type": "string"
                            }
                          }
                        }
                      ]
                    }
                  },
                  "person_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "maxItems": 5000
                  },
                  "launch": {
                    "type": "string",
                    "description": "`draft` (default), `now`, o una fecha ISO 8601 para agendarla."
                  },
                  "pacing_per_hour": {
                    "type": "integer",
                    "minimum": 10,
                    "maximum": 1000,
                    "default": 120
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    },
                    "recipients": {
                      "type": "object",
                      "properties": {
                        "requested": {
                          "type": "integer"
                        },
                        "added": {
                          "type": "integer"
                        },
                        "not_found": {
                          "type": "array",
                          "items": {
                            "type": "integer"
                          }
                        },
                        "without_phone": {
                          "type": "array",
                          "items": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          }
        }
      }
    },
    "/campaigns/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la campaña",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Campañas"
        ],
        "summary": "Una campaña",
        "operationId": "getCampaign",
        "security": [
          {
            "apiKey": [
              "campaigns:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/campaigns/{id}/launch": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id de la campaña",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "post": {
        "tags": [
          "Campañas"
        ],
        "summary": "Lanzar o agendar una campaña",
        "description": "Sin cuerpo la envía ya; con `{ \"at\": fecha }` la agenda. Si la cuenta de WhatsApp tiene un bloqueo de Meta (medio de pago, nombre visible) devuelve 409 con qué resolver.",
        "operationId": "launchCampaign",
        "security": [
          {
            "apiKey": [
              "campaigns:write"
            ]
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Listar webhooks",
        "operationId": "listWebhooks",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          }
        }
      },
      "post": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Crear un webhook",
        "description": "Devuelve el `secret` para verificar la firma. Se muestra sólo esta vez.",
        "operationId": "createWebhook",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "events"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "https, en un servidor público."
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "message.received",
                        "message.sent",
                        "lead.updated",
                        "conversation.handoff",
                        "person.created"
                      ]
                    }
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "url": {
                          "type": "string"
                        },
                        "events": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "secret": {
                          "type": "string",
                          "example": "whsec_…"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id del webhook",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Un webhook",
        "operationId": "getWebhook",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "patch": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Editar un webhook",
        "description": "`active: true` lo vuelve a prender si se apagó por fallas.",
        "operationId": "updateWebhook",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "description": {
                    "type": "string"
                  },
                  "active": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "delete": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Borrar un webhook",
        "operationId": "deleteWebhook",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Id del webhook",
          "schema": {
            "type": "integer"
          }
        }
      ],
      "post": {
        "tags": [
          "Administrar webhooks"
        ],
        "summary": "Enviar un evento de prueba",
        "description": "Un evento `ping`, en menos de un minuto.",
        "operationId": "testWebhook",
        "security": [
          {
            "apiKey": [
              "webhooks:manage"
            ]
          }
        ],
        "responses": {
          "202": {
            "description": "Encolado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/tools": {
      "get": {
        "tags": [
          "Tools"
        ],
        "summary": "Listar las tools de la cuenta",
        "operationId": "listTools",
        "security": [
          {
            "apiKey": [
              "tools:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ToolSummary"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      },
      "post": {
        "tags": [
          "Tools"
        ],
        "summary": "Crear una tool o actualizar su borrador",
        "description": "Recibe el manifiesto completo y reemplaza al borrador anterior. No cambia lo que usa el asistente: eso pasa al publicar. Sin `slug`, una tool de la cuenta con el mismo `name` se actualiza en vez de duplicarse. Un manifiesto con errores devuelve `422` y no se guarda.",
        "operationId": "saveTool",
        "security": [
          {
            "apiKey": [
              "tools:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/ToolManifest"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "slug": {
                        "type": "string",
                        "description": "El slug de una tool existente, para actualizarla."
                      }
                    }
                  }
                ]
              },
              "example": {
                "name": "Consultar stock",
                "description": "Consulta el stock de un producto en el sistema del negocio.",
                "definition": {
                  "name": "consultar_stock",
                  "description": "Consulta cuántas unidades hay de un producto y su precio. Usala cuando la persona pregunta si hay un producto, cuánto sale o si se puede retirar hoy. Devuelve nombre, unidades y precio, o encontrado en false si el código no existe.",
                  "kind": "read",
                  "parameters": [
                    {
                      "name": "codigo",
                      "type": "string",
                      "description": "Código del producto tal como lo dijo la persona o figura en el catálogo.",
                      "required": true
                    }
                  ],
                  "steps": [
                    {
                      "id": "buscar",
                      "name": "Buscar el producto",
                      "type": "api_call",
                      "apiCall": {
                        "url": "{{install_vars.base_url}}/productos/{{input.codigo}}",
                        "method": "GET",
                        "headers": {
                          "Authorization": "Bearer {{install_vars.api_key}}"
                        }
                      }
                    },
                    {
                      "id": "resumir",
                      "name": "Dejar lo que el asistente necesita",
                      "type": "transform",
                      "transform": {
                        "expression": "ctx.steps.buscar.output.data.producto ? { encontrado: true, nombre: ctx.steps.buscar.output.data.producto.nombre, unidades: ctx.steps.buscar.output.data.producto.stock, precio: ctx.steps.buscar.output.data.producto.precio } : { encontrado: false, motivo: 'No hay un producto con ese código.' }"
                      }
                    }
                  ]
                },
                "requires": {
                  "variables": [
                    {
                      "name": "base_url",
                      "type": "string",
                      "label": "URL de la API",
                      "description": "Sin barra al final.",
                      "required": true
                    },
                    {
                      "name": "api_key",
                      "type": "string",
                      "label": "Clave de la API",
                      "required": true,
                      "secret": true
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Actualizada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tool"
                    },
                    "created": {
                      "type": "boolean"
                    },
                    "validation": {
                      "$ref": "#/components/schemas/ToolValidation"
                    },
                    "next": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Creada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tool"
                    },
                    "created": {
                      "type": "boolean"
                    },
                    "validation": {
                      "$ref": "#/components/schemas/ToolValidation"
                    },
                    "next": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "422": {
            "description": "El manifiesto tiene errores. `validation.errors` dice dónde está cada uno y cómo se corrige.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "const": "INVALID_MANIFEST"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "validation": {
                      "$ref": "#/components/schemas/ToolValidation"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/tools/validate": {
      "post": {
        "tags": [
          "Tools"
        ],
        "summary": "Revisar un manifiesto sin guardarlo",
        "operationId": "validateTool",
        "security": [
          {
            "apiKey": [
              "tools:read"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ToolManifest"
              },
              "example": {
                "name": "Consultar stock",
                "description": "Consulta el stock de un producto en el sistema del negocio.",
                "definition": {
                  "name": "consultar_stock",
                  "description": "Consulta cuántas unidades hay de un producto y su precio. Usala cuando la persona pregunta si hay un producto, cuánto sale o si se puede retirar hoy. Devuelve nombre, unidades y precio, o encontrado en false si el código no existe.",
                  "kind": "read",
                  "parameters": [
                    {
                      "name": "codigo",
                      "type": "string",
                      "description": "Código del producto tal como lo dijo la persona o figura en el catálogo.",
                      "required": true
                    }
                  ],
                  "steps": [
                    {
                      "id": "buscar",
                      "name": "Buscar el producto",
                      "type": "api_call",
                      "apiCall": {
                        "url": "{{install_vars.base_url}}/productos/{{input.codigo}}",
                        "method": "GET",
                        "headers": {
                          "Authorization": "Bearer {{install_vars.api_key}}"
                        }
                      }
                    },
                    {
                      "id": "resumir",
                      "name": "Dejar lo que el asistente necesita",
                      "type": "transform",
                      "transform": {
                        "expression": "ctx.steps.buscar.output.data.producto ? { encontrado: true, nombre: ctx.steps.buscar.output.data.producto.nombre, unidades: ctx.steps.buscar.output.data.producto.stock, precio: ctx.steps.buscar.output.data.producto.precio } : { encontrado: false, motivo: 'No hay un producto con ese código.' }"
                      }
                    }
                  ]
                },
                "requires": {
                  "variables": [
                    {
                      "name": "base_url",
                      "type": "string",
                      "label": "URL de la API",
                      "description": "Sin barra al final.",
                      "required": true
                    },
                    {
                      "name": "api_key",
                      "type": "string",
                      "label": "Clave de la API",
                      "required": true,
                      "secret": true
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ToolValidation"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/tools/{slug}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "description": "El slug de la tool. Lleva una barra, que en la URL va como `%2F`: `mi-empresa%2Fconsultar-stock`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Tools"
        ],
        "summary": "Una tool con su manifiesto y su estado",
        "operationId": "getTool",
        "security": [
          {
            "apiKey": [
              "tools:read"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tool"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/tools/{slug}/test": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "description": "El slug de la tool. Lleva una barra, que en la URL va como `%2F`: `mi-empresa%2Fconsultar-stock`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "tags": [
          "Tools"
        ],
        "summary": "Probar el borrador",
        "description": "Corre los pasos con los parámetros que pases. **Los pedidos HTTP salen de verdad**: una tool que crea algo lo crea. Si termina bien, queda asentado que esa versión exacta pasó la prueba, y se puede publicar. Los valores de las variables secretas no aparecen en la respuesta.",
        "operationId": "testTool",
        "security": [
          {
            "apiKey": [
              "tools:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "params": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "El valor de cada parámetro, como los completaría el asistente."
                  },
                  "install_variables": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    },
                    "description": "Valores de las variables de instalación para esta prueba. Las que ya están cargadas en la cuenta no hace falta pasarlas."
                  }
                },
                "example": {
                  "params": {
                    "codigo": "A-1042"
                  },
                  "install_variables": {
                    "base_url": "https://api.tunegocio.com",
                    "api_key": "..."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ToolTestResult"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "422": {
            "description": "El manifiesto tiene errores. `validation.errors` dice dónde está cada uno y cómo se corrige.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "const": "INVALID_MANIFEST"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "validation": {
                      "$ref": "#/components/schemas/ToolValidation"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/tools/{slug}/publish": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "description": "El slug de la tool. Lleva una barra, que en la URL va como `%2F`: `mi-empresa%2Fconsultar-stock`.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "tags": [
          "Tools"
        ],
        "summary": "Publicar el borrador en la cuenta",
        "description": "Desde acá lo usa el asistente. Pide una prueba que haya pasado sobre ese mismo borrador: si no, responde `409 TEST_REQUIRED`. Queda publicada para tu cuenta; ofrecerla a otras cuentas se pide desde la webapp.",
        "operationId": "publishTool",
        "security": [
          {
            "apiKey": [
              "tools:write"
            ]
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "string",
                    "description": "Por ejemplo 1.0.1. Sin esto se usa la siguiente."
                  },
                  "changelog": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tool"
                    },
                    "published": {
                      "type": "boolean"
                    },
                    "version": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "409": {
            "$ref": "#/components/responses/E409"
          },
          "422": {
            "description": "El manifiesto tiene errores. `validation.errors` dice dónde está cada uno y cómo se corrige.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "const": "INVALID_MANIFEST"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    },
                    "validation": {
                      "$ref": "#/components/schemas/ToolValidation"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    }
  },
  "webhooks": {
    "message.received": {
      "post": {
        "summary": "message.received",
        "description": "Una persona escribió en una conversación.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Id del evento. Igual en todos tus endpoints y en los reintentos: usalo para no procesarlo dos veces.",
                    "example": "evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1"
                  },
                  "type": {
                    "type": "string",
                    "const": "message.received"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "message": {
                        "$ref": "#/components/schemas/Message"
                      },
                      "conversation": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "channel": {
                            "type": "string"
                          }
                        }
                      },
                      "synced_from_crm": {
                        "type": "boolean"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cualquier 2xx confirma la entrega. Otra respuesta, o más de 10 s, se reintenta."
          }
        }
      }
    },
    "message.sent": {
      "post": {
        "summary": "message.sent",
        "description": "El asistente o alguien del equipo respondió.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Id del evento. Igual en todos tus endpoints y en los reintentos: usalo para no procesarlo dos veces.",
                    "example": "evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1"
                  },
                  "type": {
                    "type": "string",
                    "const": "message.sent"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "message": {
                        "$ref": "#/components/schemas/Message"
                      },
                      "conversation": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "channel": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cualquier 2xx confirma la entrega. Otra respuesta, o más de 10 s, se reintenta."
          }
        }
      }
    },
    "lead.updated": {
      "post": {
        "summary": "lead.updated",
        "description": "La IA actualizó el análisis de una conversación: intención, score, resumen, tareas.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Id del evento. Igual en todos tus endpoints y en los reintentos: usalo para no procesarlo dos veces.",
                    "example": "evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1"
                  },
                  "type": {
                    "type": "string",
                    "const": "lead.updated"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "lead": {
                        "$ref": "#/components/schemas/Lead"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cualquier 2xx confirma la entrega. Otra respuesta, o más de 10 s, se reintenta."
          }
        }
      }
    },
    "conversation.handoff": {
      "post": {
        "summary": "conversation.handoff",
        "description": "El asistente pasó la conversación a una persona del equipo.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Id del evento. Igual en todos tus endpoints y en los reintentos: usalo para no procesarlo dos veces.",
                    "example": "evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1"
                  },
                  "type": {
                    "type": "string",
                    "const": "conversation.handoff"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "conversation": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "channel": {
                            "type": "string"
                          }
                        }
                      },
                      "reason": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "person": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "phone": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cualquier 2xx confirma la entrega. Otra respuesta, o más de 10 s, se reintenta."
          }
        }
      }
    },
    "person.created": {
      "post": {
        "summary": "person.created",
        "description": "Se creó un contacto (por una conversación, a mano o por API).",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Id del evento. Igual en todos tus endpoints y en los reintentos: usalo para no procesarlo dos veces.",
                    "example": "evt_3f1c0a9e2b7d4c51a8e6f0b2c4d6e8f1"
                  },
                  "type": {
                    "type": "string",
                    "const": "person.created"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "person": {
                        "$ref": "#/components/schemas/Person"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cualquier 2xx confirma la entrega. Otra respuesta, o más de 10 s, se reintenta."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "abk_live_…",
        "description": "Una API key de tu cuenta: Configuración → API y webhooks. Cada key tiene permisos: `persons:read` (leer personas), `persons:write` (crear y editar personas), `conversations:read` (leer conversaciones), `conversations:write` (operar conversaciones), `leads:read` (leer el análisis de la ia), `campaigns:read` (leer campañas), `campaigns:write` (crear y lanzar campañas), `messages:write` (enviar mensajes), `webhooks:manage` (administrar webhooks), `agents:read` (leer agentes), `agents:write` (editar agentes), `tools:read` (leer tools), `tools:write` (crear y publicar tools), `channels:read` (leer canales), `channels:manage` (administrar canales), `kb:read` (leer base de conocimiento), `kb:write` (editar base de conocimiento), `automations:read` (leer automatizaciones), `automations:write` (editar automatizaciones), `automations:approve` (aprobar acciones de automatizaciones), `team:read` (leer equipo), `team:manage` (administrar equipo), `metrics:read` (leer métricas)."
      }
    },
    "responses": {
      "E400": {
        "description": "El pedido tiene un dato inválido (`field` dice cuál).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E401": {
        "description": "Falta la API key, o es inválida, está revocada o vencida.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E403": {
        "description": "La key no tiene el permiso que hace falta, o la cuenta está suspendida.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E404": {
        "description": "No existe en tu cuenta.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E422": {
        "description": "WhatsApp no aceptó el mensaje. `message` trae el motivo que devolvió Meta.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E409": {
        "description": "Choca con el estado actual (ej. la cuenta de WhatsApp no puede enviar).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E429": {
        "description": "Rate limit: 120/min por key (`RATE_LIMITED`) o 600/min por cuenta (`RATE_LIMITED_ORG`, sumando todas las keys). `Retry-After` dice cuántos segundos esperar.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "ToolManifest": {
        "type": "object",
        "required": [
          "name",
          "definition"
        ],
        "description": "Una tool, entera. El detalle de cada tipo de paso y de cómo se leen los datos está en la guía: /developers/tools.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 80,
            "description": "El nombre que ve la gente en la cuenta."
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "description": "Texto corto para el listado."
          },
          "definition": {
            "type": "object",
            "required": [
              "name",
              "description",
              "kind",
              "steps"
            ],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]*$",
                "maxLength": 64,
                "description": "Cómo la llama el asistente."
              },
              "description": {
                "type": "string",
                "maxLength": 1024,
                "description": "Lo que el asistente lee para decidir cuándo usarla."
              },
              "kind": {
                "type": "string",
                "enum": [
                  "read",
                  "write"
                ]
              },
              "parameters": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "name",
                    "type",
                    "description"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "string",
                        "number",
                        "boolean"
                      ]
                    },
                    "description": {
                      "type": "string"
                    },
                    "required": {
                      "type": "boolean"
                    },
                    "enum": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              },
              "steps": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "type"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "api_call",
                        "template",
                        "build_object",
                        "transform",
                        "conditional",
                        "foreach",
                        "storage"
                      ]
                    },
                    "continueOnError": {
                      "type": "boolean"
                    }
                  },
                  "additionalProperties": true
                }
              },
              "outputTemplate": {
                "type": "string"
              }
            }
          },
          "requires": {
            "type": "object",
            "properties": {
              "variables": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "name",
                    "type",
                    "label"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "string",
                        "textarea",
                        "select"
                      ]
                    },
                    "label": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "required": {
                      "type": "boolean"
                    },
                    "secret": {
                      "type": "boolean"
                    },
                    "default": {
                      "type": "string"
                    },
                    "options": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ToolValidation": {
        "type": "object",
        "required": [
          "valid",
          "errors",
          "warnings"
        ],
        "properties": {
          "valid": {
            "type": "boolean"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code",
                "path",
                "message"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "path": {
                  "type": "string",
                  "description": "Dónde está, dentro del manifiesto."
                },
                "message": {
                  "type": "string",
                  "description": "Qué pasa y cómo se corrige."
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "code",
                "path",
                "message"
              ],
              "properties": {
                "code": {
                  "type": "string"
                },
                "path": {
                  "type": "string",
                  "description": "Dónde está, dentro del manifiesto."
                },
                "message": {
                  "type": "string",
                  "description": "Qué pasa y cómo se corrige."
                }
              }
            }
          }
        }
      },
      "ToolSummary": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "published_version": {
            "type": [
              "string",
              "null"
            ]
          },
          "updated_at": {
            "type": "string"
          }
        }
      },
      "Tool": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "function_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "published_version": {
            "type": [
              "string",
              "null"
            ]
          },
          "has_unpublished_changes": {
            "type": "boolean",
            "description": "Hay un borrador que el asistente todavía no usa."
          },
          "tested": {
            "type": "boolean",
            "description": "La versión actual pasó una prueba."
          },
          "installed": {
            "type": "boolean",
            "description": "Está en uso en la cuenta."
          },
          "variables_pending": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Variables obligatorias que falta cargar en la cuenta."
          },
          "shared": {
            "type": "string",
            "enum": [
              "private",
              "in_review",
              "public"
            ]
          },
          "updated_at": {
            "type": "string"
          },
          "manifest": {
            "$ref": "#/components/schemas/ToolManifest"
          },
          "validation": {
            "$ref": "#/components/schemas/ToolValidation"
          }
        }
      },
      "ToolTestResult": {
        "type": "object",
        "properties": {
          "passed": {
            "type": "boolean"
          },
          "output": {
            "description": "Lo que va a leer el asistente."
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_ms": {
            "type": "integer"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "error",
                    "skipped"
                  ]
                },
                "duration_ms": {
                  "type": "integer"
                },
                "error": {
                  "type": "string"
                },
                "output": {}
              }
            }
          },
          "can_publish": {
            "type": "boolean"
          },
          "note": {
            "type": "string"
          }
        }
      },
      "ErrorBody": {
        "type": "object",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "example": "INVALID_INPUT"
          },
          "message": {
            "type": "string"
          },
          "field": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error",
          "request_id"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorBody"
          },
          "request_id": {
            "type": "string",
            "description": "Envianos este id si nos escribís por un error."
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "object": {
            "const": "account"
          },
          "id": {
            "type": "integer"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "key": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "scopes": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Person": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "object": {
            "const": "person"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "description": "Sólo dígitos, con código de país."
          },
          "company": {
            "type": [
              "string",
              "null"
            ]
          },
          "job_title": {
            "type": [
              "string",
              "null"
            ]
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "state": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "postal_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "website": {
            "type": [
              "string",
              "null"
            ]
          },
          "linkedin": {
            "type": [
              "string",
              "null"
            ]
          },
          "tax_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "birthday": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "preferred_channel": {
            "type": [
              "string",
              "null"
            ]
          },
          "pipeline_stage_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "lead": {
            "type": "object",
            "properties": {
              "score": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "0 a 100."
              },
              "intent": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "urgency": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "sentiment": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "custom_fields": {
            "type": "object",
            "additionalProperties": true
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "source": {
                  "type": "string"
                },
                "campaign": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "at": {
                  "type": "string"
                }
              }
            }
          },
          "utm": {
            "type": "object",
            "properties": {
              "source": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "medium": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "campaign": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "external": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "source": {
                "type": "string"
              },
              "id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "archived": {
            "type": "boolean"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Conversation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "object": {
            "const": "conversation"
          },
          "channel": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "whatsapp",
              "instagram",
              "facebook",
              "widget-web",
              "postman",
              null
            ]
          },
          "person_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "customer": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "is_test": {
            "type": "boolean"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_message_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_message": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "text": {
                "type": "string"
              },
              "sender": {
                "type": "string"
              }
            }
          },
          "messages_count": {
            "type": "integer"
          },
          "ai_messages_count": {
            "type": "integer"
          },
          "ai_paused": {
            "type": "boolean",
            "description": "La IA está en pausa en esta conversación (la atiende una persona)."
          },
          "assigned_to_user_id": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "object": {
            "const": "message"
          },
          "conversation_id": {
            "type": "integer"
          },
          "sender": {
            "type": "string",
            "enum": [
              "person",
              "assistant",
              "operator",
              "automation",
              "system"
            ],
            "description": "Quién lo escribió: la persona, el asistente de IA, alguien del equipo, una automatización o el sistema."
          },
          "author_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "text": {
            "type": "string"
          },
          "transcription": {
            "type": [
              "string",
              "null"
            ],
            "description": "Si era un audio, lo que decía."
          },
          "media_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "internal": {
            "type": "boolean",
            "description": "Nota interna del equipo: la persona no la vio."
          },
          "delivery_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "sent",
              "delivered",
              "read",
              "failed",
              null
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Lead": {
        "type": "object",
        "properties": {
          "object": {
            "const": "lead"
          },
          "conversation_id": {
            "type": "integer"
          },
          "person_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "score": {
            "type": [
              "integer",
              "null"
            ],
            "description": "0 a 100: qué tan cerca está de comprar o contratar."
          },
          "intent": {
            "type": [
              "string",
              "null"
            ]
          },
          "urgency": {
            "type": [
              "string",
              "null"
            ]
          },
          "sentiment": {
            "type": [
              "string",
              "null"
            ]
          },
          "summary": {
            "type": [
              "string",
              "null"
            ],
            "description": "Resumen de la conversación para el equipo."
          },
          "next_steps": {
            "type": [
              "string",
              "null"
            ]
          },
          "signals": {
            "type": "array",
            "items": {}
          },
          "suggested_actions": {
            "type": "array",
            "items": {},
            "description": "Tareas que la IA le sugiere al equipo."
          },
          "recommendation": {},
          "classification": {
            "description": "El análisis completo, tal como lo guarda la IA."
          },
          "pipeline_stage_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "analyzed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "object": {
            "const": "template"
          },
          "name": {
            "type": "string"
          },
          "language": {
            "type": "string"
          },
          "category": {
            "type": "string",
            "enum": [
              "MARKETING",
              "UTILITY",
              "AUTHENTICATION"
            ]
          },
          "status": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "variables": {
            "type": "integer",
            "description": "Cuántas {{n}} tiene el cuerpo."
          },
          "url_buttons": {
            "type": "array",
            "description": "Los botones de link con variable al final de la URL. Su valor va en `button_variables` de la campaña, en este orden.",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer",
                  "description": "Posición del botón en la plantilla."
                },
                "text": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "example": "https://tusitio.com/cargas/{{1}}"
                }
              }
            }
          },
          "quality": {
            "type": [
              "string",
              "null"
            ]
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "SentMessage": {
        "type": "object",
        "properties": {
          "object": {
            "const": "message"
          },
          "status": {
            "const": "sent"
          },
          "id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Con `text`: el id del mensaje en la conversación."
          },
          "to": {
            "type": "string"
          },
          "conversation_id": {
            "type": "integer",
            "description": "La conversación donde quedó el mensaje y donde va a caer la respuesta."
          },
          "conversation_created": {
            "type": "boolean"
          },
          "person_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "template": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "language": {
                "type": "string"
              },
              "category": {
                "type": "string"
              }
            }
          },
          "text": {
            "type": "string",
            "description": "El mensaje como le llegó a la persona, con las variables puestas."
          },
          "wa_message_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "El id del mensaje en WhatsApp."
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "object": {
            "const": "campaign"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "scheduled",
              "running",
              "paused",
              "done",
              "cancelled"
            ]
          },
          "template": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "language": {
                "type": "string"
              },
              "category": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "audience_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "schedule_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "pacing_per_hour": {
            "type": "integer"
          },
          "counts": {
            "type": "object",
            "properties": {
              "recipients": {
                "type": "integer"
              },
              "sent": {
                "type": "integer"
              },
              "delivered": {
                "type": "integer"
              },
              "read": {
                "type": "integer"
              },
              "replied": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              },
              "skipped": {
                "type": "integer"
              }
            }
          },
          "estimated_cost_usd": {
            "type": [
              "number",
              "null"
            ]
          },
          "paused_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "url": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "active": {
            "type": "boolean"
          },
          "failure_streak": {
            "type": "integer",
            "description": "Entregas seguidas que fallaron. Con 50, el webhook se apaga solo."
          },
          "disabled_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string"
          }
        }
      }
    }
  }
}