{
  "name": "SP \u00b7 30 \u00b7 Primera Visita \u2014 Redirecci\u00f3n Tutor Menor",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "pv-tutor-route",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "sp30pvt-0001",
      "name": "Webhook \u00b7 PV Menor",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": true }"
      },
      "id": "sp30pvt-0002",
      "name": "Responder OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        460,
        500
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.esMenor }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equal"
              }
            }
          ]
        }
      },
      "id": "sp30pvt-0003",
      "name": "\u00bfPaciente menor de edad?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const d=$input.first().json;\nconst fechaStr=d.fechaStr||new Date().toLocaleDateString('es-ES');\nconst msg=`\ud83d\udc76 Hola ${d.nombreTutor||d.nombre}, informaci\u00f3n sobre la primera cita de *${d.nombreMenor||d.nombre}* el *${fechaStr}* a las *${d.horaStr||'--'}h*.\n\nComo tutor/a legal, tu firma ser\u00e1 necesaria en los documentos:\n\ud83d\udccb Cuestionario + LOPD: ${d.linkCuestionario||'(pendiente)'}\n\nEl d\u00eda de la cita trae tambi\u00e9n el *libro de familia o DNI del menor*.\n\n\ud83d\udcde \u00bfDudas? ${$vars.CLINICA_TELEFONO}`;\nreturn [{ json: { ...d, mensajeTutor: msg, telefonoDestino: d.telefonoTutor||d.telefono } }];"
      },
      "id": "sp30pvt-0004",
      "name": "Preparar mensaje tutor",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        220
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.EVOLUTION_URL }}/message/sendText/{{ $vars.EVOLUTION_INSTANCE }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $vars.EVOLUTION_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"number\": \"34{{ $json.telefonoDestino.replace(/[^0-9]/g,'').replace(/^34/,'') }}@s.whatsapp.net\",\n  \"text\": \"{{ $json.mensajeTutor }}\"\n}"
      },
      "id": "sp30pvt-0005",
      "name": "WhatsApp \u00b7 Tutor legal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        900,
        220
      ]
    }
  ],
  "connections": {
    "Webhook \u00b7 PV Menor": {
      "main": [
        [
          {
            "node": "\u00bfPaciente menor de edad?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Responder OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00bfPaciente menor de edad?": {
      "main": [
        [
          {
            "node": "Preparar mensaje tutor",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Preparar mensaje tutor": {
      "main": [
        [
          {
            "node": "WhatsApp \u00b7 Tutor legal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "id": "sp-pv-tutor-route-030"
}