AutomationFlowsSlack & Telegram › Worflow

Worflow

Worflow. Uses whatsAppTrigger, httpRequest, whatsApp. Event-driven trigger; 94 nodes.

Event trigger★★★★★ complexity94 nodesWhatsApp TriggerHTTP RequestWhatsApp
Slack & Telegram Trigger: Event Nodes: 94 Complexity: ★★★★★ Added:

This workflow follows the HTTP Request → WhatsApp recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "messages"
        ],
        "options": {
          "messageStatusUpdates": []
        }
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        -3824,
        -3424
      ],
      "id": "963b20e2-f1b8-4551-a97b-4e8e087252d7",
      "name": "WhatsApp Trigger1",
      "credentials": {
        "whatsAppTriggerApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/verificar-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2)  } }}",
        "options": {}
      },
      "id": "0afb9b2a-a65b-4065-96ff-71fdcd9e8aaa",
      "name": "Verificar Usuario1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -3152,
        -2256
      ]
    },
    {
      "parameters": {
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "5ad62972-8ce1-4186-a12f-14e0b4febebb",
      "name": "Consultar Estado Usuario",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -3600,
        -3424
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.exists }}",
              "value2": true
            }
          ]
        }
      },
      "id": "479b948c-4411-4a1a-875d-95827c9c966d",
      "name": "\u00bfUsuario Existe?1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2928,
        -2256
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.exists }}",
              "value2": true
            }
          ]
        }
      },
      "id": "1f469e95-5c63-4488-abe0-666989fdc2af",
      "name": "\u00bfTiene Estado Activo?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -3376,
        -3424
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $('WhatsApp Trigger1').item.json.messages[0].text.body.trim().toLowerCase() }}",
        "rules": {
          "rules": [
            {
              "operation": "=contains",
              "value2": "menu"
            }
          ]
        },
        "fallbackOutput": 1
      },
      "id": "784ae0c5-0a99-48bc-8ff8-314c534d3970",
      "name": "\u00bfEs Comando MENU?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -3152,
        -3680
      ]
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "147985a5-75eb-4520-b3df-f483f66a32d1",
      "name": "Limpiar Estado (MENU)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2704,
        -2608
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $json.estado.estado }}",
        "rules": {
          "rules": [
            {
              "value2": "esperando_cedula"
            },
            {
              "value2": "esperando_reporte",
              "output": 1
            },
            {
              "value2": "esperando_cedula_editar",
              "output": 2
            },
            {
              "value2": "esperando_edicion_reporte",
              "output": 3
            },
            {
              "value2": "esperando_datos_usuario",
              "output": 3
            },
            {
              "value2": "esperando_celular_bloquear",
              "output": 3
            }
          ]
        },
        "fallbackOutput": 3
      },
      "id": "642a1c56-fa7e-4f4b-89fe-348302230089",
      "name": "Router por Estado",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -2928,
        -4400
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $json.estado.estado }}",
        "rules": {
          "rules": [
            {
              "value2": "esperando_edicion_reporte"
            },
            {
              "value2": "esperando_datos_usuario",
              "output": 1
            },
            {
              "value2": "esperando_celular_bloquear",
              "output": 2
            }
          ]
        },
        "fallbackOutput": 0
      },
      "id": "6ad6bb5a-4b96-42a2-a043-a87f042ee48d",
      "name": "Switch Estados Adicionales",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -2704,
        -3344
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Esta es una red privada que solo funciona por invitaci\u00f3n.",
        "additionalFields": {}
      },
      "id": "86a5a534-4d96-4289-b0fa-f0b04eae971a",
      "name": "Enviar: Sin Acceso1",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2704,
        -2064
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Extraer el texto del mensaje y el n\u00famero de celular\nconst mensaje = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id || '';\n\n// Extraer solo el primer n\u00famero del mensaje si es una opci\u00f3n\nconst opcion = mensaje.trim().match(/^\\d+/)?.[0] || mensaje.trim();\n\nreturn {\n  json: {\n    opcion: opcion,\n    celular: celular,\n    mensajeCompleto: mensaje\n  }\n};"
      },
      "id": "d8fa84f6-4bfc-412a-a01d-15a2ddda5d0f",
      "name": "Limpiar Entrada1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2480,
        -1984
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{  $('WhatsApp Trigger1').item.json.messages[0].text.body}}",
        "rules": {
          "rules": [
            {
              "operation": "regex",
              "value2": "^[1-6]$"
            }
          ]
        },
        "fallbackOutput": 1
      },
      "id": "b4fd7fd0-7ce5-4ad9-bc06-40e59da0256b",
      "name": "Clasificador Principal1",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -2704,
        -2320
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $json.opcion }}",
        "rules": {
          "rules": [
            {
              "value2": "1"
            },
            {
              "value2": "2",
              "output": 1
            },
            {
              "value2": "3",
              "output": 2
            },
            {
              "value2": "4",
              "output": 3
            },
            {
              "value2": "5",
              "output": 3
            },
            {
              "value2": "6",
              "output": 3
            }
          ]
        },
        "fallbackOutput": 3
      },
      "id": "bd8bbad8-01cf-434a-a1d3-31374c2b292c",
      "name": "Router de Men\u00fa1",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -2256,
        -2016
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ $json.opcion }}",
        "rules": {
          "rules": [
            {
              "value2": "4"
            },
            {
              "value2": "5",
              "output": 1
            },
            {
              "value2": "6",
              "output": 2
            }
          ]
        },
        "fallbackOutput": 0
      },
      "id": "b7ee6a6a-ef5e-4e45-adab-fa3fe7cf6d80",
      "name": "Switch Opciones 4-5-6",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        -2032,
        -1552
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_cedula\", \"opcion\": 1 } }}",
        "options": {}
      },
      "id": "238ea952-7316-4874-aa1b-8d97dcf651db",
      "name": "Guardar Estado: Esperando C\u00e9dula",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -2448
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Has elegido la opci\u00f3n 1: **\ud83d\ude95 Consultar conductor**.\n\nPor favor, env\u00eda la c\u00e9dula del conductor que deseas consultar (solo n\u00fameros, sin puntos ni comas).\n\n**Ejemplo:** 1042458045\n\n_Se mostrar\u00e1n todos los reportes asociados a esa c\u00e9dula._",
        "additionalFields": {}
      },
      "id": "acf031dc-e9d6-46e0-b932-1c13bfa950ac",
      "name": "Pedir C\u00e9dula (Consulta)1",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1808,
        -2448
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_reporte\", \"opcion\": 2 } }}",
        "options": {}
      },
      "id": "676967a7-24ad-4cb8-b38e-ca7ec21e5ad1",
      "name": "Guardar Estado: Esperando Reporte",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -2256
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Has elegido la opci\u00f3n 2: **\ud83d\udcdd Reportar conductor**.\n\nPor favor, env\u00eda en tu pr\u00f3ximo mensaje los datos del reporte en el siguiente formato, *separados por coma*:\n\n`C\u00e9dula, Nombres, Apellidos, Placa, Empresa, Descripci\u00f3n, Valor`\n\n**Ejemplo:**\n`1042458045,Gohan,Rodr\u00edguez,ABC123,GohanSas,Conducci\u00f3n peligrosa,600000`",
        "additionalFields": {}
      },
      "id": "0eb98542-25f1-487b-bbf2-3ab305c41759",
      "name": "Pedir Datos Reporte1",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1808,
        -2256
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_cedula_editar\", \"opcion\": 3 } }}",
        "options": {}
      },
      "id": "2ce70d4b-696e-4523-a3fa-db1baecfc7e5",
      "name": "Guardar Estado: Esperando ID Reporte",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -1888
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Has elegido la opci\u00f3n 3: **\u270f\ufe0f Editar mis reportes**.\n\nPor favor, env\u00eda la c\u00e9dula del taxista cuyos reportes quieres editar.\n\n**Ejemplo:** 1042458045\n\n_Nota: Solo ver\u00e1s los reportes que t\u00fa hayas creado._",
        "additionalFields": {}
      },
      "id": "a81846c5-938b-4787-84d1-287fecb4a958",
      "name": "Pedir C\u00e9dula (Editar)",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1808,
        -1888
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Extraer c\u00e9dula del mensaje\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\nconst cedula = rawMessage.trim().replace(/[^0-9]/g, '');\n\n// Validar que sea un n\u00famero de 5 a 11 d\u00edgitos\nif (cedula.length < 5 || cedula.length > 11) {\n  return { \n    json: { \n      success: false, \n      esCedulaValida: false,\n      celular: celular,\n      mensaje: '\u274c Error: La c\u00e9dula debe tener entre 5 y 11 d\u00edgitos.\\n\\nEjemplo: 1042458045' \n    } \n  };\n}\n\nreturn {\n  json: {\n    success: true,\n    esCedulaValida: true,\n    cedula: cedula,\n    celular: celular\n  }\n};\n"
      },
      "id": "04b9a3f7-d5c2-40df-8ada-f87110ee104f",
      "name": "Validar C\u00e9dula (Editar)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2704,
        -4080
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esCedulaValida }}",
              "value2": true
            }
          ]
        }
      },
      "id": "2729e2b9-9f4e-4f39-9573-a3322fd59850",
      "name": "\u00bfC\u00e9dula V\u00e1lida? (Editar)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2480,
        -4080
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "2677fb4b-8859-42bf-a64e-8ec67399b1ce",
      "name": "Resp: C\u00e9dula Inv\u00e1lida (Editar)",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2256,
        -3984
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "737f3403-58af-4709-b4dd-6878456dd18b",
      "name": "Limpiar Estado (C\u00e9dula Inv\u00e1lida Editar)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -3984
      ]
    },
    {
      "parameters": {
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/mis-reportes/{{ $json.cedula }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-User-Celular",
              "value": "={{ $json.celular }}"
            }
          ]
        },
        "options": {}
      },
      "id": "5da3c552-7c56-4622-a0df-ae9c64ecfa49",
      "name": "API: Consultar Mis Reportes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2256,
        -4176
      ]
    },
    {
      "parameters": {
        "jsCode": "// Obtener la respuesta del endpoint\nconst data = $input.first().json;\nconst found = data.found;\nconst reportes = data.reportes || [];\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id;\n\nlet mensaje = `\ud83d\udccb *Tus Reportes para Editar*\\n\\n`;\n\nif (!found || reportes.length === 0) {\n  mensaje += `\u274c No tienes reportes creados para esta c\u00e9dula.\\n\\n`;\n  mensaje += `_Usa la opci\u00f3n 2 del men\u00fa para crear nuevos reportes._`;\n  return {\n    json: {\n      mensaje,\n      celular,\n      hayReportes: false\n    }\n  };\n}\n\nconst persona = reportes[0];\nmensaje += `\ud83d\udc64 *Nombre:* ${persona.nombres || 'N/A'} ${persona.apellidos || 'N/A'}\\n`;\nmensaje += `\ud83c\udd94 *C\u00e9dula:* ${persona.numero_documento || 'N/A'}\\n`;\nmensaje += `\ud83d\ude96 *Placa:* ${persona.placa || 'N/A'}\\n\\n`;\nmensaje += `\u26a0\ufe0f *Total de Reportes Tuyos:* ${reportes.length}\\n\\n`;\n\nreportes.forEach((reporte, index) => {\n  mensaje += `\ud83d\udcdd *Reporte #${index + 1}* (ID: ${reporte.id})\\n`;\n  mensaje += `   Nombres: ${reporte.nombres || 'N/A'}\\n`;\n  mensaje += `   Apellidos: ${reporte.apellidos || 'N/A'}\\n`;\n  mensaje += `   Placa: ${reporte.placa || 'N/A'}\\n`;\n  mensaje += `   Estado: ${reporte.estado || 'N/A'}\\n`;\n  mensaje += `   Descripci\u00f3n: ${reporte.descripcion || 'N/A'}\\n`;\n  mensaje += `   Valor: $${reporte.valor_reporte || 0}\\n`;\n  mensaje += `   Fecha: ${reporte.fecha_reporte || 'N/A'}\\n\\n`;\n});\n\n// Generar array de formatos individuales (uno por cada reporte)\nconst formatos = reportes.map((reporte, index) => {\n  const formatoEdicion = `${reporte.id},${reporte.nombres || ''},${reporte.apellidos || ''},${reporte.placa || ''},${reporte.valor_reporte || ''},${reporte.descripcion || ''},${reporte.estado || ''}`;\n  return {\n    celular,\n    formatoTexto: formatoEdicion,\n    numeroReporte: index + 1\n  };\n});\n\nreturn [\n  {\n    json: {\n      mensaje,\n      celular,\n      hayReportes: true,\n      formatos  // Guardamos los formatos para uso posterior\n    }\n  },\n  ...formatos.map(f => ({ json: f }))  // Retornamos cada formato como un item separado\n];\n"
      },
      "id": "eb189b75-79ea-4131-9364-7eea69ca23be",
      "name": "Formatear Reportes para Editar",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2032,
        -4176
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.hayReportes }}",
              "value2": true
            }
          ]
        }
      },
      "id": "279d1f2b-f921-4fdf-8674-647d9aabbac0",
      "name": "\u00bfTiene Reportes? (Editar)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1808,
        -4176
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $json.celular }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "edf0f929-7d83-41d8-9afa-f1f6de7ab83d",
      "name": "Enviar: Reportes para Editar",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -4272
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.formatoTexto }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "ff4fa325-a8f1-47b3-81d1-2229db67e493",
      "name": "Filtrar Solo Formatos",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1360,
        -4272
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $json.celular }}",
        "textBody": "={{ $json.formatoTexto }}",
        "additionalFields": {}
      },
      "id": "4dac4cf9-2899-4750-8044-1fcb283a4e4e",
      "name": "Enviar: Formatos para Copiar",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1136,
        -4344
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_edicion_reporte\", \"opcion\": 3 } }}",
        "options": {}
      },
      "id": "894411a6-1406-48d3-b770-f22922867a1b",
      "name": "Guardar Estado: Esperando Edici\u00f3n Reporte",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -912,
        -4272
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $json.celular }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "651ee9d3-0f41-4537-9753-e338544b0ec2",
      "name": "Enviar: Sin Reportes para Editar",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -4080
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "ebfc0de7-f2ce-4281-bee1-5f9cd856d035",
      "name": "Limpiar Estado (Sin Reportes Editar)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1360,
        -4080
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_datos_usuario\", \"opcion\": 5 } }}",
        "options": {}
      },
      "id": "20ab8ca1-3909-480f-ae4a-9d341b1223f5",
      "name": "Guardar Estado: Esperando Datos Usuario",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1808,
        -1504
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Has elegido la opci\u00f3n 5: **\ud83d\udc64 Crear usuario nuevo**.\n\nPor favor, env\u00eda en tu pr\u00f3ximo mensaje los datos del usuario en el siguiente formato, *separados por coma*:\n\n`Email, Nombre Completo, Celular`\n\n**Ejemplo:**\n`usuario@ejemplo.com,Juan P\u00e9rez,3001234567`\n\n\u2139\ufe0f La contrase\u00f1a por defecto ser\u00e1: **SAC123***",
        "additionalFields": {}
      },
      "id": "9cd9472e-a5da-410c-8754-5d39b4b0408b",
      "name": "Pedir Datos Usuario",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -1504
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $('WhatsApp Trigger1').item.json.contacts[0].wa_id.substring(2), \"estado\": \"esperando_celular_bloquear\", \"opcion\": 6 } }}",
        "options": {}
      },
      "id": "9a1b1e4e-b45d-4b1d-b572-8933dc380759",
      "name": "Guardar Estado: Esperando Celular Bloquear",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1808,
        -1312
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Has elegido la opci\u00f3n 6: **\ud83d\udeab Bloquear usuario**.\n\nPor favor, env\u00eda en tu pr\u00f3ximo mensaje el n\u00famero de celular del usuario que deseas bloquear (solo n\u00fameros).\n\n**Ejemplo:**\n`3001234567`",
        "additionalFields": {}
      },
      "id": "5d2242ce-1d99-45ef-ae3c-9223950bd365",
      "name": "Pedir Celular para Bloquear",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -1312
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Extraer la c\u00e9dula del mensaje\nconst mensaje = $('WhatsApp Trigger1').first().json.messages?.[0]?.text?.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts?.[0]?.wa_id.substring(2) || '';\n\n// Limpiar la c\u00e9dula (solo n\u00fameros)\nconst cedula = mensaje.replace(/\\D/g, '');\n\n// Validar que la c\u00e9dula tenga entre 5 y 11 d\u00edgitos\nconst esValida = cedula.length >= 5 && cedula.length <= 11;\n\nreturn {\n  json: {\n    cedula: cedula,\n    celular: celular,\n    esValida: esValida,\n    mensaje: esValida ? '' : '\u274c Error: La c\u00e9dula debe contener entre 5 y 11 d\u00edgitos. Por favor, env\u00eda una c\u00e9dula v\u00e1lida.\\n\\nEjemplo: 1042458045'\n  }\n};"
      },
      "id": "fc5d50d5-de95-40d3-80ae-8fefda48e865",
      "name": "Extraer C\u00e9dula (Consulta)1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2704,
        -5040
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esValida }}",
              "value2": true
            }
          ]
        }
      },
      "id": "35b2f4c2-2056-41f2-bf89-838be5090004",
      "name": "\u00bfC\u00e9dula V\u00e1lida?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2480,
        -5040
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "72422e7c-e0ca-4fa5-9e09-36c998a77cd8",
      "name": "Resp: C\u00e9dula Inv\u00e1lida",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2256,
        -5136
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "2db5608f-ed03-4ab5-89f0-a04affbfc657",
      "name": "Limpiar Estado (C\u00e9dula Inv\u00e1lida)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -5136
      ]
    },
    {
      "parameters": {
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/reportes-por-cedula/{{ $json.cedula }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-User-Celular",
              "value": "={{ $json.celular }}"
            }
          ]
        },
        "options": {}
      },
      "id": "4fc1f944-d55f-4493-acc2-8d50bef86825",
      "name": "API: Consultar Persona1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2256,
        -4944
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.found }}",
              "value2": true
            }
          ]
        }
      },
      "id": "aa122eac-26de-489a-b2ce-52a38fab1447",
      "name": "\u00bfTiene Reportes?1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2032,
        -4944
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "C\u00e9dula no reportada en nuestra base de datos.",
        "additionalFields": {}
      },
      "id": "d86a790d-e0d9-4b95-a7b0-6e42058d5e6b",
      "name": "Resp: Sin Reportes1",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1808,
        -4848
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Obtener la respuesta del endpoint (es un array)\nconst data = $input.first().json;\n\n// Datos generales\nconst found = data.found;\nconst reportes = data.reportes || [];\n\n// Tomar el celular desde el nodo \"WhatsApp Trigger1\"\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id;\n\n// Formateo de mensaje\nlet mensaje = `\ud83d\udccb *Reportes del Conductor*\\n\\n`;\n\nif (!found || reportes.length === 0) {\n  mensaje += `\u274c No se encontraron reportes para esta c\u00e9dula.\\n`;\n  return {\n    json: {\n      mensaje,\n      celular\n    }\n  };\n}\n\n// Tomar datos del primer reporte para mostrar info general\nconst persona = reportes[0];\n\nmensaje += `\ud83d\udc64 *Nombre:* ${persona.nombres || 'N/A'} ${persona.apellidos || 'N/A'}\\n`;\nmensaje += `\ud83c\udd94 *C\u00e9dula:* ${persona.numero_documento || 'N/A'}\\n`;\nmensaje += `\ud83d\ude96 *Placa:* ${persona.placa || 'N/A'}\\n\\n`;\nmensaje += `\u26a0\ufe0f *Total de Reportes:* ${reportes.length}\\n\\n`;\n\nreportes.forEach((reporte, index) => {\n  mensaje += `\ud83d\udcdd *Reporte #${index + 1}* (ID: ${reporte.id})\\n`;\n  mensaje += `   Nombres: ${reporte.nombres || 'N/A'}\\n`;\n  mensaje += `   Apellidos: ${reporte.apellidos || 'N/A'}\\n`;\n  mensaje += `   Placa: ${reporte.placa || 'N/A'}\\n`;\n  mensaje += `   Estado: ${reporte.estado || 'N/A'}\\n`;\n  mensaje += `   Descripci\u00f3n: ${reporte.descripcion || 'N/A'}\\n`;\n  mensaje += `   Valor: $${reporte.valor_reporte || 0}\\n`;\n  mensaje += `   Fecha: ${reporte.fecha_reporte || 'N/A'}\\n\\n`;\n});\n\nreturn {\n  json: {\n    mensaje,\n    celular\n  }\n};\n"
      },
      "id": "08fc343f-eed9-4711-8af2-e5d94331422b",
      "name": "Formatear Mensaje (Consulta)1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1808,
        -5040
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $json.celular }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "c0f1af9a-8a52-4b9d-908a-1247ad40026e",
      "name": "Resp: Enviar Reportes (Consulta)1",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -5040
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "4e6b4f9b-96b3-4036-94c8-55f2f5b198f2",
      "name": "Limpiar Estado Usuario (Consulta)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1360,
        -5040
      ]
    },
    {
      "parameters": {
        "jsCode": "// Obtener el mensaje completo del usuario\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\nconst parts = rawMessage.split(',').map(p => p.trim());\n\n// Soportar 6 o 7 campos\nif (parts.length < 6) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El formato del mensaje es incorrecto. Deben ser m\u00ednimo 6 campos separados por comas.\\n\\nFormato: C\u00e9dula,Nombres,Apellidos,Placa,Empresa,Descripci\u00f3n,Valor\\n\\nEjemplo:\\n1042458045,Gohan,Rodr\u00edguez,ABC123,GohanSas,Conducci\u00f3n peligrosa,600000' \n    } \n  };\n}\n\n// Si son 6 campos, asumimos que no hay valor reportado\nlet numero_documento, nombres, apellidos, placa, vehiculo_afiliado, descripcion, valor_reporte_raw;\n\nif (parts.length === 6) {\n  [numero_documento, nombres, apellidos, placa, vehiculo_afiliado, descripcion] = parts;\n  valor_reporte_raw = '0';\n} else if (parts.length === 7) {\n  [numero_documento, nombres, apellidos, placa, vehiculo_afiliado, descripcion, valor_reporte_raw] = parts;\n} else {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: Demasiados campos. M\u00e1ximo 7 campos.\\n\\nFormato: C\u00e9dula,Nombres,Apellidos,Placa,Empresa,Descripci\u00f3n,Valor' \n    } \n  };\n}\n\n// Limpieza y Formateo de datos\nconst valor_reporte = parseInt(valor_reporte_raw.replace(/[^0-9]/g, ''), 10) || 0;\nconst estado = \"ACTIVA\";\n\nconst reportData = {\n  numero_documento: numero_documento.replace(/\\D/g, ''),\n  nombres: nombres.toUpperCase(),\n  apellidos: apellidos.toUpperCase(),\n  placa: placa.toUpperCase().replace(/\\s/g, ''),\n  vehiculo_afiliado: vehiculo_afiliado.toUpperCase(),\n  descripcion: descripcion,\n  valor_reporte: valor_reporte,\n  estado: estado\n};\n\nconst confirmationMessage = `\u2705 **Validaci\u00f3n Exitosa. Datos a Registrar:**\\n- C\u00e9dula: ${reportData.numero_documento}\\n- Nombres: ${reportData.nombres} ${reportData.apellidos}\\n- Placa: ${reportData.placa}\\n- Empresa: ${reportData.vehiculo_afiliado}\\n- Descripci\u00f3n: ${reportData.descripcion}\\n- Valor: $${reportData.valor_reporte.toLocaleString('es-CO')}\\n\\n*Procediendo a registrar el reporte...*`;\n\nreturn {\n  json: {\n    success: true,\n    esFormatoValido: true,\n    reportData: reportData,\n    celular: celular,\n    confirmationMessage: confirmationMessage\n  }\n};\n"
      },
      "id": "7601b315-82a4-4276-88b4-c7248df7648e",
      "name": "Extraer y Formatear Reporte1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2704,
        -4656
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esFormatoValido }}",
              "value2": true
            }
          ]
        }
      },
      "id": "399d008b-5972-4cf6-929c-e224d2056e19",
      "name": "\u00bfFormato V\u00e1lido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2480,
        -4656
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "54f71487-0d43-44fe-a825-e6331572615a",
      "name": "Resp: Formato Inv\u00e1lido",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2256,
        -4752
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "70095dbc-b170-4261-984c-7228b7569a7f",
      "name": "Limpiar Estado (Formato Inv\u00e1lido)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -4752
      ]
    },
    {
      "parameters": {
        "jsCode": "// Obtener el mensaje completo del usuario\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\nconst parts = rawMessage.split(',').map(p => p.trim());\n\n// Validar que tenga 3 campos\nif (parts.length !== 3) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El formato del mensaje es incorrecto. Deben ser 3 campos separados por comas.\\n\\nFormato: Email,Nombre,Celular\\n\\nEjemplo:\\nusuario@ejemplo.com,Juan P\u00e9rez,3001234567' \n    } \n  };\n}\n\nconst [username, nombres, celularUsuario] = parts;\n\n// Validar email b\u00e1sico\nconst emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nif (!emailRegex.test(username)) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El email no es v\u00e1lido. Por favor usa un formato correcto (ejemplo: usuario@ejemplo.com)' \n    } \n  };\n}\n\n// Validar celular (10 d\u00edgitos)\nconst celularLimpio = celularUsuario.replace(/\\D/g, '');\nif (celularLimpio.length !== 10) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El celular debe tener 10 d\u00edgitos. Ejemplo: 3001234567' \n    } \n  };\n}\n\n// Contrase\u00f1a por defecto\nconst password = 'SAC123*';\n\nconst userData = {\n  username: username.toLowerCase(),\n  nombres: nombres,\n  celular: celularLimpio,\n  password: password\n};\n\nreturn {\n  json: {\n    success: true,\n    esFormatoValido: true,\n    userData: userData,\n    celular: celular\n  }\n};\n"
      },
      "id": "9d0cf024-0443-42bf-824f-870c13905c39",
      "name": "Extraer y Validar Datos Usuario",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2480,
        -3312
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esFormatoValido }}",
              "value2": true
            }
          ]
        }
      },
      "id": "0f1e1378-7b9c-4926-a2bc-4c3c3e9f2425",
      "name": "\u00bfDatos Usuario V\u00e1lidos?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2256,
        -3312
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "05a8ad33-334f-418d-a538-38ee225e197e",
      "name": "Resp: Datos Usuario Inv\u00e1lidos",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2032,
        -3408
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "56d29c4f-c6e4-4bdb-8bb4-ca1b51408b7e",
      "name": "Limpiar Estado (Datos Usuario Inv\u00e1lidos)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1808,
        -3408
      ]
    },
    {
      "parameters": {
        "jsCode": "// Obtener el ID del reporte\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\nconst idReporte = rawMessage.trim();\n\n// Validar que sea un n\u00famero\nif (!/^\\d+$/.test(idReporte)) {\n  return { \n    json: { \n      success: false, \n      esIdValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El ID del reporte debe ser un n\u00famero.\\n\\nEjemplo: 123' \n    } \n  };\n}\n\nreturn {\n  json: {\n    success: true,\n    esIdValido: true,\n    idReporte: idReporte,\n    celular: celular\n  }\n};\n"
      },
      "id": "2672c9f4-70de-45c7-939f-97f24f39d511",
      "name": "Validar ID Reporte",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -3824,
        -1088
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esIdValido }}",
              "value2": true
            }
          ]
        }
      },
      "id": "900003a8-ff22-4580-afa4-ed0f12dcbec0",
      "name": "\u00bfID V\u00e1lido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -3824,
        -864
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "fe1b655b-6d27-429d-b3ab-0373f8658f7b",
      "name": "Resp: ID Inv\u00e1lido",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -3824,
        -192
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "e316f9a3-6d60-458e-8ff9-c55c5b2cf588",
      "name": "Limpiar Estado (ID Inv\u00e1lido)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -3824,
        32
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { \"celular\": $json.celular, \"estado\": \"esperando_edicion_reporte\", \"opcion\": 3, \"id_reporte\": $json.idReporte } }}",
        "options": {}
      },
      "id": "8324c0b8-f134-441a-887b-26357a54b2f7",
      "name": "Guardar Estado: Esperando Edici\u00f3n",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -3824,
        -640
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "Perfecto. Ahora env\u00eda los nuevos datos del reporte en el siguiente formato (puedes dejar campos vac\u00edos si no quieres modificarlos, pero respeta las comas):\\n\\n`Nombres,Apellidos,Placa,Valor,Descripci\u00f3n,Estado`\\n\\n**Ejemplo:**\\n`Juan,P\u00e9rez,ABC123,500000,Conducci\u00f3n peligrosa,ACTIVA`\\n\\n_Campos vac\u00edos:_\\n`,,,,,` (solo comas)",
        "additionalFields": {}
      },
      "id": "bb561357-768d-4782-8b9e-df5be7e3e21e",
      "name": "Pedir Datos Edici\u00f3n",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -3824,
        -416
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Obtener los datos de edici\u00f3n con ID\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\nconst parts = rawMessage.split(',').map(p => p.trim());\n\n// Debe tener 7 campos (ID + 6 datos)\nif (parts.length !== 7) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El formato debe tener 7 campos separados por comas.\\n\\nFormato: ID,Nombres,Apellidos,Placa,Valor,Descripci\u00f3n,Estado\\n\\nEjemplo:\\n123,Juan,P\u00e9rez,ABC123,500000,Conducci\u00f3n peligrosa,ACTIVA\\n\\nSi no quieres modificar un campo (excepto ID), d\u00e9jalo vac\u00edo pero respeta las comas.' \n    } \n  };\n}\n\nconst [idReporte, nombres, apellidos, placa, valor, descripcion, estadoReporte] = parts;\n\n// Validar que el ID sea un n\u00famero\nif (!/^\\d+$/.test(idReporte)) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El ID del reporte debe ser un n\u00famero.\\n\\nEjemplo: 123,Juan,P\u00e9rez,ABC123,500000,Conducci\u00f3n peligrosa,ACTIVA' \n    } \n  };\n}\n\n// Construir objeto con solo los campos que no est\u00e1n vac\u00edos\nconst datosEdicion = {};\n\nif (nombres) datosEdicion.nombres = nombres;\nif (apellidos) datosEdicion.apellidos = apellidos;\nif (placa) datosEdicion.placa = placa;\nif (valor) {\n  const valorNum = parseInt(valor.replace(/\\D/g, ''));\n  if (!isNaN(valorNum)) datosEdicion.valor_reporte = valorNum;\n}\nif (descripcion) datosEdicion.descripcion_reporte = descripcion;\nif (estadoReporte) datosEdicion.estado = estadoReporte;\n\n// Validar que al menos un campo se va a editar\nif (Object.keys(datosEdicion).length === 0) {\n  return { \n    json: { \n      success: false, \n      esFormatoValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: Debes proporcionar al menos un campo para editar (despu\u00e9s del ID).' \n    } \n  };\n}\n\nreturn {\n  json: {\n    success: true,\n    esFormatoValido: true,\n    datosEdicion: datosEdicion,\n    idReporte: idReporte,\n    celular: celular\n  }\n};\n"
      },
      "id": "826cd3f6-de36-4e1c-965e-052894853691",
      "name": "Procesar Datos Edici\u00f3n",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2480,
        -3696
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esFormatoValido }}",
              "value2": true
            }
          ]
        }
      },
      "id": "1a31f18c-7197-4cf1-9395-5169169e7025",
      "name": "\u00bfFormato Edici\u00f3n V\u00e1lido?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2256,
        -3696
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "566415b8-937d-46af-8eba-fc52cd93d289",
      "name": "Resp: Formato Edici\u00f3n Inv\u00e1lido",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2032,
        -3600
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "aee37ea5-eb91-4cf8-9e41-bc22e5e57cb2",
      "name": "Limpiar Estado (Formato Edici\u00f3n Inv\u00e1lido)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1808,
        -3600
      ]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/personas/{{ $json.idReporte }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-User-Celular",
              "value": "={{ $json.celular }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.datosEdicion }}",
        "options": {}
      },
      "id": "c1a30d23-d910-478d-a605-b7c9bf993e5e",
      "name": "API: Editar Reporte",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -3792
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "id": "96e015f0-b36b-42c8-8f73-779cf547c703",
      "name": "\u00bfEdici\u00f3n Exitosa?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1808,
        -3792
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u2705 Reporte editado exitosamente.",
        "additionalFields": {}
      },
      "id": "2b81efc5-5101-406f-9ecb-c246ab347103",
      "name": "Resp: Edici\u00f3n Exitosa",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -3888
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u274c Error al editar el reporte: {{ $json.message || 'No tienes permisos para editar este reporte o no existe.' }}",
        "additionalFields": {}
      },
      "id": "f16ef3d2-76d2-40a6-a580-42cfa6ea18e0",
      "name": "Resp: Error Edici\u00f3n",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -3600
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "81c39b1a-845e-45db-9d47-e0dbd9d9b424",
      "name": "Limpiar Estado (Edici\u00f3n)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1360,
        -3792
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/usuarios",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.userData }}",
        "options": {}
      },
      "id": "cdfbfa4c-9e9b-4754-9a5f-d86e142fcf42",
      "name": "API: Crear Usuario",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -3216
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "id": "c0fbb0bf-eb45-493b-ad31-c1291a33e656",
      "name": "\u00bfUsuario Creado?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1808,
        -3216
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u2705 \u00a1Usuario creado exitosamente!\n\nEl nuevo usuario ya puede acceder al sistema.",
        "additionalFields": {}
      },
      "id": "be45539b-9ce1-44df-b78f-fae7a26ad6d7",
      "name": "Resp: Usuario Creado",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -3408
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u274c Error al crear usuario: {{ $json.message || 'Error desconocido' }}",
        "additionalFields": {}
      },
      "id": "418ec5d3-a65e-476e-b704-34d77b0df823",
      "name": "Resp: Error Crear Usuario",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -3120
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "56db940c-a1c3-435a-86d0-f92e448e086f",
      "name": "Limpiar Estado (Crear Usuario)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1360,
        -3216
      ]
    },
    {
      "parameters": {
        "jsCode": "// Obtener el celular a bloquear\nconst rawMessage = $('WhatsApp Trigger1').first().json.messages[0].text.body || '';\nconst celular = $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) || '';\n\n// Limpiar el celular (solo n\u00fameros)\nconst celularBloquear = rawMessage.replace(/\\D/g, '');\n\n// Validar que tenga 10 d\u00edgitos\nif (celularBloquear.length !== 10) {\n  return { \n    json: { \n      success: false, \n      esValido: false,\n      celular: celular,\n      mensaje: '\u274c Error: El celular debe tener 10 d\u00edgitos.\\n\\nEjemplo: 3001234567' \n    } \n  };\n}\n\nreturn {\n  json: {\n    success: true,\n    esValido: true,\n    celularBloquear: celularBloquear,\n    celular: celular\n  }\n};\n"
      },
      "id": "037ce258-43a7-4195-9a20-2145f0ff21fe",
      "name": "Extraer y Validar Celular Bloquear",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2480,
        -2736
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.esValido }}",
              "value2": true
            }
          ]
        }
      },
      "id": "bb134b2e-5087-4fb8-9d39-2865c9b35135",
      "name": "\u00bfCelular V\u00e1lido para Bloquear?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -2256,
        -2736
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "={{ $json.mensaje }}",
        "additionalFields": {}
      },
      "id": "e8e49bfa-d7d4-4b20-8b54-f63dc09ffb31",
      "name": "Resp: Celular Bloquear Inv\u00e1lido",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -2032,
        -2640
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "1ce23093-4638-4cfc-8449-21cfe55aa235",
      "name": "Limpiar Estado (Celular Bloquear Inv\u00e1lido)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1808,
        -2640
      ]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/usuarios/{{ $json.celularBloquear }}/bloquear",
        "options": {}
      },
      "id": "a9dbe347-7164-45f4-aa0c-13855500dabf",
      "name": "API: Bloquear Usuario",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -2032,
        -2832
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "id": "a852f866-3e50-47a8-b379-0a28c7f9cd68",
      "name": "\u00bfUsuario Bloqueado?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1808,
        -2832
      ]
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u2705 Usuario bloqueado exitosamente.\n\nEl usuario ya no podr\u00e1 acceder al sistema.",
        "additionalFields": {}
      },
      "id": "61d2fe9d-dfca-4187-8d77-ab6518804502",
      "name": "Resp: Usuario Bloqueado",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -2928
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "821068047761861",
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger1').item.json.contacts[0].wa_id }}",
        "textBody": "\u274c Error al bloquear usuario: {{ $json.message || 'Usuario no encontrado o error desconocido' }}",
        "additionalFields": {}
      },
      "id": "cce8e4fd-fe8b-4093-9f06-d254ca2e1500",
      "name": "Resp: Error Bloquear Usuario",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        -1584,
        -2448
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://electo-infosac.fxtfoe.easypanel.host/api/estado-usuario/{{ $('WhatsApp Trigger1').first().json.contacts[0].wa_id.substring(2) }}",
        "options": {}
      },
      "id": "bb20c2b2-c575-4cc2-8ebf-c4e47e6699f2",
      "name": "Limpiar Estado (Bloquear Usuario)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        -1360,
        -2832
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://electo-infosac.fxtfoe.easypanel.host/api/personas",
        "sendHeaders": true,
        "headerParameters": {
    

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow automates customer conversations on WhatsApp by checking user status, routing messages through decision logic, and sending appropriate replies without manual intervention. It suits support teams and businesses that handle high volumes of WhatsApp enquiries and need consistent, state-aware responses. The core step is the sequence of HTTP requests that query and update user state before the switch nodes decide the next action.

Use it when you require reliable routing based on stored user data and want to keep conversations within WhatsApp. Avoid it for simple one-off broadcasts or when you need AI-generated replies. Common variations replace the state checks with different data sources or add extra switch branches for new commands.

About this workflow

Worflow. Uses whatsAppTrigger, httpRequest, whatsApp. Event-driven trigger; 94 nodes.

Source: https://github.com/gohanrv1/sac_app/blob/58b952f63fcde43e5d1eed8991222e06ead7dc2c/worflow.json — original creator credit. Request a take-down →

More Slack & Telegram workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Slack & Telegram

This workflow is designed for **customer support teams, e-commerce founders, and operations managers** who want to handle thousands of customer queries seamlessly. Instead of building a brand-new chat

Telegram Trigger, Supabase, WhatsApp +2
Slack & Telegram

This workflow enables seamless, bidirectional communication between WhatsApp and Slack using n8n. It automates the reception, processing, and forwarding of messages (text, media, and documents) betwee

WhatsApp Trigger, Slack, Slack Trigger +2
Slack & Telegram

This workflow listens for incoming WhatsApp messages that contain media (e.g., images) and automatically downloads the media file using WhatsApp's private media URL. The trigger node activates when a

WhatsApp Trigger, WhatsApp, HTTP Request
Slack & Telegram

This workflow is for service-based businesses and freelancers who want to automate booking appointments via WhatsApp without relying on third-party scheduling tools. It's perfect for small teams who w

WhatsApp Trigger, WhatsApp, Postgres +1
Slack & Telegram

Automates LinkedIn job searches across multiple countries and categories, filters results with AI, stores data in Google Sheets, and sends weekly Telegram notifications. Perfect for professionals seek

Telegram Trigger, Item Lists, HTTP Request +3