{
  "name": "Recepcionista IA · Clínica dental (WhatsApp)",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {}
      },
      "id": "242059b7-948e-447a-a8ba-1abde71a437d",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        0,
        400
      ],
      "webhookId": "8fd5ad24-df1e-4b80-ad67-0e563b1b8359"
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "b2215af4-75a1-41aa-aa7a-b905f92c01f6",
              "name": "clinica",
              "value": "Clínica Dental Ruiz",
              "type": "string"
            },
            {
              "id": "aab74662-481f-4277-ab6e-9f964d30299f",
              "name": "doctora",
              "value": "Dra. Ruiz",
              "type": "string"
            },
            {
              "id": "9c504e19-a325-47c9-a08d-6675642fd92c",
              "name": "direccion",
              "value": "Av. Ejemplo 123, Tu ciudad",
              "type": "string"
            },
            {
              "id": "afbfe0ad-7fb5-4f9f-a16f-9b78bdcefb7c",
              "name": "latitud",
              "value": 19.4326,
              "type": "number"
            },
            {
              "id": "02e8d53e-e644-4a3a-a1b6-c5896ceb72d3",
              "name": "longitud",
              "value": -99.1332,
              "type": "number"
            },
            {
              "id": "fec8802a-e583-4340-aeab-aac43a6232c5",
              "name": "zonaHoraria",
              "value": "America/Mexico_City",
              "type": "string"
            },
            {
              "id": "74f79793-6ffa-44ab-abab-a02d8ad4954b",
              "name": "horario",
              "value": "Lunes a viernes de 9:00 a 19:00 y sábados de 9:00 a 14:00. Domingos cerrado.",
              "type": "string"
            },
            {
              "id": "7d3b53f3-f09b-4d6f-a0db-16fb29d31538",
              "name": "servicios",
              "value": "Valoración $25 USD; Limpieza dental $50 USD; Resina desde $60 USD; Atención de urgencia $45 USD; Ortodoncia: valoración sin costo. (Precios de ejemplo: pon los tuyos y tu moneda.)",
              "type": "string"
            },
            {
              "id": "a6b014cf-1a17-4bda-a7df-ebb465f03a37",
              "name": "telefonoClinica",
              "value": "5215500000000",
              "type": "string"
            },
            {
              "id": "88db2248-8681-4d36-ac49-27f3c7e141a2",
              "name": "idiomaPlantillas",
              "value": "es",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "44a358df-75cb-4863-aa70-a2bff3eb9fc3",
      "name": "Datos de la clínica",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        400
      ]
    },
    {
      "parameters": {
        "jsCode": "// One clean item per incoming WhatsApp message. Status updates (sent, delivered, read) are dropped here.\nconst out = [];\n$input.all().forEach((item, index) => {\n  const raw = item.json;\n  const v = raw.messages ? raw : (raw.entry?.[0]?.changes?.[0]?.value ?? raw);\n  const msg = v.messages?.[0];\n  if (!msg) return;\n\n  const contacto = v.contacts?.[0] ?? {};\n  let tipo = msg.type;\n  let texto = '';\n  let eleccion = null;\n\n  if (msg.type === 'text') texto = msg.text?.body ?? '';\n  else if (msg.type === 'interactive') {\n    const r = msg.interactive?.button_reply ?? msg.interactive?.list_reply ?? {};\n    texto = r.title ?? '';\n    // our time buttons carry the appointment in their id: {\"i\": inicio, \"u\": urgente, \"m\": motivo, \"n\": nombre}\n    try {\n      const p = JSON.parse(r.id);\n      if (p && p.i) { eleccion = p; tipo = 'eleccion'; }\n    } catch (e) {}\n  } else if (msg.type === 'button') {\n    // quick reply on a template: the only template with buttons is the appointment reminder\n    texto = `${msg.button?.text ?? ''} (respuesta al recordatorio de su cita de mañana)`;\n  } else if (msg.type !== 'audio') texto = `[El paciente envió un mensaje de tipo \"${msg.type}\" que no se puede leer]`;\n\n  out.push({\n    json: {\n      tipo,\n      texto,\n      telefono: msg.from,\n      nombre: eleccion?.n || contacto.profile?.name || '',\n      audioId: msg.audio?.id ?? null,\n      mensajeId: msg.id,\n      phoneNumberId: v.metadata?.phone_number_id,\n      // only for a tapped time button\n      inicio: eleccion?.i ?? null,\n      urgente: eleccion ? eleccion.u === 1 : false,\n      motivo: eleccion?.m ?? '',\n    },\n    pairedItem: { item: index },\n  });\n});\nreturn out;"
      },
      "id": "2c33d368-eac1-4b31-ad3e-0524b15bfbd8",
      "name": "Lee el mensaje",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        400
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "6ab6ad38-a8c7-4b48-a5a5-81218d7b53b6",
                    "leftValue": "={{ $json.tipo }}",
                    "rightValue": "eleccion",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Eligió horario"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "1d89e5c4-5425-43eb-a28b-f2346dec277b",
                    "leftValue": "={{ $json.tipo }}",
                    "rightValue": "audio",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Audio"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Texto"
        }
      },
      "id": "6405d68d-d20b-406a-ad8d-30c33bfeabeb",
      "name": "Tipo de mensaje",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        660,
        400
      ]
    },
    {
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.audioId }}"
      },
      "id": "cbebc272-3c24-421a-afac-1119f27f4947",
      "name": "Obtén el audio",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        860,
        200
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "3d707e89-9aa6-4be6-ad76-7087db8083d8",
      "name": "Descarga el audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1060,
        200
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "audio",
        "operation": "transcribe",
        "binaryPropertyName": "data",
        "options": {
          "language": "es"
        }
      },
      "id": "ac039052-d88b-4cfa-ac91-dfcbe723c750",
      "name": "Transcribe audio",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.3,
      "position": [
        1460,
        200
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Fecha y hora actual en la clínica: {{ $now.setZone($('Datos de la clínica').first().json.zonaHoraria).setLocale('es').toFormat(\"cccc d 'de' LLLL 'de' yyyy, HH:mm\") }}\nPaciente: {{ $('Lee el mensaje').item.json.nombre || 'sin nombre' }} (WhatsApp +{{ $('Lee el mensaje').item.json.telefono }})\nMensaje{{ $('Lee el mensaje').item.json.tipo === 'audio' ? ' (nota de voz transcrita)' : '' }}: {{ $('Lee el mensaje').item.json.tipo === 'audio' ? ($json.text || '[No se pudo escuchar la nota de voz: pídele con amabilidad que la escriba]') : $('Lee el mensaje').item.json.texto }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=Eres la recepcionista virtual de {{ $('Datos de la clínica').first().json.clinica }}, una clínica dental. Atiendes por WhatsApp a cualquier hora, también de noche y en fines de semana, cuando no hay nadie en la clínica.\n\nDatos de la clínica\n- Doctora: {{ $('Datos de la clínica').first().json.doctora }}\n- Dirección: {{ $('Datos de la clínica').first().json.direccion }}\n- Horario de atención: {{ $('Datos de la clínica').first().json.horario }}\n- Zona horaria: {{ $('Datos de la clínica').first().json.zonaHoraria }}\n- Cada cita dura 30 minutos.\n- Servicios y precios de referencia: {{ $('Datos de la clínica').first().json.servicios }}\n\nTu trabajo\n1. Entender qué necesita la persona, aunque escriba informal o con errores. Los audios te llegan ya transcritos.\n2. Detectar urgencias: dolor fuerte, sangrado que no para, cara inflamada, golpe o diente roto, fiebre con dolor dental. Si hay urgencia, marca urgente=true y ofrece primero los horarios libres más cercanos.\n3. Agendar. Antes de ofrecer horarios, usa la herramienta \"Agenda\" para ver qué horarios están ocupados en el rango que vas a ofrecer. Ofrece 2 o 3 horarios de 30 minutos que estén libres, dentro del horario de atención y nunca en el pasado.\n4. Si la persona confirma un horario escribiéndolo (en vez de tocar un botón), revisa con \"Agenda\" que siga libre y que esté dentro del horario de atención, y responde con accion=\"reservar\" y cita_inicio. Si no está libre, ofrece otros.\n5. Si en la conversación ya quedó agendada una cita, no vuelvas a ofrecer horarios salvo que la persona pida otra cita.\n6. Si la persona responde al recordatorio de su cita: si confirma, agradécele y dile que la esperan; si quiere cambiar la hora, usa accion=\"derivar\".\n\nLímites\n- No des diagnósticos ni recomiendes medicamentos. Si preguntan qué tienen, explica con calidez que la doctora lo revisará en la cita. Ante una emergencia grave (dificultad para respirar o tragar, inflamación que avanza rápido), indícale que acuda a urgencias de inmediato.\n- No inventes precios, servicios ni horarios que no estén en los datos de la clínica.\n- Si piden cambiar o cancelar una cita ya agendada, o algo que no puedes resolver, usa accion=\"derivar\" y diles que el equipo de la clínica les confirma en cuanto abra.\n- Pide el nombre de la persona antes de ofrecer horarios si todavía no lo sabes.\n\nEstilo: como un mensaje de WhatsApp. Breve (máximo 3 frases), cálido, en español neutro, sin formato markdown y con un emoji como máximo.\n\nCampos de tu respuesta\n- respuesta: el mensaje para la persona.\n- accion: \"responder\", \"ofrecer_horarios\" (con botones), \"reservar\" o \"derivar\".\n- botones: solo con accion=\"ofrecer_horarios\". De 2 a 3 objetos con titulo (máximo 20 caracteres y distintos entre sí, por ejemplo \"Mié 5 · 09:30\") e inicio (fecha y hora ISO 8601 con zona horaria, por ejemplo 2026-11-05T09:30:00-06:00).\n- urgente: true o false.\n- motivo: el motivo de consulta en 2 a 5 palabras.\n- nombre_paciente: el nombre, si lo sabes.\n- cita_inicio: solo con accion=\"reservar\", en ISO 8601 con zona horaria.",
          "maxIterations": 6
        }
      },
      "id": "6202148a-9d02-41ca-a057-105ea4647528",
      "name": "Recepcionista IA",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1820,
        400
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "claude-opus-5-5"
        },
        "options": {
          "maxTokensToSample": 4096,
          "thinkingMode": "adaptive",
          "effort": "medium",
          "promptCaching": "5m"
        }
      },
      "id": "f60dab43-e963-40bf-acaa-93b22854e1b6",
      "name": "Claude",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.6,
      "position": [
        1660,
        660
      ]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Lee el mensaje').item.json.telefono }}",
        "contextWindowLength": 12
      },
      "id": "8b1a8b06-4430-482a-a2bc-f7599253bc7a",
      "name": "Memoria",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        1820,
        660
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Devuelve los horarios OCUPADOS de la agenda de la doctora entre 'desde' y 'hasta'. Úsala siempre antes de ofrecer horarios.",
        "resource": "calendar",
        "operation": "availability",
        "calendar": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "timeMin": "={{ $fromAI('desde', 'Inicio del rango a revisar, ISO 8601 con zona horaria', 'string') }}",
        "timeMax": "={{ $fromAI('hasta', 'Fin del rango a revisar, ISO 8601 con zona horaria', 'string') }}",
        "options": {
          "outputFormat": "bookedSlots"
        }
      },
      "id": "891e9d6d-47f1-4acf-aba2-dca1b282afcb",
      "name": "Agenda",
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        1980,
        660
      ]
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"respuesta\": {\n      \"type\": \"string\",\n      \"description\": \"Mensaje de WhatsApp para la persona\"\n    },\n    \"accion\": {\n      \"type\": \"string\",\n      \"enum\": [\n        \"responder\",\n        \"ofrecer_horarios\",\n        \"reservar\",\n        \"derivar\"\n      ]\n    },\n    \"botones\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"titulo\": {\n            \"type\": \"string\"\n          },\n          \"inicio\": {\n            \"type\": \"string\"\n          }\n        },\n        \"required\": [\n          \"titulo\",\n          \"inicio\"\n        ]\n      }\n    },\n    \"urgente\": {\n      \"type\": \"boolean\"\n    },\n    \"motivo\": {\n      \"type\": \"string\"\n    },\n    \"nombre_paciente\": {\n      \"type\": \"string\"\n    },\n    \"cita_inicio\": {\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"respuesta\",\n    \"accion\",\n    \"urgente\"\n  ]\n}"
      },
      "id": "69fff631-3fcf-44fb-a804-4f31f2530f62",
      "name": "Formato de respuesta",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        2140,
        660
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Turns the agent's answer into what WhatsApp needs, plus the conversation context.\nconst ctx = $('Lee el mensaje').item.json;\nconst o = $json.output ?? {};\n// The agent failed (API down, no credits...): answer politely and alert the clinic.\nconst fallo = !$json.output;\nconst corta = (s, n) => String(s ?? '').replace(/\\s+/g, ' ').trim().slice(0, n);\n\nlet original = ctx.texto;\ntry { original = $('Transcribe audio').item.json.text || original; } catch (e) {}\n\nconst nombre = corta(o.nombre_paciente || ctx.nombre, 40);\nconst urgente = o.urgente === true;\nconst motivo = corta(o.motivo, 40);\n\n// WhatsApp reply buttons: max 3, unique titles up to 20 characters, ids up to 256 characters\nconst vistos = new Set();\nconst botones = (Array.isArray(o.botones) ? o.botones : [])\n  .filter((b) => b && b.inicio && b.titulo && !vistos.has(corta(b.titulo, 20)) && vistos.add(corta(b.titulo, 20)))\n  .slice(0, 3)\n  .map((b) => ({\n    type: 'reply',\n    reply: { id: JSON.stringify({ i: b.inicio, u: urgente ? 1 : 0, m: motivo, n: nombre }).slice(0, 256), title: corta(b.titulo, 20) },\n  }));\n\nlet accion = fallo ? 'derivar' : o.accion || 'responder';\nif (accion === 'ofrecer_horarios' && botones.length === 0) accion = 'responder';\nif (accion === 'reservar' && !DateTime.fromISO(String(o.cita_inicio ?? '')).isValid) accion = 'responder';\n\nreturn {\n  json: {\n    accion,\n    respuesta: o.respuesta || 'Gracias por escribir 🙏 En cuanto pueda, alguien de la clínica te responde por aquí.',\n    botones,\n    urgente,\n    motivo,\n    nombre,\n    inicio: o.cita_inicio ?? null,\n    telefono: ctx.telefono,\n    phoneNumberId: ctx.phoneNumberId,\n    mensajeOriginal: corta(original, 180),\n  },\n};"
      },
      "id": "e17c7266-8459-4ca7-ad27-a2077b33f974",
      "name": "Prepara la respuesta",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2180,
        400
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "e265690f-06fb-4bc6-a40c-4c79a2ad328c",
                    "leftValue": "={{ $json.accion }}",
                    "rightValue": "ofrecer_horarios",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Ofrece horarios"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "fcd79bac-5b34-4224-a1d7-901690a40b5d",
                    "leftValue": "={{ $json.accion }}",
                    "rightValue": "reservar",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Reserva"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Responde"
        }
      },
      "id": "19916455-8ee9-4b99-af2f-1573e05807a8",
      "name": "¿Qué hace?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        2400,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v23.0/{{ $json.phoneNumberId }}/messages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "whatsAppApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ messaging_product: 'whatsapp', recipient_type: 'individual', to: $json.telefono, type: 'interactive', interactive: { type: 'button', body: { text: $json.respuesta }, action: { buttons: $json.botones } } }) }}",
        "options": {}
      },
      "id": "e62a515e-dec9-440b-ad61-431c65037214",
      "name": "Envía horarios (botones)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2640,
        220
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "phoneNumberId": "={{ $json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $json.telefono }}",
        "textBody": "={{ $json.respuesta }}",
        "additionalFields": {}
      },
      "id": "d2d691cb-598a-44a0-a3ab-7c39aca3505a",
      "name": "Responde",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        2640,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "d082b4a8-0e00-49ee-aa9c-be1dccc6a7af",
              "leftValue": "={{ $json.urgente }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            },
            {
              "id": "2d348b34-f803-4ade-a5cd-64521bd802ba",
              "leftValue": "={{ $json.accion }}",
              "rightValue": "derivar",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "0deed41e-b9da-4474-abab-d5eb27fd8eac",
      "name": "¿Avisar a la clínica?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2400,
        860
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "sendTemplate",
        "phoneNumberId": "={{ $json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $('Datos de la clínica').first().json.telefonoClinica }}",
        "template": "=aviso_clinica|{{ $('Datos de la clínica').first().json.idiomaPlantillas }}",
        "components": {
          "component": [
            {
              "type": "body",
              "bodyParameters": {
                "parameter": [
                  {
                    "type": "text",
                    "text": "={{ $json.urgente ? 'URGENCIA' : 'Revisión' }}"
                  },
                  {
                    "type": "text",
                    "text": "={{ $json.nombre || 'Sin nombre' }} (+{{ $json.telefono }})"
                  },
                  {
                    "type": "text",
                    "text": "={{ $json.mensajeOriginal || $json.motivo || '-' }}"
                  }
                ]
              }
            }
          ]
        }
      },
      "id": "535c39e2-892e-46fb-a9a6-c46128448ea7",
      "name": "Avisa a la clínica",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        2640,
        860
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "511e7e0f-50dc-4b02-a47a-bfd54cb85e3d",
              "name": "telefono",
              "value": "={{ $json.telefono }}",
              "type": "string"
            },
            {
              "id": "dff8d722-dd24-4661-a03f-98bc7d7e1171",
              "name": "phoneNumberId",
              "value": "={{ $json.phoneNumberId }}",
              "type": "string"
            },
            {
              "id": "eb8d7e2b-1629-4d54-a256-ed5da57e3c2b",
              "name": "nombre",
              "value": "={{ $json.nombre || 'Paciente' }}",
              "type": "string"
            },
            {
              "id": "99af0b23-374e-41f8-a09e-c08681b5c8f2",
              "name": "motivo",
              "value": "={{ $json.motivo || 'Consulta' }}",
              "type": "string"
            },
            {
              "id": "83bb6c82-1d87-4fde-a2e7-8dfcc1ce91e5",
              "name": "urgente",
              "value": "={{ $json.urgente === true }}",
              "type": "boolean"
            },
            {
              "id": "0f544b1e-4632-4729-ab1e-7099353daa7c",
              "name": "inicio",
              "value": "={{ DateTime.fromISO($json.inicio, { setZone: true }).toISO() }}",
              "type": "string"
            },
            {
              "id": "e22cbcaf-fd25-4d77-a16f-9d9e89d11e9a",
              "name": "fin",
              "value": "={{ DateTime.fromISO($json.inicio, { setZone: true }).plus({ minutes: 30 }).toISO() }}",
              "type": "string"
            },
            {
              "id": "3567ce00-33f0-4b5a-a2bd-45f37660a73a",
              "name": "inicioLegible",
              "value": "={{ DateTime.fromISO($json.inicio, { setZone: true }).setLocale('es').toFormat(\"cccc d 'de' LLLL 'a las' HH:mm\") }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "d1a631d9-3d88-472c-a8bf-c011f8cdecbd",
      "name": "Datos de la cita",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2880,
        620
      ]
    },
    {
      "parameters": {
        "resource": "calendar",
        "operation": "availability",
        "calendar": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "timeMin": "={{ $json.inicio }}",
        "timeMax": "={{ $json.fin }}",
        "options": {
          "outputFormat": "availability"
        }
      },
      "id": "24039d2f-5ee8-4a3b-a2d5-ad67d58dd37e",
      "name": "¿Sigue libre?",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        3100,
        620
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c0254330-94c6-4f76-a18d-6dc30dca1556",
              "leftValue": "={{ $json.available }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            },
            {
              "id": "48382262-c04f-435e-8769-9d0702337520",
              "leftValue": "={{ DateTime.fromISO($('Datos de la cita').item.json.inicio) > $now }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d2aae8f7-4dc0-4763-affc-9948882b66c5",
      "name": "¿Libre?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3320,
        620
      ]
    },
    {
      "parameters": {
        "resource": "event",
        "operation": "create",
        "calendar": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "start": "={{ $('Datos de la cita').item.json.inicio }}",
        "end": "={{ $('Datos de la cita').item.json.fin }}",
        "additionalFields": {
          "summary": "={{ ($('Datos de la cita').item.json.urgente ? '🚨 ' : '') + $('Datos de la cita').item.json.nombre + ' · ' + $('Datos de la cita').item.json.motivo }}",
          "description": "=Paciente: {{ $('Datos de la cita').item.json.nombre }}\nWhatsApp: +{{ $('Datos de la cita').item.json.telefono }}\nMotivo: {{ $('Datos de la cita').item.json.motivo }}\nUrgente: {{ $('Datos de la cita').item.json.urgente ? 'Sí' : 'No' }}\nAgendada por la Recepcionista IA",
          "location": "={{ $('Datos de la clínica').first().json.direccion }}"
        }
      },
      "id": "6060e085-cd70-4621-afef-8be92e1aca57",
      "name": "Crea la cita",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        3540,
        520
      ]
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "sheetName": {
          "__rl": true,
          "value": "Pacientes",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Registrado": "={{ $now.toISO() }}",
            "Nombre": "={{ $('Datos de la cita').item.json.nombre }}",
            "WhatsApp": "={{ $('Datos de la cita').item.json.telefono }}",
            "Motivo": "={{ $('Datos de la cita').item.json.motivo }}",
            "Urgente": "={{ $('Datos de la cita').item.json.urgente ? 'Sí' : 'No' }}",
            "Cita": "={{ $('Datos de la cita').item.json.inicio }}",
            "Evento": "={{ $json.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Registrado",
              "displayName": "Registrado",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Nombre",
              "displayName": "Nombre",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "WhatsApp",
              "displayName": "WhatsApp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Motivo",
              "displayName": "Motivo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Urgente",
              "displayName": "Urgente",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cita",
              "displayName": "Cita",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Evento",
              "displayName": "Evento",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "77ed09fc-2f76-4487-aba3-bced23506c02",
      "name": "Guarda ficha",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        3780,
        400
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "phoneNumberId": "={{ $('Datos de la cita').item.json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $('Datos de la cita').item.json.telefono }}",
        "textBody": "=¡Listo, {{ $('Datos de la cita').item.json.nombre }}! ✅ Tu cita con la {{ $('Datos de la clínica').first().json.doctora }} quedó para el {{ $('Datos de la cita').item.json.inicioLegible }}. Te mando la ubicación para que llegues sin problema.",
        "additionalFields": {}
      },
      "id": "4a558ef6-50dd-4c90-ad70-4f5d0e5cb526",
      "name": "Confirma la cita",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        3780,
        620
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "phoneNumberId": "={{ $('Datos de la cita').item.json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $('Datos de la cita').item.json.telefono }}",
        "messageType": "location",
        "longitude": "={{ $('Datos de la clínica').first().json.longitud }}",
        "latitude": "={{ $('Datos de la clínica').first().json.latitud }}"
      },
      "id": "4352d00a-1472-441d-a82a-d6d709f10c64",
      "name": "Envía ubicación",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        4000,
        620
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "phoneNumberId": "={{ $('Datos de la cita').item.json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $('Datos de la cita').item.json.telefono }}",
        "textBody": "=Uy, ese horario ya no está disponible 😅 ¿Te propongo otro?",
        "additionalFields": {}
      },
      "id": "2c6b3a96-fb1e-4b1b-a6c5-b3f1a34ad6d9",
      "name": "Horario ocupado",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        3540,
        800
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "f0928d88-8b4c-4caf-ae49-2af5f3c4cda1",
      "name": "Cada mañana 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        1260
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "aab74662-481f-4277-ab6e-9f964d30299f",
              "name": "doctora",
              "value": "Dra. Ruiz",
              "type": "string"
            },
            {
              "id": "a6b014cf-1a17-4bda-a7df-ebb465f03a37",
              "name": "telefonoClinica",
              "value": "5215500000000",
              "type": "string"
            },
            {
              "id": "13ae5727-292a-44a6-a133-2730ca7ce8da",
              "name": "phoneNumberId",
              "value": "TU_PHONE_NUMBER_ID",
              "type": "string"
            },
            {
              "id": "fec8802a-e583-4340-aeab-aac43a6232c5",
              "name": "zonaHoraria",
              "value": "America/Mexico_City",
              "type": "string"
            },
            {
              "id": "88db2248-8681-4d36-ac49-27f3c7e141a2",
              "name": "idiomaPlantillas",
              "value": "es",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "a85af168-eed9-4755-a499-a1f987e27778",
      "name": "Datos de la clínica (mañana)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        1260
      ]
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "sheetName": {
          "__rl": true,
          "value": "Pacientes",
          "mode": "name"
        },
        "filtersUI": {},
        "options": {}
      },
      "id": "d773d29c-4321-472d-a26b-fb8d685ec6d6",
      "name": "Pacientes nuevos",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        460,
        1140
      ]
    },
    {
      "parameters": {
        "jsCode": "// Patients booked in the last 24 hours, as one line (WhatsApp template parameters can't contain line breaks).\nconst cfg = $('Datos de la clínica (mañana)').first().json;\nconst desde = $now.minus({ hours: 24 });\nconst filas = $input.all()\n  .map((i) => i.json)\n  .filter((r) => r.Registrado && DateTime.fromISO(r.Registrado) >= desde)\n  .sort((a, b) => String(a.Cita).localeCompare(String(b.Cita)));\nif (filas.length === 0) return [];\nconst lista = filas\n  .map((r) => {\n    const hora = DateTime.fromISO(r.Cita, { setZone: true }).setZone(cfg.zonaHoraria).setLocale('es').toFormat(\"ccc HH:mm\");\n    return `${hora} ${r.Nombre} (${String(r.Motivo).toLowerCase()}${r.Urgente === 'Sí' ? ', urgencia' : ''})`;\n  })\n  .join(' · ');\nreturn [{ json: { total: String(filas.length), lista } }];"
      },
      "id": "4984e73b-1e42-461f-a6e6-bbafc83b2d54",
      "name": "Arma el resumen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        1140
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "sendTemplate",
        "phoneNumberId": "={{ $('Datos de la clínica (mañana)').first().json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $('Datos de la clínica (mañana)').first().json.telefonoClinica }}",
        "template": "=resumen_diario|{{ $('Datos de la clínica (mañana)').first().json.idiomaPlantillas }}",
        "components": {
          "component": [
            {
              "type": "body",
              "bodyParameters": {
                "parameter": [
                  {
                    "type": "text",
                    "text": "={{ $('Datos de la clínica (mañana)').first().json.doctora }}"
                  },
                  {
                    "type": "text",
                    "text": "={{ $json.total }}"
                  },
                  {
                    "type": "text",
                    "text": "={{ $json.lista }}"
                  }
                ]
              }
            }
          ]
        }
      },
      "id": "db79d2fa-866b-47b9-a483-7b363459a34a",
      "name": "Resumen a la doctora",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        900,
        1140
      ]
    },
    {
      "parameters": {
        "resource": "event",
        "operation": "getAll",
        "calendar": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "returnAll": true,
        "timeMin": "={{ $now.setZone($('Datos de la clínica (mañana)').first().json.zonaHoraria).plus({ days: 1 }).startOf('day').toISO() }}",
        "timeMax": "={{ $now.setZone($('Datos de la clínica (mañana)').first().json.zonaHoraria).plus({ days: 1 }).endOf('day').toISO() }}",
        "options": {
          "orderBy": "startTime"
        }
      },
      "id": "681208a1-5111-47b5-a7c1-a0cd7c2ee7ee",
      "name": "Citas de mañana",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.3,
      "position": [
        460,
        1380
      ]
    },
    {
      "parameters": {
        "jsCode": "// One reminder per appointment booked by the receptionist (it writes \"WhatsApp: +<number>\" in the description).\nconst cfg = $('Datos de la clínica (mañana)').first().json;\nconst out = [];\nfor (const { json: ev } of $input.all()) {\n  const tel = String(ev.description ?? '').match(/WhatsApp:\\s*\\+?(\\d{8,15})/);\n  if (!tel || !ev.start?.dateTime) continue;\n  const nombre = (String(ev.description).match(/Paciente:\\s*(.+)/) ?? [])[1] ?? 'Hola';\n  const hora = DateTime.fromISO(ev.start.dateTime, { setZone: true }).setZone(cfg.zonaHoraria).toFormat('HH:mm');\n  out.push({ json: { telefono: tel[1], nombre: nombre.trim(), hora } });\n}\nreturn out;"
      },
      "id": "eeaeb226-bd97-4ce8-abe5-d44685336410",
      "name": "Prepara recordatorios",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        1380
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "sendTemplate",
        "phoneNumberId": "={{ $('Datos de la clínica (mañana)').first().json.phoneNumberId }}",
        "recipientPhoneNumber": "={{ $json.telefono }}",
        "template": "=recordatorio_cita|{{ $('Datos de la clínica (mañana)').first().json.idiomaPlantillas }}",
        "components": {
          "component": [
            {
              "type": "body",
              "bodyParameters": {
                "parameter": [
                  {
                    "type": "text",
                    "text": "={{ $json.nombre }}"
                  },
                  {
                    "type": "text",
                    "text": "={{ $json.hora }}"
                  },
                  {
                    "type": "text",
                    "text": "={{ $('Datos de la clínica (mañana)').first().json.doctora }}"
                  }
                ]
              }
            }
          ]
        }
      },
      "id": "044f8762-72be-406d-a17d-d615698b6580",
      "name": "Envía recordatorio",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1.1,
      "position": [
        900,
        1380
      ]
    },
    {
      "parameters": {
        "content": "## 1 · Escucha\nCada mensaje de WhatsApp entra aquí. Los audios se transcriben con Whisper; un toque en un botón de horario va directo a reservar.",
        "height": 520,
        "width": 1680,
        "color": 5
      },
      "id": "39d38ab0-9eab-4862-a0c0-4c79a9be97d2",
      "name": "Nota 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        80
      ]
    },
    {
      "parameters": {
        "content": "## 2 · Entiende\nLa Recepcionista IA (Claude) entiende qué necesita la persona, detecta urgencias y revisa la agenda real antes de ofrecer horarios.",
        "height": 740,
        "width": 700,
        "color": 3
      },
      "id": "212e279c-cf54-4be9-a0a7-5567cb9595d8",
      "name": "Nota 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1620,
        80
      ]
    },
    {
      "parameters": {
        "content": "## 3 · Agenda\nResponde por WhatsApp, ofrece horarios con botones y, al elegir uno, crea la cita, guarda la ficha y manda la ubicación. Urgencias y casos especiales avisan a la clínica.",
        "height": 1100,
        "width": 2180,
        "color": 4
      },
      "id": "a849ff6a-1a77-4596-acfd-5b9cf4fd2ab9",
      "name": "Nota 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2340,
        80
      ]
    },
    {
      "parameters": {
        "content": "## 4 · Reporta\nCada mañana a las 08:00: resumen de pacientes nuevos para la doctora y recordatorios para las citas de mañana.",
        "height": 500,
        "width": 1180,
        "color": 6
      },
      "id": "cc19cb1e-019d-4f53-a1d9-d3e350f33bad",
      "name": "Nota 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        1040
      ]
    },
    {
      "parameters": {
        "content": "## Antes de activar\n1. Llena **Datos de la clínica** y **Datos de la clínica (mañana)**.\n2. Credenciales: WhatsApp (API de Cloud de Meta) en los nodos de WhatsApp y en los dos HTTP Request, OpenAI en *Transcribe audio*, Anthropic en *Claude*, Google en Calendar y Sheets.\n3. Elige el calendario de la doctora en *Agenda*, *¿Sigue libre?*, *Crea la cita* y *Citas de mañana*.\n4. Crea una hoja con la pestaña **Pacientes** y las columnas: Registrado, Nombre, WhatsApp, Motivo, Urgente, Cita, Evento.\n5. Crea y aprueba en Meta las plantillas *aviso_clinica*, *resumen_diario* y *recordatorio_cita* (los textos están en la página donde descargaste el flujo).\n6. Publica el flujo (**Publish**): n8n registra solo el webhook en tu app de Meta con la credencial WhatsApp OAuth.",
        "height": 460,
        "width": 1000,
        "color": 7
      },
      "id": "a2679b61-9472-4ae2-a475-73965b165d5c",
      "name": "Nota configuración",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -420
      ]
    },
    {
      "parameters": {
        "jsCode": "// Whisper detects the format from the file extension, and WhatsApp's download has none.\n// Voice notes arrive as OGG; attached audio files can be MP3, M4A, WAV or WEBM.\nconst extensiones = {\n  'audio/ogg': 'ogg', 'audio/opus': 'ogg', 'audio/mpeg': 'mp3', 'audio/mp3': 'mp3',\n  'audio/mp4': 'm4a', 'audio/m4a': 'm4a', 'audio/x-m4a': 'm4a', 'audio/aac': 'm4a',\n  'audio/wav': 'wav', 'audio/x-wav': 'wav', 'audio/webm': 'webm',\n};\nfor (const item of $input.all()) {\n  const audio = item.binary?.data;\n  if (!audio) continue;\n  const tipo = String(audio.mimeType ?? '').split(';')[0].trim().toLowerCase();\n  const ext = extensiones[tipo] ?? 'ogg';\n  audio.fileName = `nota-de-voz.${ext}`;\n  audio.fileExtension = ext;\n}\nreturn $input.all();"
      },
      "id": "ff50d22d-d7f5-45c8-9131-e4d10ca74058",
      "name": "Nombra el audio",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1260,
        200
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "ai",
              "message": "=¡Listo, {{ $('Datos de la cita').item.json.nombre }}! ✅ Tu cita con la {{ $('Datos de la clínica').first().json.doctora }} quedó para el {{ $('Datos de la cita').item.json.inicioLegible }}. Te mando la ubicación para que llegues sin problema."
            }
          ]
        }
      },
      "id": "73279947-d695-4934-a786-e77b794e13df",
      "name": "Anota la cita",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "typeVersion": 1.1,
      "position": [
        4220,
        620
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "ai",
              "message": "=Uy, ese horario ya no está disponible 😅 ¿Te propongo otro?"
            }
          ]
        }
      },
      "id": "643f2bde-4aa6-422a-b704-f5367b46ab38",
      "name": "Anota horario ocupado",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "typeVersion": 1.1,
      "position": [
        3780,
        800
      ]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Datos de la cita').item.json.telefono }}",
        "contextWindowLength": 12
      },
      "id": "ecf8d927-ea77-47ad-a4fa-c0f6c2c49d2a",
      "name": "Memoria (citas)",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        4000,
        1000
      ]
    }
  ],
  "connections": {
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Datos de la clínica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Datos de la clínica": {
      "main": [
        [
          {
            "node": "Lee el mensaje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lee el mensaje": {
      "main": [
        [
          {
            "node": "Tipo de mensaje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tipo de mensaje": {
      "main": [
        [
          {
            "node": "Datos de la cita",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Obtén el audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Recepcionista IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Obtén el audio": {
      "main": [
        [
          {
            "node": "Descarga el audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Descarga el audio": {
      "main": [
        [
          {
            "node": "Nombra el audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe audio": {
      "main": [
        [
          {
            "node": "Recepcionista IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude": {
      "ai_languageModel": [
        [
          {
            "node": "Recepcionista IA",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Memoria": {
      "ai_memory": [
        [
          {
            "node": "Recepcionista IA",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Agenda": {
      "ai_tool": [
        [
          {
            "node": "Recepcionista IA",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Formato de respuesta": {
      "ai_outputParser": [
        [
          {
            "node": "Recepcionista IA",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Recepcionista IA": {
      "main": [
        [
          {
            "node": "Prepara la respuesta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepara la respuesta": {
      "main": [
        [
          {
            "node": "¿Qué hace?",
            "type": "main",
            "index": 0
          },
          {
            "node": "¿Avisar a la clínica?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Qué hace?": {
      "main": [
        [
          {
            "node": "Envía horarios (botones)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Datos de la cita",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Responde",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Avisar a la clínica?": {
      "main": [
        [
          {
            "node": "Avisa a la clínica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Datos de la cita": {
      "main": [
        [
          {
            "node": "¿Sigue libre?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Sigue libre?": {
      "main": [
        [
          {
            "node": "¿Libre?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿Libre?": {
      "main": [
        [
          {
            "node": "Crea la cita",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Horario ocupado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Crea la cita": {
      "main": [
        [
          {
            "node": "Guarda ficha",
            "type": "main",
            "index": 0
          },
          {
            "node": "Confirma la cita",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Confirma la cita": {
      "main": [
        [
          {
            "node": "Envía ubicación",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cada mañana 08:00": {
      "main": [
        [
          {
            "node": "Datos de la clínica (mañana)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Datos de la clínica (mañana)": {
      "main": [
        [
          {
            "node": "Pacientes nuevos",
            "type": "main",
            "index": 0
          },
          {
            "node": "Citas de mañana",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pacientes nuevos": {
      "main": [
        [
          {
            "node": "Arma el resumen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Arma el resumen": {
      "main": [
        [
          {
            "node": "Resumen a la doctora",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Citas de mañana": {
      "main": [
        [
          {
            "node": "Prepara recordatorios",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepara recordatorios": {
      "main": [
        [
          {
            "node": "Envía recordatorio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nombra el audio": {
      "main": [
        [
          {
            "node": "Transcribe audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envía ubicación": {
      "main": [
        [
          {
            "node": "Anota la cita",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Horario ocupado": {
      "main": [
        [
          {
            "node": "Anota horario ocupado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Memoria (citas)": {
      "ai_memory": [
        [
          {
            "node": "Anota la cita",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "Anota horario ocupado",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Mexico_City",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
