Código de Implementación

Configuración del Webhook

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "webhookId": "cotizacion-webhook"
    },
    {
      "parameters": {
        "functionCode": "// Procesar datos del formulario\nconst cotizacion = {\n  fecha: new Date().toLocaleDateString(),\n  numero: 'COT-' + Math.floor(Math.random() * 10000),\n  cliente: {\n    nombre: $input.all()[0].json.nombre,\n    email: $input.all()[0].json.email,\n    telefono: $input.all()[0].json.telefono,\n    empresa: $input.all()[0].json.empresa\n  },\n  items: $input.all()[0].json.items.map(item => ({\n    descripcion: item.descripcion,\n    cantidad: item.cantidad,\n    precioUnitario: item.precio,\n    total: item.cantidad * item.precio\n  })),\n  subtotal: $input.all()[0].json.items.reduce((sum, item) => sum + (item.cantidad * item.precio), 0),\n  iva: 0.16, // 16% de IVA (ajustar según país)\n  total: $input.all()[0].json.items.reduce((sum, item) => sum + (item.cantidad * item.precio), 0) * 1.16\n};\n\nreturn [{json: cotizacion}];"
      },
      "name": "Procesar Datos",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "operation": "create",
        "templateId": "",
        "additionalFields": {
          "fileName": "Cotizacion_{{ $node[\"Procesar Datos\"].json[\"numero"] }}.pdf",
          "folderId": ""
        },
        "options": {
          "pdf": true
        }
      },
      "name": "Generar PDF",
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "credentials": {
        "googleApi": "google-oauth2-api"
      }
    },
    {
      "parameters": {
        "subject": "Cotización {{ $node[\"Procesar Datos\"].json[\"numero"] }} - {{ $node[\"Procesar Datos\"].json[\"cliente\"][\"empresa"] }}",
        "body": "Estimado {{ $node[\"Procesar Datos\"].json[\"cliente\"][\"nombre"] }},

Adjunto encontrará la cotización solicitada.

Número: {{ $node[\"Procesar Datos\"].json[\"numero"] }}
Fecha: {{ $node[\"Procesar Datos\"].json[\"fecha"] }}
Total: {{ $node[\"Procesar Datos\"].json[\"total"].toFixed(2) }}

Saludos cordiales,
Equipo de Ventas", "to": "={{ $node[\"Procesar Datos\"].json[\"cliente\"][\"email"] }}", "additionalFields": { "attachments": { "property": "={{ $node[\"Generar PDF\"].json[\"pdf\"] }}", "name": "={{ $node[\"Generar PDF\"].json[\"fileName\"] }}" } }, "options": {} }, "name": "Enviar Email", "type": "n8n-nodes-base.emailSend", "typeVersion": 1, "position": [ 1050, 300 ], "credentials": { "smtp": "smtp-credentials" } }, { "parameters": { "operation": "create", "entity": "Cotizaciones", "properties": { "Numero": "={{ $node[\"Procesar Datos\"].json[\"numero"] }}", "Cliente": "={{ $node[\"Procesar Datos\"].json[\"cliente\"][\"nombre"] }}", "Empresa": "={{ $node[\"Procesar Datos\"].json[\"cliente\"][\"empresa"] }}", "Email": "={{ $node[\"Procesar Datos\"].json[\"cliente\"][\"email"] }}", "Telefono": "={{ $node[\"Procesar Datos\"].json[\"cliente\"][\"telefono"] }}", "Fecha": "={{ $node[\"Procesar Datos\"].json[\"fecha"] }}", "Total": "={{ $node[\"Procesar Datos\"].json[\"total"] }}", "Estado": "Enviada", "PDF": "={{ $node[\"Generar PDF\"].json[\"webViewLink\"] }}" } }, "name": "Registrar en CRM", "type": "n8n-nodes-base.airtable", "typeVersion": 1, "position": [ 1050, 450 ], "credentials": { "airtableApi": "airtable-api" } } ], "connections": { "Start": { "main": [ [ { "node": "Webhook", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "Procesar Datos", "type": "main", "index": 0 } ] ] }, "Procesar Datos": { "main": [ [ { "node": "Generar PDF", "type": "main", "index": 0 } ] ] }, "Generar PDF": { "main": [ [ { "node": "Enviar Email", "type": "main", "index": 0 }, { "node": "Registrar en CRM", "type": "main", "index": 0 } ] ] } } }

Explicación del Flujo

Webhook:

Recibe los datos del formulario web con la información del cliente y los items a cotizar.

Procesar Datos (Function Node):

Generar PDF (Google Docs):

Enviar Email:

Registrar en CRM (Airtable):

Configuración Requerida

Credenciales:

Plantilla de Google Docs:

Debemos crear una plantilla en Google Docs con marcadores de posición para los datos de la cotización

Formulario Web:

El formulario debe enviar datos en formato JSON con la siguiente estructura mínima:

{
    "nombre": "Nombre del Cliente",
    "email": "cliente@email.com",
    "telefono": "1234567890",
    "empresa": "Nombre de la Empresa",
    "items": [
        {
            "descripcion": "Producto o Servicio",
            "cantidad": 1,
            "precio": 100.00
        }
    ]
}
Flujo Informe Código