{
  "name": "Consulta Horarios por WhatsApp desde Excel",
  "nodes": [
    {
      "id": "1",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        100,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "consulta-horarios",
        "responseMode": "onReceived",
        "responseData": {
          "responseBody": "Recibido. Procesando consulta..."
        }
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "2",
      "name": "Simular Mensaje Usuario",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        300,
        300
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "mensaje",
              "value": "\u00bfQu\u00e9 horarios hay para ma\u00f1ana?"
            }
          ]
        }
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "3",
      "name": "Interpretar Fecha",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        500,
        300
      ],
      "parameters": {
        "functionCode": "const input = $json[\"mensaje\"]; const now = new Date(); let targetDate = new Date(); if (input.includes(\"ma\u00f1ana\")) { targetDate.setDate(now.getDate() + 1); } const yyyy = targetDate.getFullYear(); const mm = String(targetDate.getMonth() + 1).padStart(2, '0'); const dd = String(targetDate.getDate()).padStart(2, '0'); const formattedDate = `${yyyy}-${mm}-${dd}`; return [{ json: { fecha_buscada: formattedDate } }];"
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "4",
      "name": "Descargar Excel",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        300
      ],
      "parameters": {
        "url": "https://example.com/horarios.xlsx",
        "responseFormat": "file",
        "options": {}
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "5",
      "name": "Leer Excel",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "parameters": {
        "operation": "toJson",
        "options": {
          "rawData": false
        }
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "6",
      "name": "Filtrar Horarios",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1100,
        300
      ],
      "parameters": {
        "functionCode": "const fechaBuscada = $items(\"Interpretar Fecha\")[0].json.fecha_buscada; return items.filter(item => item.json.fecha === fechaBuscada);"
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "7",
      "name": "Formatear Mensaje",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1300,
        300
      ],
      "parameters": {
        "functionCode": "let texto = \"Horarios para la fecha solicitada:\\n\"; for (const item of items) { texto += `\ud83d\udd50 ${item.json.hora} - ${item.json.evento}\\n`; } return [{ json: { mensaje_final: texto } }];"
      },
      "notes": "",
      "credentials": {}
    },
    {
      "id": "8",
      "name": "Enviar por WhatsApp (Placeholder)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1500,
        300
      ],
      "parameters": {},
      "notes": "",
      "credentials": {}
    }
  ],
  "connections": {
    "Webhook Trigger": [
      [
        {
          "node": "Simular Mensaje Usuario",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Simular Mensaje Usuario": [
      [
        {
          "node": "Interpretar Fecha",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Interpretar Fecha": [
      [
        {
          "node": "Descargar Excel",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Descargar Excel": [
      [
        {
          "node": "Leer Excel",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Leer Excel": [
      [
        {
          "node": "Filtrar Horarios",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Filtrar Horarios": [
      [
        {
          "node": "Formatear Mensaje",
          "type": "main",
          "index": 0
        }
      ]
    ],
    "Formatear Mensaje": [
      [
        {
          "node": "Enviar por WhatsApp (Placeholder)",
          "type": "main",
          "index": 0
        }
      ]
    ]
  },
  "active": false,
  "settings": {},
  "versionId": "1"
}