{
  "name": "Flujo MVP \u2013 WA \u2192 Precalificaci\u00f3n \u2192 Sheets/Trello \u2192 Agenda \u2192 Recordatorios",
  "nodes": [
    {
      "parameters": {
        "path": "webhook",
        "methods": [
          "POST"
        ]
      },
      "id": "Webhook_Entrada",
      "name": "Webhook (WhatsApp)",
      "type": "n8n-nodes-base.webhook"
    },
    {
      "parameters": {
        "functionCode": "// Normaliza payload entrante (nombre, telefono, mensaje)\nreturn items.map(i=>{\n  const body = i.json.body || i.json;\n  return { json: {\n    nombre: body.nombre || '', dni: body.dni || '', telefono: body.telefono || '',\n    mensaje: body.mensaje || '', origen: 'WA'\n  }};\n});"
      },
      "name": "Function \u2013 Normalizar",
      "type": "n8n-nodes-base.function"
    },
    {
      "parameters": {
        "sheetId": "<REEMPLAZAR>",
        "range": "Casos_MVP!A:Z"
      },
      "name": "Google Sheets \u2013 Append",
      "type": "n8n-nodes-base.googleSheets"
    },
    {
      "parameters": {
        "resource": "card",
        "operation": "create",
        "idList": "<ID_LISTA_NUEVOS>",
        "name": "{{ $json.nombre || 'Nuevo caso' }}"
      },
      "name": "Trello \u2013 Crear tarjeta",
      "type": "n8n-nodes-base.trello"
    },
    {
      "parameters": {
        "resource": "event",
        "operation": "create",
        "calendarId": "<REEMPLAZAR>",
        "start": "={{$now.plus({ hours: 48 }).toISO()}}",
        "end": "={{$now.plus({ hours: 49 }).toISO()}}",
        "summary": "Cita inicial \u2013 {{ $json.nombre }}"
      },
      "name": "Google Calendar \u2013 Crear cita",
      "type": "n8n-nodes-base.googleCalendar"
    },
    {
      "parameters": {
        "url": "https://graph.facebook.com/v21.0/<PHONE_NUMBER_ID>/messages",
        "options": {
          "bodyContentType": "json"
        },
        "jsonParameters": true,
        "authentication": "none",
        "bodyParametersJson": "={ messaging_product: 'whatsapp', to: $json.telefono, type: 'text', text: { body: '\u00a1Gracias! Tu cita qued\u00f3 agendada. Te recordaremos 24 h y 3 h antes.' } }"
      },
      "name": "HTTP \u2013 Confirmaci\u00f3n WA",
      "type": "n8n-nodes-base.httpRequest"
    },
    {
      "parameters": {
        "amount": 24,
        "unit": "hours"
      },
      "name": "Wait \u2013 24h",
      "type": "n8n-nodes-base.wait"
    },
    {
      "parameters": {
        "url": "https://graph.facebook.com/v21.0/<PHONE_NUMBER_ID>/messages",
        "options": {
          "bodyContentType": "json"
        },
        "jsonParameters": true,
        "authentication": "none",
        "bodyParametersJson": "={ messaging_product: 'whatsapp', to: $json.telefono, type: 'text', text: { body: 'Recordatorio: ten\u00e9s turno ma\u00f1ana. Cualquier cambio, avisanos por ac\u00e1.' } }"
      },
      "name": "HTTP \u2013 Recordatorio 24h",
      "type": "n8n-nodes-base.httpRequest"
    },
    {
      "parameters": {
        "amount": 21,
        "unit": "hours"
      },
      "name": "Wait \u2013 21h",
      "type": "n8n-nodes-base.wait"
    },
    {
      "parameters": {
        "url": "https://graph.facebook.com/v21.0/<PHONE_NUMBER_ID>/messages",
        "options": {
          "bodyContentType": "json"
        },
        "jsonParameters": true,
        "authentication": "none",
        "bodyParametersJson": "={ messaging_product: 'whatsapp', to: $json.telefono, type: 'text', text: { body: 'Recordatorio: tu turno es en 3 horas. Te esperamos en el estudio.' } }"
      },
      "name": "HTTP \u2013 Recordatorio 3h",
      "type": "n8n-nodes-base.httpRequest"
    }
  ],
  "connections": {
    "Webhook (WhatsApp)": {
      "main": [
        [
          {
            "node": "Function \u2013 Normalizar",
            "type": "main"
          }
        ]
      ]
    },
    "Function \u2013 Normalizar": {
      "main": [
        [
          {
            "node": "Google Sheets \u2013 Append",
            "type": "main"
          },
          {
            "node": "Trello \u2013 Crear tarjeta",
            "type": "main"
          },
          {
            "node": "Google Calendar \u2013 Crear cita",
            "type": "main"
          }
        ]
      ]
    },
    "Google Calendar \u2013 Crear cita": {
      "main": [
        [
          {
            "node": "HTTP \u2013 Confirmaci\u00f3n WA",
            "type": "main"
          }
        ]
      ]
    },
    "HTTP \u2013 Confirmaci\u00f3n WA": {
      "main": [
        [
          {
            "node": "Wait \u2013 24h",
            "type": "main"
          }
        ]
      ]
    },
    "Wait \u2013 24h": {
      "main": [
        [
          {
            "node": "HTTP \u2013 Recordatorio 24h",
            "type": "main"
          }
        ]
      ]
    },
    "HTTP \u2013 Recordatorio 24h": {
      "main": [
        [
          {
            "node": "Wait \u2013 21h",
            "type": "main"
          }
        ]
      ]
    },
    "Wait \u2013 21h": {
      "main": [
        [
          {
            "node": "HTTP \u2013 Recordatorio 3h",
            "type": "main"
          }
        ]
      ]
    }
  }
}