{
  "name": "Agente de fotos · VisionRs",
  "nodes": [
    {
      "id": "6fcf1c31-a799-4f98-a6f1-db68d06c335b",
      "name": "Llega un mail con fotos",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.4,
      "position": [0, 0],
      "parameters": {
        "pollTimes": { "item": [{ "mode": "everyMinute" }] },
        "simple": false,
        "filters": {
          "q": "has:attachment subject:fotos -label:agente-revisado newer_than:7d",
          "readStatus": "both"
        },
        "options": { "downloadAttachments": true, "dataPropertyAttachmentsPrefixName": "attachment_" }
      }
    },
    {
      "id": "8e1f02d9-ac45-4122-b6b0-4bf3fd042fe8",
      "name": "Configuración",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [240, 0],
      "parameters": {
        "mode": "manual",
        "includeOtherFields": true,
        "assignments": {
          "assignments": [
            { "id": "cfg-chat", "name": "telegram_chat_id", "value": "PEGÁ ACÁ TU CHAT ID", "type": "string" }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "4fd36937-1cf0-4f3b-94ca-19f6711bc72f",
      "name": "Elegir la carpeta",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [480, 0],
      "parameters": {
        "text": "=Asunto: {{ $json.subject }}\n\n{{ ($json.text || \"\").slice(0, 1500) }}",
        "schemaType": "fromAttributes",
        "attributes": {
          "attributes": [
            { "name": "carpeta", "type": "string", "description": "Nombre corto y claro para la carpeta, sacado del asunto. Por ejemplo «Obra Pérez» o «Habitación 12». Sin la palabra fotos y sin fecha.", "required": true }
          ]
        },
        "options": {
          "systemPromptTemplate": "Elegís el nombre de la carpeta donde se guardan las fotos de un mail. Usá las palabras del asunto y no inventes nada. Si el asunto no dice nada útil, usá «Fotos sin nombre»."
        }
      }
    },
    {
      "id": "a192f8c7-1fcd-410f-ba3e-1732fb477d73",
      "name": "Cabeza: el modelo",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [500, 220],
      "parameters": {
        "model": { "__rl": true, "mode": "list", "value": "gpt-5-mini" },
        "options": { "reasoningEffort": "low" }
      }
    },
    {
      "id": "441f0d78-ee1d-4575-bef4-f91adbec7d5d",
      "name": "Crear la carpeta",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [760, 0],
      "parameters": {
        "resource": "folder",
        "operation": "create",
        "name": "={{ $now.toFormat('yyyy-MM-dd') }} · {{ $json.output.carpeta }}",
        "driveId": { "__rl": true, "mode": "list", "value": "My Drive" },
        "folderId": { "__rl": true, "mode": "list", "value": "root", "cachedResultName": "/ (Root folder)" },
        "options": {}
      }
    },
    {
      "id": "a8f58ca1-370d-4600-b2a6-5d717a4022d7",
      "name": "Separar las fotos",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1000, 0],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "// Una salida por cada foto del mail, lista para subir a su carpeta.\nconst fotos = [];\nfor (const [i, carpeta] of $input.all().entries()) {\n  const mail = $('Llega un mail con fotos').itemMatching(i);\n  for (const archivo of Object.values(mail.binary ?? {})) {\n    if (!archivo.mimeType?.startsWith('image/')) continue;\n    fotos.push({\n      json: { carpeta_id: carpeta.json.id, carpeta: carpeta.json.name, mail_id: mail.json.id },\n      binary: { foto: archivo },\n      pairedItem: { item: i },\n    });\n  }\n}\nreturn fotos;"
      }
    },
    {
      "id": "d4f04268-0dc5-4e64-8bcf-9616fa76348f",
      "name": "Subir la foto",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [1240, 0],
      "parameters": {
        "resource": "file",
        "operation": "upload",
        "inputDataFieldName": "foto",
        "driveId": { "__rl": true, "mode": "list", "value": "My Drive" },
        "folderId": { "__rl": true, "mode": "id", "value": "={{ $json.carpeta_id }}" },
        "options": {}
      }
    },
    {
      "id": "13d9824c-6ca7-4676-9bfa-34ebb1c23832",
      "name": "Avisar que están subidas",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [1480, 0],
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "={{ $('Configuración').first().json.telegram_chat_id }}",
        "text": "=Listo, subí las fotos:\n{{ Object.entries($(\"Separar las fotos\").all().reduce((a, f) => { a[f.json.carpeta] = (a[f.json.carpeta] || 0) + 1; return a }, {})).map(([c, n]) => \"• \" + n + (n === 1 ? \" foto\" : \" fotos\") + \" en «\" + c + \"»\").join(\"\\n\").replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\") }}",
        "additionalFields": { "appendAttribution": false }
      },
      "executeOnce": true,
      "webhookId": "b14a715a-329a-433d-b0cd-799e4b7db35b"
    },
    {
      "id": "2738c713-b8d1-43da-9127-19f83d8c21b0",
      "name": "Un aviso por mail",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1720, 0],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "// Los mails que ya tienen sus fotos en Drive, una vez cada uno.\nconst ids = [...new Set($('Separar las fotos').all().map(f => f.json.mail_id))];\nreturn ids.map(id => ({ json: { id } }));"
      }
    },
    {
      "id": "4090db81-34e4-4b5f-aafc-55cbad5a2b6f",
      "name": "Marcar como revisado",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [1960, 0],
      "parameters": {
        "resource": "message",
        "operation": "addLabels",
        "messageId": "={{ $json.id }}",
        "labelIds": []
      },
      "webhookId": "435f3546-93ba-4dc3-8382-6976bb35f3eb"
    },
    {
      "id": "d4640090-94fd-4b61-a4d7-1ec981f65f97",
      "name": "Nota: para usarlo",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-60, -520],
      "parameters": {
        "content": "## Agente de fotos\nUna plantilla de la guía «Tu primer agente, paso a paso» de VisionRs: visionrs.com.ar/ia/que-es-un-agente/\n\nCuando mandás (o te mandan) un mail con «fotos» en el asunto, el agente lee el asunto, crea en tu Drive una carpeta con la fecha y ese nombre, sube ahí cada foto y te avisa por Telegram.\n\n**Para usarlo:**\n1. Conectá tus cuentas en los bloques con aviso: Gmail, OpenAI, Google Drive y Telegram.\n2. En «Configuración», pegá tu chat ID de Telegram.\n3. En «Crear la carpeta», elegí la carpeta de Drive donde van todas (por ejemplo, «Fotos»).\n4. En Gmail, creá la etiqueta «agente-revisado» y elegila en «Marcar como revisado».\n5. Si querés otra palabra en vez de «fotos», cambiá la búsqueda en «Llega un mail con fotos».",
        "color": 5,
        "width": 580,
        "height": 460
      }
    },
    {
      "id": "7e7be56d-1525-44cf-8d70-1d71c9fcf041",
      "name": "Nota: la cabeza",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [400, 330],
      "parameters": {
        "content": "**La cabeza** es el modelo. Si preferís Claude o Gemini, borrá este bloque y conectá «Anthropic Chat Model» o «Google Gemini Chat Model».",
        "color": 6,
        "width": 380,
        "height": 130
      }
    }
  ],
  "connections": {
    "Llega un mail con fotos": { "main": [[{ "node": "Configuración", "type": "main", "index": 0 }]] },
    "Configuración": { "main": [[{ "node": "Elegir la carpeta", "type": "main", "index": 0 }]] },
    "Elegir la carpeta": { "main": [[{ "node": "Crear la carpeta", "type": "main", "index": 0 }]] },
    "Cabeza: el modelo": { "ai_languageModel": [[{ "node": "Elegir la carpeta", "type": "ai_languageModel", "index": 0 }]] },
    "Crear la carpeta": { "main": [[{ "node": "Separar las fotos", "type": "main", "index": 0 }]] },
    "Separar las fotos": { "main": [[{ "node": "Subir la foto", "type": "main", "index": 0 }]] },
    "Subir la foto": { "main": [[{ "node": "Avisar que están subidas", "type": "main", "index": 0 }]] },
    "Avisar que están subidas": { "main": [[{ "node": "Un aviso por mail", "type": "main", "index": 0 }]] },
    "Un aviso por mail": { "main": [[{ "node": "Marcar como revisado", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1", "timezone": "America/Argentina/Buenos_Aires" },
  "pinData": {},
  "nodeGroups": [
    {
      "id": "c73d4e62-5e29-438a-b0d3-fe7a4d84b4c7",
      "name": "Elige la carpeta y sube las fotos",
      "nodeNames": ["Elegir la carpeta", "Cabeza: el modelo", "Crear la carpeta", "Separar las fotos", "Subir la foto"],
      "description": "Lee el asunto, crea la carpeta con la fecha y sube ahí cada foto del mail"
    }
  ]
}
