{
  "name": "IA Negocios · Leads del formulario web a Google Sheets + aviso por email",
  "nodes": [
    {
      "parameters": {
        "content": "## Plantilla de IA Negocios (ianegocios.tech)\n\nRecibe los datos de un formulario web, los guarda en Google Sheets y te avisa por email.\n\n**Para ponerla en marcha:**\n1. En **Guardar en Google Sheets**: conecta tu cuenta de Google, pega la URL de tu hoja y crea una pestaña llamada `Leads` con las columnas: fecha, nombre, email, telefono, mensaje, origen.\n2. En **Avisarme por email**: conecta tu SMTP y cambia el remitente y el destinatario.\n3. Activa el workflow y copia la **Production URL** del nodo Webhook.\n4. Configura tu formulario para enviar un POST a esa URL con los campos `nombre`, `email`, `telefono` y `mensaje`.\n\nPrueba primero con datos ficticios. No guardes datos personales que no necesites (RGPD).",
        "height": 420,
        "width": 420
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e01",
      "name": "Instrucciones",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-480, -140]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-formulario",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e02",
      "name": "Formulario web",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0],
      "webhookId": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e0a"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "fecha",
              "value": "={{ $now.setZone('Europe/Madrid').toFormat('yyyy-LL-dd HH:mm') }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "nombre",
              "value": "={{ ($json.body.nombre ?? '').toString().trim() }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "email",
              "value": "={{ ($json.body.email ?? '').toString().trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "telefono",
              "value": "={{ ($json.body.telefono ?? '').toString().trim() }}",
              "type": "string"
            },
            {
              "id": "a5",
              "name": "mensaje",
              "value": "={{ ($json.body.mensaje ?? '').toString().trim().slice(0, 2000) }}",
              "type": "string"
            },
            {
              "id": "a6",
              "name": "origen",
              "value": "={{ $json.headers.referer ?? 'formulario web' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e03",
      "name": "Limpiar datos",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [220, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.email }}",
              "rightValue": "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e04",
      "name": "¿Email válido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Leads",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e05",
      "name": "Guardar en Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [680, -100]
    },
    {
      "parameters": {
        "fromEmail": "avisos@tudominio.com",
        "toEmail": "tu-email@tudominio.com",
        "subject": "={{ 'Nuevo lead: ' + $('Limpiar datos').item.json.nombre }}",
        "emailFormat": "text",
        "text": "=Nuevo contacto desde el formulario web\n\nFecha: {{ $('Limpiar datos').item.json.fecha }}\nNombre: {{ $('Limpiar datos').item.json.nombre }}\nEmail: {{ $('Limpiar datos').item.json.email }}\nTeléfono: {{ $('Limpiar datos').item.json.telefono }}\n\nMensaje:\n{{ $('Limpiar datos').item.json.mensaje }}\n\nYa está guardado en tu hoja de Google Sheets.",
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e06",
      "name": "Avisarme por email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [900, -100]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": true }",
        "options": {}
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e07",
      "name": "Responder OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [1120, -100]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": false, \"error\": \"Email no válido\" }",
        "options": {
          "responseCode": 400
        }
      },
      "id": "5c1d7a10-0b1e-4c55-9f3a-0a1b2c3d4e08",
      "name": "Responder error",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [680, 120]
    }
  ],
  "connections": {
    "Formulario web": {
      "main": [[{ "node": "Limpiar datos", "type": "main", "index": 0 }]]
    },
    "Limpiar datos": {
      "main": [[{ "node": "¿Email válido?", "type": "main", "index": 0 }]]
    },
    "¿Email válido?": {
      "main": [
        [{ "node": "Guardar en Google Sheets", "type": "main", "index": 0 }],
        [{ "node": "Responder error", "type": "main", "index": 0 }]
      ]
    },
    "Guardar en Google Sheets": {
      "main": [[{ "node": "Avisarme por email", "type": "main", "index": 0 }]]
    },
    "Avisarme por email": {
      "main": [[{ "node": "Responder OK", "type": "main", "index": 0 }]]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
