Skip to main content

Webhooks - Recibir Eventos

Los webhooks te notifican cuando llegan mensajes o cambian estados.

Configurar webhook

curl -X POST "https://tu-evolution.deployalo.com/webhook/set/mi-negocio" \
-H "apikey: TU_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://tu-servidor.com/webhook",
"events": [
"MESSAGES_UPSERT",
"MESSAGES_UPDATE",
"CONNECTION_UPDATE"
]
}'

Eventos disponibles

EventoDescripción
MESSAGES_UPSERTNuevo mensaje recibido
MESSAGES_UPDATEEstado de mensaje cambió
SEND_MESSAGEMensaje enviado
CONNECTION_UPDATEConexión cambió
QRCODE_UPDATEDNuevo código QR

Payload de mensaje recibido

{
"event": "MESSAGES_UPSERT",
"instance": "mi-negocio",
"data": {
"key": {
"remoteJid": "[email protected]",
"fromMe": false,
"id": "3EB0..."
},
"message": {
"conversation": "Hola, ¿tienen disponible el producto X?"
},
"messageTimestamp": 1702656000
}
}

Integrar con n8n

1. Crear workflow en n8n

  1. Agrega nodo Webhook
  2. Method: POST
  3. Copia la URL generada

2. Configurar en Evolution

Usa la URL de n8n como webhook:

curl -X POST ".../webhook/set/mi-negocio" \
-d '{"url": "https://tu-n8n.deployalo.com/webhook/xxx"}'

3. Procesar mensaje

En n8n, agrega nodos para:

  1. Extraer texto del mensaje
  2. Procesar con IA o lógica
  3. Responder via HTTP Request a Evolution

Ejemplo: Auto-respuesta

// Nodo Function en n8n
const mensaje = $input.item.json.data.message.conversation;
const numero = $input.item.json.data.key.remoteJid.replace('@s.whatsapp.net', '');

// Respuesta automática
return {
json: {
number: numero,
text: `Recibimos tu mensaje: "${mensaje}". Te responderemos pronto.`
}
};

Verificar configuración

curl "https://tu-evolution.deployalo.com/webhook/find/mi-negocio" \
-H "apikey: TU_API_KEY"

Eliminar webhook

curl -X DELETE "https://tu-evolution.deployalo.com/webhook/delete/mi-negocio" \
-H "apikey: TU_API_KEY"