{
  "name": "Resumen matutino del correo (plano de Saphia Labs)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 7 * * 1-5"
            }
          ]
        }
      },
      "id": "trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": false,
        "limit": 30,
        "simple": true,
        "filters": {
          "readStatus": "unread",
          "receivedAfter": "={{ $now.minus(24, 'hours').toISO() }}",
          "q": "-category:promotions -category:social"
        }
      },
      "id": "gmail",
      "name": "Gmail: correos sin leer (24h)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Arma un solo JSON con remitente, asunto y las primeras 300 letras.\nconst correos = $input.all().map(i => ({\n  de: i.json.from || i.json.From || '',\n  asunto: i.json.subject || i.json.Subject || '(sin asunto)',\n  inicio: String(i.json.snippet || i.json.text || '').slice(0, 300),\n}));\nreturn [{ json: { fecha: $now.toFormat('cccc d LLLL'), total: correos.length, correos } }];"
      },
      "id": "code",
      "name": "Code: estructurar",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        0
      ]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "claude-sonnet-5-5"
        },
        "messages": {
          "values": [
            {
              "role": "user",
              "content": "={{ 'Fecha: ' + $json.fecha + '\\nCorreos sin leer: ' + $json.total + '\\n\\n' + JSON.stringify($json.correos, null, 2) }}"
            }
          ]
        },
        "options": {
          "system": "Eres el asistente ejecutivo de [nombre]. Recibes una lista de correos (remitente, asunto, inicio del texto). Devuelve un resumen de máximo 5 líneas:\n1. URGENTE HOY: lo que requiere respuesta o decisión antes del mediodía, con remitente y qué piden.\n2. PUEDE ESPERAR: lo relevante que no es urgente, en una línea cada uno, máximo 3.\n3. IGNORAR: cuántos correos son boletines, notificaciones o publicidad (solo el número).\nReglas: no inventes contenido que no esté en el texto; si un correo es ambiguo, ponlo en PUEDE ESPERAR; nombra a las personas tal como firman; sin emojis ni saludos.",
          "maxTokens": 4000
        }
      },
      "id": "claude",
      "name": "Claude: resumir",
      "type": "@n8n/n8n-nodes-langchain.anthropic",
      "typeVersion": 1,
      "position": [
        780,
        0
      ]
    },
    {
      "parameters": {
        "chatId": "TU_CHAT_ID",
        "text": "={{ ($json.content || []).filter(b => b.type === 'text').map(b => b.text).join('\\n').trim() || 'El resumen llegó vacío: revisa la ejecución en n8n.' }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "telegram",
      "name": "Telegram: enviar resumen",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1040,
        0
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Gmail: correos sin leer (24h)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail: correos sin leer (24h)": {
      "main": [
        [
          {
            "node": "Code: estructurar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: estructurar": {
      "main": [
        [
          {
            "node": "Claude: resumir",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude: resumir": {
      "main": [
        [
          {
            "node": "Telegram: enviar resumen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Bogota"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "probadoEn": "n8n 2.41.6, octubre 2026",
    "fuente": "https://saphialabs.com/recursos/flujos/#f1"
  }
}