{
  "name": "Logixb2b — Formulario web → CRM (n8n)",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Webhook lead-form → Config → IF email válido → alta CRM (neverError) → Slack al equipo."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "crm"
    },
    {
      "name": "formulario"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Formulario web → CRM (n8n)\n\n**Recurso:** `/recursos/formulario-crm-n8n`\n**Guía:** /automatizar-envio-leads-formulario-crm-n8n\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 Formulario** (`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 formulario** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **Normalizar campos** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **¿Email contiene @?** (`IF`): sin credencial. Comprueba la condición (email, umbral, over_limit, etc.) con datos reales de prueba.\n- **Crear/actualizar CRM (HTTP)** (`HTTP Request` CRM): Credentials → **Header Auth** / OAuth del CRM. Sustituye `crm*Url` en el nodo **Config**. Prueba con un Lead de sandbox.\n- **Unir CRM + lead** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Aviso Slack equipo** (`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\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": "form-webhook",
      "name": "Webhook Formulario",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "lead-form",
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-form",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "form-config",
      "name": "Config formulario",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "form-c1",
              "name": "crmContactsUrl",
              "value": "https://TU-CRM.ejemplo/api/contacts",
              "type": "string"
            },
            {
              "id": "form-c2",
              "name": "crmApiKey",
              "value": "sustituye-con-tu-clave-del-crm",
              "type": "string"
            },
            {
              "id": "form-c3",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "form-c4",
              "name": "receivedAt",
              "value": "={{ $now.setZone('Europe/Madrid').toFormat('yyyy-MM-dd HH:mm') }}",
              "type": "string"
            },
            {
              "id": "form-c5",
              "name": "rawBody",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            }
          ]
        }
      }
    },
    {
      "id": "form-normalize",
      "name": "Normalizar campos",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        600,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "form-n1",
              "name": "email",
              "value": "={{ String($json.rawBody.email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "form-n2",
              "name": "name",
              "value": "={{ String($json.rawBody.name || $json.rawBody.nombre || '').trim() }}",
              "type": "string"
            },
            {
              "id": "form-n3",
              "name": "company",
              "value": "={{ String($json.rawBody.company || $json.rawBody.empresa || '').trim() }}",
              "type": "string"
            },
            {
              "id": "form-n4",
              "name": "crmContactsUrl",
              "value": "={{ $json.crmContactsUrl }}",
              "type": "string"
            },
            {
              "id": "form-n5",
              "name": "crmApiKey",
              "value": "={{ $json.crmApiKey }}",
              "type": "string"
            },
            {
              "id": "form-n6",
              "name": "slackWebhookUrl",
              "value": "={{ $json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "form-n7",
              "name": "receivedAt",
              "value": "={{ $json.receivedAt }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "form-if-email",
      "name": "¿Email contiene @?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "form-cond-email",
              "leftValue": "={{ $json.email }}",
              "rightValue": "@",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "form-crm",
      "name": "Crear/actualizar CRM (HTTP)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.crmContactsUrl }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.crmApiKey }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ email: $json.email, name: $json.name, company: $json.company, source: 'web-form', receivedAt: $json.receivedAt }) }}",
        "options": {
          "timeout": 20000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      }
    },
    {
      "id": "form-after-crm",
      "name": "Unir CRM + lead",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1500,
        40
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "form-u1",
              "name": "crmStatus",
              "value": "={{ $json.statusCode }}",
              "type": "number"
            },
            {
              "id": "form-u2",
              "name": "crmOk",
              "value": "={{ Number($json.statusCode) >= 200 && Number($json.statusCode) < 300 }}",
              "type": "boolean"
            },
            {
              "id": "form-u3",
              "name": "crmId",
              "value": "={{ $json.body?.id || $json.body?.contactId || '' }}",
              "type": "string"
            },
            {
              "id": "form-u4",
              "name": "email",
              "value": "={{ $('Normalizar campos').item.json.email }}",
              "type": "string"
            },
            {
              "id": "form-u5",
              "name": "name",
              "value": "={{ $('Normalizar campos').item.json.name }}",
              "type": "string"
            },
            {
              "id": "form-u6",
              "name": "company",
              "value": "={{ $('Normalizar campos').item.json.company }}",
              "type": "string"
            },
            {
              "id": "form-u7",
              "name": "slackWebhookUrl",
              "value": "={{ $('Normalizar campos').item.json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "form-u8",
              "name": "receivedAt",
              "value": "={{ $('Normalizar campos').item.json.receivedAt }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "form-slack",
      "name": "Aviso Slack equipo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1800,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.slackWebhookUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.slackText || 'Actualización Logixb2b' }) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "form-invalid",
      "name": "Email inválido — descartar",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1200,
        560
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook Formulario": {
      "main": [
        [
          {
            "node": "Config formulario",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config formulario": {
      "main": [
        [
          {
            "node": "Normalizar campos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar campos": {
      "main": [
        [
          {
            "node": "¿Email contiene @?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Email contiene @?": {
      "main": [
        [
          {
            "node": "Crear/actualizar CRM (HTTP)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email inválido — descartar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Crear/actualizar CRM (HTTP)": {
      "main": [
        [
          {
            "node": "Unir CRM + lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unir CRM + lead": {
      "main": [
        [
          {
            "node": "Aviso Slack equipo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
