{
  "name": "Reporte semanal automático",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [1],
              "triggerAtHour": 7
            }
          ]
        }
      },
      "id": "3f3a3a10-0001-4a10-8b1a-000000000001",
      "name": "Cada lunes 7am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [-160, 0]
    },
    {
      "parameters": {
        "operation": "get",
        "documentId": {
          "__rl": true,
          "value": "REEMPLAZA_CON_TU_ID_DE_GOOGLE_SHEET",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Ventas",
          "mode": "list",
          "cachedResultName": "Ventas"
        },
        "options": {}
      },
      "id": "3f3a3a10-0002-4a10-8b1a-000000000002",
      "name": "Leer Ventas",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [60, -100]
    },
    {
      "parameters": {
        "operation": "get",
        "documentId": {
          "__rl": true,
          "value": "REEMPLAZA_CON_TU_ID_DE_GOOGLE_SHEET",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Operacion",
          "mode": "list",
          "cachedResultName": "Operacion"
        },
        "options": {}
      },
      "id": "3f3a3a10-0003-4a10-8b1a-000000000003",
      "name": "Leer Operación",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [60, 100]
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineAll",
        "options": {}
      },
      "id": "3f3a3a10-0004-4a10-8b1a-000000000004",
      "name": "Unir datos",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [280, 0]
    },
    {
      "parameters": {
        "jsCode": "// Consolida ventas + operación en métricas simples para el resumen\nconst items = $input.all();\nconst ventas = items.filter(i => i.json.origen !== 'operacion');\nconst totalVentas = ventas.reduce((acc, i) => acc + (Number(i.json.monto) || 0), 0);\n\nreturn [{\n  json: {\n    totalVentas,\n    registros: items.length,\n    generadoEn: new Date().toISOString(),\n    datos: items.map(i => i.json)\n  }\n}];"
      },
      "id": "3f3a3a10-0005-4a10-8b1a-000000000005",
      "name": "Consolidar métricas",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [500, 0]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Eres un analista. Redacta un resumen ejecutivo semanal breve en español a partir de las métricas de ventas y operación entregadas. Incluye 2-3 hallazgos y, si detectas algo fuera de lo normal, márcalo como ALERTA."
            },
            {
              "role": "user",
              "content": "={{ JSON.stringify($json) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3f3a3a10-0006-4a10-8b1a-000000000006",
      "name": "Generar resumen (IA)",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1.3,
      "position": [720, 0]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "REEMPLAZA_CON_TU_CANAL",
          "mode": "list",
          "cachedResultName": "reportes-semanales"
        },
        "text": "={{ $json.message.content }}",
        "options": {}
      },
      "id": "3f3a3a10-0007-4a10-8b1a-000000000007",
      "name": "Publicar en Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [940, 0]
    }
  ],
  "connections": {
    "Cada lunes 7am": {
      "main": [
        [
          { "node": "Leer Ventas", "type": "main", "index": 0 },
          { "node": "Leer Operación", "type": "main", "index": 0 }
        ]
      ]
    },
    "Leer Ventas": {
      "main": [[{ "node": "Unir datos", "type": "main", "index": 0 }]]
    },
    "Leer Operación": {
      "main": [[{ "node": "Unir datos", "type": "main", "index": 1 }]]
    },
    "Unir datos": {
      "main": [[{ "node": "Consolidar métricas", "type": "main", "index": 0 }]]
    },
    "Consolidar métricas": {
      "main": [[{ "node": "Generar resumen (IA)", "type": "main", "index": 0 }]]
    },
    "Generar resumen (IA)": {
      "main": [[{ "node": "Publicar en Slack", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "plantilla-juanespaca-reporte-semanal"
  }
}
