{
  "name": "Logixb2b — Primer workflow de ventas B2B",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Webhook primer-lead → normaliza → IF email válido → POST CRM → Slack «Nuevo lead». Primer import de ventas B2B."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "ventas"
    },
    {
      "name": "primer-flujo"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Primer workflow de ventas B2B\n\n**Recurso:** `/recursos/primer-workflow-ventas-b2b`\n**Guía:** /como-crear-primer-workflow-n8n-ventas-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 primer-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 URLs** (`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 contiene @?** (`IF`): sin credencial. Comprueba la condición (email, umbral, over_limit, etc.) con datos reales de prueba.\n- **POST crear lead CRM** (`HTTP Request` CRM): Credentials → **Header Auth** / OAuth del CRM. Sustituye `crm*Url` en el nodo **Config**. Prueba con un Lead de sandbox.\n- **Unir lead + CRM** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Slack: Nuevo lead** (`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": "trigger-webhook",
      "name": "Webhook primer-lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "primer-lead",
      "parameters": {
        "httpMethod": "POST",
        "path": "primer-lead",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "set-config",
      "name": "Config URLs",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "crmCreateUrl",
              "value": "https://TU-CRM.ejemplo/api/contacts",
              "type": "string"
            },
            {
              "id": "c2",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "rawBody",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            }
          ]
        }
      }
    },
    {
      "id": "set-lead",
      "name": "Normalizar lead",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        600,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "l1",
              "name": "name",
              "value": "={{ String($json.rawBody.name || $json.rawBody.nombre || 'Lead sin nombre').trim() }}",
              "type": "string"
            },
            {
              "id": "l2",
              "name": "email",
              "value": "={{ String($json.rawBody.email || '').trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "l3",
              "name": "company",
              "value": "={{ String($json.rawBody.company || $json.rawBody.empresa || 'Empresa sin nombre').trim() }}",
              "type": "string"
            },
            {
              "id": "l4",
              "name": "source",
              "value": "={{ String($json.rawBody.source || $json.rawBody.origen || 'primer-workflow-n8n').trim() }}",
              "type": "string"
            },
            {
              "id": "l5",
              "name": "crmCreateUrl",
              "value": "={{ $json.crmCreateUrl }}",
              "type": "string"
            },
            {
              "id": "l6",
              "name": "slackWebhookUrl",
              "value": "={{ $json.slackWebhookUrl }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "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": "cond-email",
              "leftValue": "={{ $json.email }}",
              "rightValue": "@",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "http-crm",
      "name": "POST crear lead CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.crmCreateUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ name: $json.name, email: $json.email, company: $json.company, source: $json.source }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "set-after-crm",
      "name": "Unir lead + CRM",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1500,
        40
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "u1",
              "name": "name",
              "value": "={{ $('Normalizar lead').item.json.name }}",
              "type": "string"
            },
            {
              "id": "u2",
              "name": "email",
              "value": "={{ $('Normalizar lead').item.json.email }}",
              "type": "string"
            },
            {
              "id": "u3",
              "name": "company",
              "value": "={{ $('Normalizar lead').item.json.company }}",
              "type": "string"
            },
            {
              "id": "u4",
              "name": "source",
              "value": "={{ $('Normalizar lead').item.json.source }}",
              "type": "string"
            },
            {
              "id": "u5",
              "name": "slackWebhookUrl",
              "value": "={{ $('Normalizar lead').item.json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "u6",
              "name": "crmResponse",
              "value": "={{ JSON.stringify($json) }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "http-slack",
      "name": "Slack: Nuevo lead",
      "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": "noop-invalid",
      "name": "Email inválido — descartar",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1200,
        560
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook primer-lead": {
      "main": [
        [
          {
            "node": "Config URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config URLs": {
      "main": [
        [
          {
            "node": "Normalizar lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar lead": {
      "main": [
        [
          {
            "node": "¿Email contiene @?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Email contiene @?": {
      "main": [
        [
          {
            "node": "POST crear lead CRM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email inválido — descartar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST crear lead CRM": {
      "main": [
        [
          {
            "node": "Unir lead + CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unir lead + CRM": {
      "main": [
        [
          {
            "node": "Slack: Nuevo lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
