{
  "name": "Clasificar correos con Claude (FluIA)",
  "nodes": [
    {
      "parameters": {
        "content": "## Clasificar correos con Claude\n1. Conecta Gmail en el disparador y en 'Archivar newsletter'.\n2. Pon tu clave de Anthropic en el nodo Claude (Haiku: barato y rápido).\n3. En 'Archivar newsletter', elige la etiqueta de Gmail que quieras aplicar.\n4. Pon tu chat ID en Telegram y tu hoja en Google Sheets (columnas: fecha, remitente, asunto, categoria).\n\nPlantilla de fluia.es",
        "height": 220,
        "width": 520
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "63c61d24-90ae-466b-8a26-1d0213d13939",
      "name": "Nota 3ec9"
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": true,
        "filters": {},
        "options": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        320
      ],
      "id": "d25db878-2047-47c7-af47-173f259b8e5b",
      "name": "Correo nuevo",
      "credentials": {
        "gmailOAuth2": {
          "id": "REEMPLAZAR",
          "name": "Gmail (tu cuenta)"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Remitente: {{ $json.From }}\nAsunto: {{ $json.Subject }}\nTexto: {{ $json.snippet }}",
        "messages": {
          "messageValues": [
            {
              "type": "SystemMessagePromptTemplate",
              "message": "Clasifica el correo en UNA de estas categorías y responde solo con la palabra, sin nada más: URGENTE (pide una acción con plazo o es un problema), CLIENTE (un cliente o posible cliente), PROVEEDOR (facturas, pedidos, servicios contratados), NEWSLETTER (boletines, promociones, notificaciones automáticas), OTRO."
            }
          ]
        },
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        260,
        320
      ],
      "id": "ec9eeabb-c5d7-44ef-96b1-424b30318018",
      "name": "Claude clasifica"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "claude-haiku-4-5"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.6,
      "position": [
        300,
        540
      ],
      "id": "7f9d3ffe-06a9-48e6-9762-d7007d47d75f",
      "name": "Claude",
      "credentials": {
        "anthropicApi": {
          "id": "REEMPLAZAR",
          "name": "Anthropic (tu clave de API)"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Urgente",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "edb58627-35db-4f3f-83a4-71437879c669",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.text.trim().toUpperCase() }}",
                    "rightValue": "URGENTE"
                  }
                ]
              }
            },
            {
              "outputKey": "Newsletter",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "cac77d9b-9f68-446c-a69a-b1842d81dcc0",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.text.trim().toUpperCase() }}",
                    "rightValue": "NEWSLETTER"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Resto"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        640,
        320
      ],
      "id": "7cfe97a8-aa82-4dc0-9d16-66f185f861d0",
      "name": "Según categoría"
    },
    {
      "parameters": {
        "chatId": "TU_CHAT_ID",
        "text": "=🔴 Correo urgente de {{ $('Correo nuevo').item.json.From }}\nAsunto: {{ $('Correo nuevo').item.json.Subject }}\n\n{{ $('Correo nuevo').item.json.snippet }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        920,
        140
      ],
      "id": "88f1b562-c23b-475f-844e-0f4ef968ee5f",
      "name": "Avisar por Telegram",
      "credentials": {
        "telegramApi": {
          "id": "REEMPLAZAR",
          "name": "Bot de Telegram"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $('Correo nuevo').item.json.id }}",
        "labelIds": [
          "ID_DE_LA_ETIQUETA"
        ]
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        920,
        320
      ],
      "id": "f1cbad3d-988b-4e98-ab9b-0a1d2c84ff99",
      "name": "Archivar newsletter",
      "credentials": {
        "gmailOAuth2": {
          "id": "REEMPLAZAR",
          "name": "Gmail (tu cuenta)"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "ID_DE_TU_HOJA"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Correos"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "fecha": "={{ $now.toFormat('yyyy-MM-dd HH:mm') }}",
            "remitente": "={{ $('Correo nuevo').item.json.From }}",
            "asunto": "={{ $('Correo nuevo').item.json.Subject }}",
            "categoria": "={{ $json.text.trim().toUpperCase() }}"
          },
          "schema": [
            {
              "id": "fecha",
              "displayName": "fecha",
              "type": "string",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "remitente",
              "displayName": "remitente",
              "type": "string",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "asunto",
              "displayName": "asunto",
              "type": "string",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "categoria",
              "displayName": "categoria",
              "type": "string",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true
            }
          ],
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        920,
        500
      ],
      "id": "4a7ed605-bfd9-4f1b-953f-61d4259a2dc6",
      "name": "Registrar en Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REEMPLAZAR",
          "name": "Google Sheets (tu cuenta)"
        }
      }
    }
  ],
  "connections": {
    "Correo nuevo": {
      "main": [
        [
          {
            "node": "Claude clasifica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude": {
      "ai_languageModel": [
        [
          {
            "node": "Claude clasifica",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Claude clasifica": {
      "main": [
        [
          {
            "node": "Según categoría",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Según categoría": {
      "main": [
        [
          {
            "node": "Avisar por Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Archivar newsletter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Registrar en Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "instanceId": "fluia-plantilla"
  }
}