{
  "name": "Logixb2b — Chatbot → cualificación → handoff",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Webhook chatbot → valida email → CRM create + Slack handoff; si inválido, log sin handoff."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "chatbot"
    },
    {
      "name": "handoff"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Chatbot → cualificación → handoff\n\n**Recurso:** `/recursos/chatbot-cualificacion-handoff`\n**Guía:** /chatbots-ia-cualificacion-inicial-leads-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 chatbot** (`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 handoff** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **Normalizar payload bot** (`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- **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- **Enlace CRM + handoff** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Slack handoff ventas** (`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- **Log email inválido** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\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-bot",
      "name": "Webhook chatbot",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "wh-bot",
      "parameters": {
        "httpMethod": "POST",
        "path": "chatbot-lead-handoff",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "set-config",
      "name": "Config handoff",
      "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": "crmRecordBaseUrl",
              "value": "https://TU-CRM.ejemplo/contacts/",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "set-norm",
      "name": "Normalizar payload bot",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        600,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "n1",
              "name": "email",
              "value": "={{ String((($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).email || '')).trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "n2",
              "name": "name",
              "value": "={{ ($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).name || '' }}",
              "type": "string"
            },
            {
              "id": "n3",
              "name": "company",
              "value": "={{ ($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).company || '' }}",
              "type": "string"
            },
            {
              "id": "n4",
              "name": "need",
              "value": "={{ ($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).need || '' }}",
              "type": "string"
            },
            {
              "id": "n5",
              "name": "chatSummary",
              "value": "={{ ($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).chatSummary || ($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).summary || '' }}",
              "type": "string"
            },
            {
              "id": "n6",
              "name": "emailValid",
              "value": "={{ /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(String((($('Webhook chatbot').item.json.body || $('Webhook chatbot').item.json).email || '')).trim()) }}",
              "type": "boolean"
            },
            {
              "id": "n7",
              "name": "crmCreateUrl",
              "value": "={{ $('Config handoff').item.json.crmCreateUrl }}",
              "type": "string"
            },
            {
              "id": "n8",
              "name": "crmRecordBaseUrl",
              "value": "={{ $('Config handoff').item.json.crmRecordBaseUrl }}",
              "type": "string"
            },
            {
              "id": "n9",
              "name": "slackWebhookUrl",
              "value": "={{ $('Config handoff').item.json.slackWebhookUrl }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "if-email",
      "name": "¿Email válido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "if-email-cond",
              "leftValue": "={{ $json.emailValid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "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({ email: $json.email, name: $json.name, company: $json.company, need: $json.need, source: 'chatbot', chatSummary: $json.chatSummary }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "set-link",
      "name": "Enlace CRM + handoff",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1500,
        40
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "l1",
              "name": "email",
              "value": "={{ $('Normalizar payload bot').item.json.email }}",
              "type": "string"
            },
            {
              "id": "l2",
              "name": "name",
              "value": "={{ $('Normalizar payload bot').item.json.name }}",
              "type": "string"
            },
            {
              "id": "l3",
              "name": "company",
              "value": "={{ $('Normalizar payload bot').item.json.company }}",
              "type": "string"
            },
            {
              "id": "l4",
              "name": "chatSummary",
              "value": "={{ $('Normalizar payload bot').item.json.chatSummary }}",
              "type": "string"
            },
            {
              "id": "l5",
              "name": "crmLink",
              "value": "={{ $('Normalizar payload bot').item.json.crmRecordBaseUrl + ($json.id || $json.contactId || $json.email || '') }}",
              "type": "string"
            },
            {
              "id": "l6",
              "name": "slackWebhookUrl",
              "value": "={{ $('Normalizar payload bot').item.json.slackWebhookUrl }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "http-slack",
      "name": "Slack handoff ventas",
      "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": "set-invalid",
      "name": "Log email inválido",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1200,
        560
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "i1",
              "name": "status",
              "value": "invalid_email",
              "type": "string"
            },
            {
              "id": "i2",
              "name": "email",
              "value": "={{ $json.email }}",
              "type": "string"
            },
            {
              "id": "i3",
              "name": "message",
              "value": "Lead chatbot descartado: email no válido",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "noop-invalid",
      "name": "Sin handoff",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1500,
        560
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook chatbot": {
      "main": [
        [
          {
            "node": "Config handoff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config handoff": {
      "main": [
        [
          {
            "node": "Normalizar payload bot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar payload bot": {
      "main": [
        [
          {
            "node": "¿Email válido?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Email válido?": {
      "main": [
        [
          {
            "node": "POST crear lead CRM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log email inválido",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST crear lead CRM": {
      "main": [
        [
          {
            "node": "Enlace CRM + handoff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enlace CRM + handoff": {
      "main": [
        [
          {
            "node": "Slack handoff ventas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log email inválido": {
      "main": [
        [
          {
            "node": "Sin handoff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
