{
  "name": "Logixb2b — Webhook → Notificación tiempo real",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Webhook lead-alert → Config → IF email válido → Slack al equipo + autorespuesta HTTP opcional."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "webhook"
    },
    {
      "name": "alertas"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Webhook → Notificación tiempo real\n\n**Recurso:** `/recursos/webhook-notificacion-tiempo-real`\n**Guía:** /webhooks-n8n-guia-practica-integraciones-b2b\n**Zona:** Europe/Madrid · `active: false` al importar (tú lo activas).\n\n### 1) Importar\n1. n8n → ⋯ → **Import from File** → este JSON.\n2. El flujo llega **inactive**. No pegues secretos en el lienzo ni en el archivo.\n\n### 2) Credenciales y configuración por nodo\n- **Webhook Lead** (`webhook`): sin credencial. Tras Active, copia **URL de producción** (HTTPS del VPS/Cloud). El emisor (formulario, CRM, bot) debe POST a esa URL.\n- **Config alerta** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **Normalizar lead** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **¿Email válido?** (`IF`): sin credencial. Comprueba la condición (email, umbral, over_limit, etc.) con datos reales de prueba.\n- **Notificar equipo Slack** (`HTTP Request` → Slack/Teams): crea Incoming Webhook en Slack (o Adaptive Card URL en Teams). Pega la URL en **Config** o en este nodo. Auth: none (la URL ya es secreta).\n- **¿Autorespuesta ON?** (`IF`): sin credencial. Comprueba la condición (email, umbral, over_limit, etc.) con datos reales de prueba.\n- **Autorespuesta lead (HTTP)** (`HTTP Request` CRM): Credentials → **Header Auth** / OAuth del CRM. Sustituye `crm*Url` en el nodo **Config**. Prueba con un Lead de sandbox.\n\n### 3) Orden recomendado de puesta en marcha\n1. Rellena el nodo **Config** (URLs reales, umbrales, webhooks de Slack).\n2. Crea Credentials en n8n (candado de cada nodo HTTP / Sheets / OpenAI) y **enlázalas**.\n3. Ejecuta **una vez** (Manual / Test URL del Webhook / \"Execute workflow\").\n4. Verifica CRM + Slack/Sheets (y que la IA no escriba en producción sin HITL).\n5. Solo entonces: interruptor **Active**.\n\n### 4) Producción 24/7 en VPS (UE)\nImportar en localhost no basta: webhooks y cron necesitan n8n encendido.\n\n1. VPS en UE (Hetzner/OVH/IONOS…) + Docker Compose + **Postgres** + HTTPS (Caddy/Nginx).\n2. Variables mínimas: `GENERIC_TIMEZONE=Europe/Madrid`, `WEBHOOK_URL=https://n8n.tudominio.com/`, `N8N_ENCRYPTION_KEY`, `N8N_HOST` / `N8N_PROTOCOL=https`.\n3. Firewall: solo 80/443 (+ SSH). Backups del volumen Postgres + export de workflows.\n4. Importa este JSON en la instancia de producción, vuelve a crear Credentials (no se copian solas), actualiza URLs del Config al dominio real.\n5. Pon **Active**. Prueba el Webhook de producción o espera el próximo cron.\n6. Alternativa: **n8n Cloud** (mismo JSON; Credentials en la UI Cloud).\n\n### 5) RGPD + EU AI Act (resumen)\nSi hay nodos IA sois **deployers** (Reglamento UE 2024/1689). Art. 4 alfabetización. **HITL** antes de outreach, scores masivos o pausas de cuenta. Minimiza PII en Slack/logs. Informativo — no es asesoramiento legal. /uso-responsable-de-ia-y-transparencia\n",
        "height": 1500,
        "width": 580,
        "color": 4
      }
    },
    {
      "id": "wh-trigger",
      "name": "Webhook Lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        560
      ],
      "webhookId": "lead-alert",
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-alert",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "wh-config",
      "name": "Config alerta",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        560
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "wh-c1",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "wh-c2",
              "name": "enableAutoresponse",
              "value": false,
              "type": "boolean"
            },
            {
              "id": "wh-c3",
              "name": "autoresponseUrl",
              "value": "https://api.resend.com/emails",
              "type": "string"
            },
            {
              "id": "wh-c4",
              "name": "autoresponseApiKey",
              "value": "sustituye-con-tu-clave-de-correo",
              "type": "string"
            },
            {
              "id": "wh-c5",
              "name": "fromEmail",
              "value": "hola@TU-DOMINIO.ejemplo",
              "type": "string"
            },
            {
              "id": "wh-c6",
              "name": "replySubject",
              "value": "Hemos recibido tu mensaje",
              "type": "string"
            },
            {
              "id": "wh-c7",
              "name": "receivedAt",
              "value": "={{ $now.setZone('Europe/Madrid').toFormat('yyyy-MM-dd HH:mm') }}",
              "type": "string"
            },
            {
              "id": "wh-c8",
              "name": "rawBody",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            }
          ]
        }
      }
    },
    {
      "id": "wh-normalize",
      "name": "Normalizar lead",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        600,
        560
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "wh-n1",
              "name": "email",
              "value": "={{ String($json.rawBody.email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "wh-n2",
              "name": "name",
              "value": "={{ String($json.rawBody.name || $json.rawBody.nombre || '').trim() }}",
              "type": "string"
            },
            {
              "id": "wh-n3",
              "name": "company",
              "value": "={{ String($json.rawBody.company || $json.rawBody.empresa || '').trim() }}",
              "type": "string"
            },
            {
              "id": "wh-n4",
              "name": "slackWebhookUrl",
              "value": "={{ $json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "wh-n5",
              "name": "enableAutoresponse",
              "value": "={{ $json.enableAutoresponse }}",
              "type": "boolean"
            },
            {
              "id": "wh-n6",
              "name": "autoresponseUrl",
              "value": "={{ $json.autoresponseUrl }}",
              "type": "string"
            },
            {
              "id": "wh-n7",
              "name": "autoresponseApiKey",
              "value": "={{ $json.autoresponseApiKey }}",
              "type": "string"
            },
            {
              "id": "wh-n8",
              "name": "fromEmail",
              "value": "={{ $json.fromEmail }}",
              "type": "string"
            },
            {
              "id": "wh-n9",
              "name": "replySubject",
              "value": "={{ $json.replySubject }}",
              "type": "string"
            },
            {
              "id": "wh-n10",
              "name": "receivedAt",
              "value": "={{ $json.receivedAt }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "wh-if-email",
      "name": "¿Email válido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        560
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "wh-cond-email",
              "leftValue": "={{ $json.email }}",
              "rightValue": "@",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "wh-slack",
      "name": "Notificar equipo Slack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.slackWebhookUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.slackText || 'Actualización Logixb2b' }) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "wh-if-auto",
      "name": "¿Autorespuesta ON?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "wh-cond-auto",
              "leftValue": "={{ $('Normalizar lead').item.json.enableAutoresponse }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "wh-autoresponse",
      "name": "Autorespuesta lead (HTTP)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1800,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $('Normalizar lead').item.json.autoresponseUrl }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Normalizar lead').item.json.autoresponseApiKey }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ from: $('Normalizar lead').item.json.fromEmail, to: [$('Normalizar lead').item.json.email], subject: $('Normalizar lead').item.json.replySubject, text: 'Hola ' + ($('Normalizar lead').item.json.name || '') + ',\\n\\nHemos recibido tu mensaje y te contactaremos pronto.\\n\\n— Equipo comercial' }) }}",
        "options": {
          "timeout": 15000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      }
    },
    {
      "id": "wh-skip-auto",
      "name": "Sin autorespuesta",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1800,
        560
      ],
      "parameters": {}
    },
    {
      "id": "wh-invalid",
      "name": "Email inválido — sin alerta",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1200,
        820
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook Lead": {
      "main": [
        [
          {
            "node": "Config alerta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config alerta": {
      "main": [
        [
          {
            "node": "Normalizar lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar lead": {
      "main": [
        [
          {
            "node": "¿Email válido?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Email válido?": {
      "main": [
        [
          {
            "node": "Notificar equipo Slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email inválido — sin alerta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notificar equipo Slack": {
      "main": [
        [
          {
            "node": "¿Autorespuesta ON?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Autorespuesta ON?": {
      "main": [
        [
          {
            "node": "Autorespuesta lead (HTTP)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sin autorespuesta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
