{
 "name": "Alameda · consultas al CRM",
 "nodes": [
  {
   "id": "6ac30a4d-3ccd-4880-86a6-3d763879cf8c",
   "name": "Nota b7cb",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    -40,
    -380
   ],
   "parameters": {
    "content": "## Consultas de la inmobiliaria\nLlegan por el formulario del sitio o por webhook (portales, mail reenviado). La IA las clasifica en 4 ramas y cada rama asigna su asesor; después extrae zona, presupuesto y urgencia, las carga en el CRM con la fecha de seguimiento y avisa al asesor y al cliente.",
    "width": 560,
    "height": 200,
    "color": 4
   }
  },
  {
   "id": "790594f8-a06d-4ca5-8dad-e7c48bc1c359",
   "name": "Formulario del sitio",
   "type": "n8n-nodes-base.formTrigger",
   "typeVersion": 2.6,
   "position": [
    0,
    -60
   ],
   "parameters": {
    "formTitle": "Alameda Propiedades · Consultas",
    "formDescription": "Escríbenos qué buscas y un asesor te responde hoy.",
    "formFields": {
     "values": [
      {
       "fieldLabel": "Nombre",
       "fieldName": "nombre",
       "fieldType": "text",
       "requiredField": true,
       "placeholder": "Martina López"
      },
      {
       "fieldLabel": "Correo",
       "fieldName": "email",
       "fieldType": "email",
       "requiredField": true,
       "placeholder": "martina@correo.com"
      },
      {
       "fieldLabel": "Teléfono",
       "fieldName": "telefono",
       "fieldType": "text",
       "requiredField": false,
       "placeholder": "351 555 0000"
      },
      {
       "fieldLabel": "Tu consulta",
       "fieldName": "mensaje",
       "fieldType": "textarea",
       "requiredField": true,
       "placeholder": "Busco un 2 ambientes en alquiler en Nueva Córdoba, hasta 600 mil…"
      }
     ]
    },
    "responseMode": "onReceived",
    "options": {
     "appendAttribution": false,
     "buttonLabel": "Enviar consulta",
     "path": "consultas-alameda",
     "respondWithOptions": {
      "values": {
       "respondWith": "text",
       "formSubmittedText": "¡Gracias! Un asesor te escribe hoy mismo."
      }
     }
    }
   },
   "webhookId": "927a43d6-fb39-4658-a7f5-22fa46f3a538"
  },
  {
   "id": "adfcd65e-227c-45cb-afc7-44c7735c15cb",
   "name": "Webhook de portales",
   "type": "n8n-nodes-base.webhook",
   "typeVersion": 2.1,
   "position": [
    0,
    160
   ],
   "parameters": {
    "httpMethod": "POST",
    "path": "portales-alameda",
    "responseMode": "onReceived",
    "options": {}
   },
   "webhookId": "1d6e9789-cb02-4e12-9c12-aed8246c57b2"
  },
  {
   "id": "c0aed665-9d6e-4814-b9f8-57b35efa3d17",
   "name": "Unificar la consulta",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    240,
    40
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "945d02d6-91e1-4be3-b05e-42b797980f48",
       "name": "nombre",
       "value": "={{ $json.nombre || $json.body?.nombre }}",
       "type": "string"
      },
      {
       "id": "0285c1cd-84e1-41c8-aed5-016a95e2b5ee",
       "name": "email",
       "value": "={{ $json.email || $json.body?.email }}",
       "type": "string"
      },
      {
       "id": "850b4d2c-1cd6-4a91-8c9d-c706ffc42a7d",
       "name": "telefono",
       "value": "={{ $json.telefono || $json.body?.telefono || '' }}",
       "type": "string"
      },
      {
       "id": "41b9d49c-1443-4cfe-b2d8-9371cc1173ec",
       "name": "mensaje",
       "value": "={{ $json.mensaje || $json.body?.mensaje }}",
       "type": "string"
      },
      {
       "id": "3dfd2370-f54d-4a74-9b38-98c474a3195d",
       "name": "canal",
       "value": "={{ $json.body ? 'Portal / webhook' : 'Formulario del sitio' }}",
       "type": "string"
      }
     ]
    },
    "includeOtherFields": true,
    "options": {}
   }
  },
  {
   "id": "64649a8a-d38a-4efa-97e0-f5ef817561f2",
   "name": "La IA clasifica",
   "type": "@n8n/n8n-nodes-langchain.textClassifier",
   "typeVersion": 1.1,
   "position": [
    480,
    40
   ],
   "parameters": {
    "inputText": "={{ $json.mensaje }}",
    "categories": {
     "categories": [
      {
       "category": "Compra",
       "description": "Quiere comprar una propiedad"
      },
      {
       "category": "Alquiler",
       "description": "Quiere alquilar una propiedad"
      },
      {
       "category": "Tasación",
       "description": "Quiere tasar, vender o poner en alquiler una propiedad suya"
      },
      {
       "category": "Otra consulta",
       "description": "Cualquier otra cosa: reclamos, administración, trabajo"
      }
     ]
    },
    "options": {
     "fallback": "discard"
    }
   }
  },
  {
   "id": "f01e0419-a54a-4fa0-befa-05ed7c8e033c",
   "name": "Claude",
   "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
   "typeVersion": 1.6,
   "position": [
    500,
    280
   ],
   "parameters": {
    "model": {
     "__rl": true,
     "mode": "id",
     "value": "claude-sonnet-5-5"
    },
    "options": {
     "maxTokensToSample": 1200,
     "thinkingMode": "adaptive",
     "effort": "low"
    }
   },
   "credentials": {
    "anthropicApi": {
     "id": "",
     "name": "Claude (demos)"
    }
   }
  },
  {
   "id": "87120949-ee06-428e-825e-1df1c66958b2",
   "name": "Asesor: Lucía Ferreyra",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    780,
    -180
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "8bdaf31e-dcfc-40f2-8d30-64938a4ca554",
       "name": "tipo",
       "value": "Compra",
       "type": "string"
      },
      {
       "id": "d47cad18-5676-45c6-8bec-99b61cbd6553",
       "name": "asesor",
       "value": "Lucía Ferreyra",
       "type": "string"
      },
      {
       "id": "81c00d92-e712-4b56-8451-c7048f75755d",
       "name": "email_asesor",
       "value": "lucía@alameda.demo",
       "type": "string"
      }
     ]
    },
    "includeOtherFields": true,
    "options": {}
   }
  },
  {
   "id": "a78b16b0-6445-4a78-8b15-7656e88c2087",
   "name": "Asesor: Tomás Aguirre",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    780,
    -60
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "834c335a-2fcf-4cb7-8d5b-7b71f885dcbd",
       "name": "tipo",
       "value": "Alquiler",
       "type": "string"
      },
      {
       "id": "9d043515-a804-4428-9d0c-8f4c2a754c8b",
       "name": "asesor",
       "value": "Tomás Aguirre",
       "type": "string"
      },
      {
       "id": "06a1ff77-f902-4733-87dd-809e8d4007b0",
       "name": "email_asesor",
       "value": "tomás@alameda.demo",
       "type": "string"
      }
     ]
    },
    "includeOtherFields": true,
    "options": {}
   }
  },
  {
   "id": "5b265bba-0da4-4677-8d82-5901b2ed7f3a",
   "name": "Asesor: Carmen Ledesma",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    780,
    60
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "804dd2a3-7b50-450d-96c7-14640d854261",
       "name": "tipo",
       "value": "Tasación",
       "type": "string"
      },
      {
       "id": "198e6736-564e-4fc0-a5f7-5dea9d0c7a5e",
       "name": "asesor",
       "value": "Carmen Ledesma",
       "type": "string"
      },
      {
       "id": "1be7df7b-3a9a-4bbe-8c92-07c038987340",
       "name": "email_asesor",
       "value": "carmen@alameda.demo",
       "type": "string"
      }
     ]
    },
    "includeOtherFields": true,
    "options": {}
   }
  },
  {
   "id": "c5235616-baab-45bc-9280-ed73f7e4b101",
   "name": "Asesor: Recepción",
   "type": "n8n-nodes-base.set",
   "typeVersion": 3.4,
   "position": [
    780,
    180
   ],
   "parameters": {
    "assignments": {
     "assignments": [
      {
       "id": "0d0c8db7-4eb7-48e5-8d90-eb21f10f2302",
       "name": "tipo",
       "value": "Otra consulta",
       "type": "string"
      },
      {
       "id": "c0d00b74-46b8-4bb3-80f1-741da3752870",
       "name": "asesor",
       "value": "Recepción",
       "type": "string"
      },
      {
       "id": "4fb494fc-de14-481a-a725-e10dec27b01e",
       "name": "email_asesor",
       "value": "recepción@alameda.demo",
       "type": "string"
      }
     ]
    },
    "includeOtherFields": true,
    "options": {}
   }
  },
  {
   "id": "a2096233-abbe-406c-b58f-88a0884705fd",
   "name": "La IA saca los datos",
   "type": "@n8n/n8n-nodes-langchain.informationExtractor",
   "typeVersion": 1.2,
   "position": [
    1040,
    40
   ],
   "parameters": {
    "text": "={{ $json.mensaje }}",
    "schemaType": "fromAttributes",
    "attributes": {
     "attributes": [
      {
       "name": "zona",
       "type": "string",
       "description": "Barrio o zona que menciona; vacío si no dice"
      },
      {
       "name": "presupuesto",
       "type": "string",
       "description": "Presupuesto con su moneda tal como lo dice (ej. «600 mil por mes», «USD 120.000»); vacío si no dice"
      },
      {
       "name": "urgencia",
       "type": "string",
       "description": "alta (necesita ya, este mes, tiene fecha), media o baja",
       "required": true
      },
      {
       "name": "resumen",
       "type": "string",
       "description": "La consulta en una oración, para el asesor",
       "required": true
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "12da55af-3edd-4f64-897a-b1f5212797dd",
   "name": "Claude ",
   "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
   "typeVersion": 1.6,
   "position": [
    1060,
    280
   ],
   "parameters": {
    "model": {
     "__rl": true,
     "mode": "id",
     "value": "claude-sonnet-5-5"
    },
    "options": {
     "maxTokensToSample": 1200,
     "thinkingMode": "adaptive",
     "effort": "low"
    }
   },
   "credentials": {
    "anthropicApi": {
     "id": "",
     "name": "Claude (demos)"
    }
   }
  },
  {
   "id": "c2c91fc3-4902-4e0e-9a45-63f56cadca38",
   "name": "Fecha de seguimiento",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    1300,
    40
   ],
   "parameters": {
    "mode": "runOnceForEachItem",
    "jsCode": "\n// Urgencia alta: se llama hoy; media: mañana; baja: en 3 días. Siempre en día hábil (sábado y domingo pasan al lunes).\nconst u = String($json.output?.urgencia || 'media').toLowerCase();\nconst dias = u.startsWith('a') ? 0 : u.startsWith('m') ? 1 : 3;\nconst f = new Date(); f.setDate(f.getDate() + dias);\nif (f.getDay() === 6) f.setDate(f.getDate() + 2); if (f.getDay() === 0) f.setDate(f.getDate() + 1);\nconst base = $('Unificar la consulta').item.json;\n// El extractor devuelve sólo sus datos: el asesor se toma de la rama del clasificador que corrió.\nconst RAMAS = [\"Asesor: Lucía Ferreyra\", \"Asesor: Tomás Aguirre\", \"Asesor: Carmen Ledesma\", \"Asesor: Recepción\"];\nconst rama = RAMAS.map(n => { try { return $(n).item.json; } catch { return null; } }).find(Boolean) || {};\nreturn { ...base, ...$json.output, tipo: rama.tipo, asesor: rama.asesor, email_asesor: rama.email_asesor,\n  seguimiento: f.toISOString().slice(0, 10), urgencia: u };\n"
   }
  },
  {
   "id": "5c4d8a8a-94d2-489e-be1b-f28b4f224f93",
   "name": "Registro de consultas",
   "type": "n8n-nodes-base.dataTable",
   "typeVersion": 1.1,
   "position": [
    1540,
    40
   ],
   "parameters": {
    "resource": "row",
    "operation": "insert",
    "dataTableId": {
     "__rl": true,
     "mode": "id",
     "value": ""
    },
    "columns": {
     "mappingMode": "defineBelow",
     "value": {
      "recibida": "={{ $now.toISODate() }}",
      "nombre": "={{ $json.nombre }}",
      "email": "={{ $json.email }}",
      "telefono": "={{ $json.telefono }}",
      "tipo": "={{ $json.tipo }}",
      "urgencia": "={{ $json.urgencia }}",
      "presupuesto": "={{ $json.presupuesto }}",
      "zona": "={{ $json.zona }}",
      "asesor": "={{ $json.asesor }}",
      "resumen": "={{ $json.resumen }}"
     },
     "matchingColumns": [],
     "schema": [
      {
       "id": "recibida",
       "displayName": "recibida",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "nombre",
       "displayName": "nombre",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "email",
       "displayName": "email",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "telefono",
       "displayName": "telefono",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "tipo",
       "displayName": "tipo",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "urgencia",
       "displayName": "urgencia",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "presupuesto",
       "displayName": "presupuesto",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "zona",
       "displayName": "zona",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "asesor",
       "displayName": "asesor",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "resumen",
       "displayName": "resumen",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      }
     ]
    },
    "options": {}
   }
  },
  {
   "id": "b21528d7-d6e1-4365-9c61-555892143328",
   "name": "CRM · contacto",
   "type": "n8n-nodes-base.dataTable",
   "typeVersion": 1.1,
   "position": [
    1780,
    40
   ],
   "parameters": {
    "resource": "row",
    "operation": "upsert",
    "dataTableId": {
     "__rl": true,
     "mode": "id",
     "value": ""
    },
    "columns": {
     "mappingMode": "defineBelow",
     "value": {
      "nombre": "={{ $('Fecha de seguimiento').item.json.nombre }}",
      "email": "={{ $('Fecha de seguimiento').item.json.email }}",
      "telefono": "={{ $('Fecha de seguimiento').item.json.telefono }}",
      "origen": "={{ 'Alameda · ' + $('Fecha de seguimiento').item.json.canal }}",
      "etapa": "={{ 'Nuevo · ' + $('Fecha de seguimiento').item.json.tipo }}",
      "asesor": "={{ $('Fecha de seguimiento').item.json.asesor }}",
      "proximo_seguimiento": "={{ $('Fecha de seguimiento').item.json.seguimiento }}",
      "notas": "={{ $('Fecha de seguimiento').item.json.resumen }}"
     },
     "matchingColumns": [],
     "schema": [
      {
       "id": "nombre",
       "displayName": "nombre",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "email",
       "displayName": "email",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "telefono",
       "displayName": "telefono",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "origen",
       "displayName": "origen",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "etapa",
       "displayName": "etapa",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "asesor",
       "displayName": "asesor",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "proximo_seguimiento",
       "displayName": "proximo_seguimiento",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      },
      {
       "id": "notas",
       "displayName": "notas",
       "required": false,
       "defaultMatch": false,
       "display": true,
       "type": "string",
       "canBeUsedToMatch": true
      }
     ]
    },
    "options": {},
    "filters": {
     "conditions": [
      {
       "keyName": "email",
       "condition": "eq",
       "keyValue": "={{ $('Fecha de seguimiento').item.json.email }}"
      }
     ]
    }
   }
  },
  {
   "id": "e04e8d27-af20-45e1-9b8e-b0dc9c6dad6c",
   "name": "Aviso al asesor",
   "type": "n8n-nodes-base.emailSend",
   "typeVersion": 2.1,
   "position": [
    2020,
    -80
   ],
   "parameters": {
    "fromEmail": "CRM Alameda <crm@alameda.demo>",
    "toEmail": "={{ $('Fecha de seguimiento').item.json.email_asesor }}",
    "subject": "={{ ($('Fecha de seguimiento').item.json.urgencia.startsWith('a') ? '🔴 ' : '') + $('Fecha de seguimiento').item.json.tipo + ': ' + $('Fecha de seguimiento').item.json.nombre }}",
    "emailFormat": "html",
    "html": "={{ `<p><b>${$('Fecha de seguimiento').item.json.resumen}</b></p><p>Zona: ${$('Fecha de seguimiento').item.json.zona || '—'} · Presupuesto: ${$('Fecha de seguimiento').item.json.presupuesto || '—'} · Urgencia: ${$('Fecha de seguimiento').item.json.urgencia}</p><p>${$('Fecha de seguimiento').item.json.email} · ${$('Fecha de seguimiento').item.json.telefono || 'sin teléfono'}</p><p>Seguimiento agendado: ${$('Fecha de seguimiento').item.json.seguimiento}</p><blockquote>${$('Fecha de seguimiento').item.json.mensaje}</blockquote>` }}",
    "options": {
     "appendAttribution": false
    }
   },
   "credentials": {
    "smtp": {
     "id": "",
     "name": "Buzón de prueba (Mailpit)"
    }
   }
  },
  {
   "id": "da7344ad-3e14-4c98-a843-95d5df5bda74",
   "name": "Respuesta al cliente",
   "type": "n8n-nodes-base.emailSend",
   "typeVersion": 2.1,
   "position": [
    2020,
    160
   ],
   "parameters": {
    "fromEmail": "Alameda Propiedades <hola@alameda.demo>",
    "toEmail": "={{ $('Fecha de seguimiento').item.json.email }}",
    "subject": "Recibimos tu consulta · Alameda Propiedades",
    "emailFormat": "html",
    "html": "={{ `<div style=\"font-family:Georgia,serif;max-width:540px;color:#1C2622\"><p style=\"font-size:20px\">Alameda Propiedades</p><p>Hola, ${$('Fecha de seguimiento').item.json.nombre}:</p><p>Recibimos tu consulta de <b>${$('Fecha de seguimiento').item.json.tipo.toLowerCase()}</b>. Te va a atender <b>${$('Fecha de seguimiento').item.json.asesor}</b>, que te escribe ${$('Fecha de seguimiento').item.json.urgencia.startsWith('a') ? 'hoy mismo' : 'en las próximas horas'}.</p><p style=\"font-size:11px;color:#6C675E\">Demostración: Alameda es una inmobiliaria ficticia y este correo quedó en un buzón de prueba.</p></div>` }}",
    "options": {
     "appendAttribution": false
    }
   },
   "credentials": {
    "smtp": {
     "id": "",
     "name": "Buzón de prueba (Mailpit)"
    }
   }
  }
 ],
 "connections": {
  "Formulario del sitio": {
   "main": [
    [
     {
      "node": "Unificar la consulta",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Webhook de portales": {
   "main": [
    [
     {
      "node": "Unificar la consulta",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Unificar la consulta": {
   "main": [
    [
     {
      "node": "La IA clasifica",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Claude": {
   "ai_languageModel": [
    [
     {
      "node": "La IA clasifica",
      "type": "ai_languageModel",
      "index": 0
     }
    ]
   ]
  },
  "La IA clasifica": {
   "main": [
    [
     {
      "node": "Asesor: Lucía Ferreyra",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Asesor: Tomás Aguirre",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Asesor: Carmen Ledesma",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Asesor: Recepción",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Asesor: Lucía Ferreyra": {
   "main": [
    [
     {
      "node": "La IA saca los datos",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Asesor: Tomás Aguirre": {
   "main": [
    [
     {
      "node": "La IA saca los datos",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Asesor: Carmen Ledesma": {
   "main": [
    [
     {
      "node": "La IA saca los datos",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Asesor: Recepción": {
   "main": [
    [
     {
      "node": "La IA saca los datos",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Claude ": {
   "ai_languageModel": [
    [
     {
      "node": "La IA saca los datos",
      "type": "ai_languageModel",
      "index": 0
     }
    ]
   ]
  },
  "La IA saca los datos": {
   "main": [
    [
     {
      "node": "Fecha de seguimiento",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Fecha de seguimiento": {
   "main": [
    [
     {
      "node": "Registro de consultas",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Registro de consultas": {
   "main": [
    [
     {
      "node": "CRM · contacto",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "CRM · contacto": {
   "main": [
    [
     {
      "node": "Aviso al asesor",
      "type": "main",
      "index": 0
     },
     {
      "node": "Respuesta al cliente",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1",
  "timezone": "America/Argentina/Buenos_Aires",
  "saveManualExecutions": true
 }
}