{
  "name": "WAIA Connect — Responder a un entrante (hola mundo)",
  "nodes": [
    {
      "parameters": {
        "content": "## Responder automáticamente a un entrante\n\nEl \"hola mundo\": llega un `message.received` y respondés con un texto.\n\n1. **Webhook (POST)** → *Authentication: Header Auth* (credencial con Name=`X-Connect-Token`, Value=tu `wct_…`).\n2. En **Config** poné tu `apiBase` y tu API key (`wc_live_…`).\n3. El **IF** deja pasar solo `message.received` (ignora acuses, echoes, etc.).\n4. El nodo HTTP responde por `POST /v1/messages` al mismo número.\n\n⚠ Webhook en **POST** (n8n lo crea en GET por defecto).\n⚠ Respondé 2xx rápido; el trabajo pesado va después. Connect reintenta si tu endpoint falla.",
        "height": 320,
        "width": 440
      },
      "id": "ar-sticky",
      "name": "Responder a un entrante — leeme",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-560, 120]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "waia-connect-auto-reply",
        "authentication": "headerAuth",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "ar-webhook",
      "name": "Webhook (POST)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [-60, 300],
      "webhookId": "waia-connect-auto-reply",
      "notes": "POST + Header Auth. El sobre entero llega en $json.body."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "a-base", "name": "apiBase", "type": "string", "value": "https://api.waiaconnect.com" },
            { "id": "a-key", "name": "apiKey", "type": "string", "value": "wc_live_YOUR_API_KEY" },
            { "id": "a-reply", "name": "replyText", "type": "string", "value": "¡Gracias por escribir! Ya te respondemos." }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "ar-config",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [220, 300],
      "notes": "Placeholders. Guardá la API key en una credencial si compartís el workflow."
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "typeValidation": "strict" },
          "conditions": [
            { "id": "c-recv", "leftValue": "={{ $json.body.type }}", "rightValue": "message.received", "operator": { "type": "string", "operation": "equals" } }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "ar-if",
      "name": "¿Es message.received?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [500, 300],
      "notes": "Solo entrantes de un cliente. Ignora acuses / echoes / eventos de conexión."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Config').item.json.apiBase }}/v1/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "=Bearer {{ $('Config').item.json.apiKey }}" },
            { "name": "Content-Type", "value": "application/json" },
            { "name": "Idempotency-Key", "value": "={{ $json.body.id }}" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ connectionId: $json.body.connection.id, to: $json.body.data.message.from, type: 'text', text: { body: $('Config').item.json.replyText } }) }}",
        "options": {}
      },
      "id": "ar-reply",
      "name": "Responder (POST /v1/messages)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [780, 240],
      "notes": "Usa el id del evento como Idempotency-Key → un reintento del webhook no duplica la respuesta."
    }
  ],
  "connections": {
    "Webhook (POST)": { "main": [ [ { "node": "Config", "type": "main", "index": 0 } ] ] },
    "Config": { "main": [ [ { "node": "¿Es message.received?", "type": "main", "index": 0 } ] ] },
    "¿Es message.received?": { "main": [ [ { "node": "Responder (POST /v1/messages)", "type": "main", "index": 0 } ], [] ] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": { "templateCredsSetupCompleted": false }
}
