{
  "name": "Cotizador automático con IA",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Solicitud de cotización",
        "formDescription": "Completa los datos para recibir tu cotización personalizada",
        "formFields": {
          "values": [
            { "fieldLabel": "Nombre", "requiredField": true },
            { "fieldLabel": "Correo", "fieldType": "email", "requiredField": true },
            { "fieldLabel": "Producto o modelo", "requiredField": true },
            { "fieldLabel": "Cantidad", "fieldType": "number", "requiredField": true }
          ]
        },
        "options": {}
      },
      "id": "1f1a1a10-0001-4a10-8b1a-000000000001",
      "name": "Form Trigger",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [-140, 0],
      "webhookId": "cotizador-form-trigger"
    },
    {
      "parameters": {
        "operation": "get",
        "documentId": {
          "__rl": true,
          "value": "REEMPLAZA_CON_TU_ID_DE_GOOGLE_SHEET",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Precios",
          "mode": "list",
          "cachedResultName": "Precios"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Producto",
              "lookupValue": "={{ $json['Producto o modelo'] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "1f1a1a10-0002-4a10-8b1a-000000000002",
      "name": "Buscar precio histórico",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [80, 0],
      "notesInFlow": true,
      "notes": "Lookup en la hoja 'Precios' por Producto/Modelo"
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Eres un asesor comercial. Redacta una propuesta de cotización breve, cálida y profesional en español, usando el nombre del cliente, el producto, la cantidad y el precio histórico entregados. Incluye el total estimado."
            },
            {
              "role": "user",
              "content": "=Cliente: {{ $('Form Trigger').item.json['Nombre'] }}\nCorreo: {{ $('Form Trigger').item.json['Correo'] }}\nProducto: {{ $('Form Trigger').item.json['Producto o modelo'] }}\nCantidad: {{ $('Form Trigger').item.json['Cantidad'] }}\nPrecio histórico unitario: {{ $json['Precio'] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "1f1a1a10-0003-4a10-8b1a-000000000003",
      "name": "Redactar propuesta (IA)",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1.3,
      "position": [300, 0]
    },
    {
      "parameters": {
        "sendTo": "={{ $('Form Trigger').item.json['Correo'] }}",
        "subject": "=Tu cotización · {{ $('Form Trigger').item.json['Producto o modelo'] }}",
        "message": "={{ $json.message.content }}",
        "options": {}
      },
      "id": "1f1a1a10-0004-4a10-8b1a-000000000004",
      "name": "Enviar cotización (Gmail)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [520, -80]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "REEMPLAZA_CON_TU_ID_DE_GOOGLE_SHEET",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "CRM",
          "mode": "list",
          "cachedResultName": "CRM"
        },
        "columns": {
          "value": {
            "Nombre": "={{ $('Form Trigger').item.json['Nombre'] }}",
            "Correo": "={{ $('Form Trigger').item.json['Correo'] }}",
            "Producto": "={{ $('Form Trigger').item.json['Producto o modelo'] }}",
            "Cantidad": "={{ $('Form Trigger').item.json['Cantidad'] }}",
            "Fecha": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "1f1a1a10-0005-4a10-8b1a-000000000005",
      "name": "Registrar en CRM",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [520, 80]
    }
  ],
  "connections": {
    "Form Trigger": {
      "main": [[{ "node": "Buscar precio histórico", "type": "main", "index": 0 }]]
    },
    "Buscar precio histórico": {
      "main": [[{ "node": "Redactar propuesta (IA)", "type": "main", "index": 0 }]]
    },
    "Redactar propuesta (IA)": {
      "main": [
        [
          { "node": "Enviar cotización (Gmail)", "type": "main", "index": 0 },
          { "node": "Registrar en CRM", "type": "main", "index": 0 }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "plantilla-juanespaca-cotizador"
  }
}
