Abrir NextChat
Atendimento

Webhooks

O NextChat avisa o seu sistema a cada evento.

Nesta página

Em vez de consultar a API o tempo todo, cadastre um endereço e o NextChat envia um POST a cada evento. Cadastre pela API (permissão webhooks:manage) ou em Configurações → Integrações.

EventoQuando
message.receivedChegou uma mensagem do cliente
message.sentSaiu uma mensagem (do app, do celular ou da API)
conversation.updatedA conversa mudou (responsável, setor, última mensagem…); é frequente
attendance.openedUm atendimento (protocolo) foi aberto
attendance.closedUm atendimento foi finalizado
kanban.card.createdUm cartão foi criado
kanban.card.movedUm cartão mudou de etapa (traz from_stage_id, to_stage_id e quem moveu)
kanban.card.completedUm cartão foi para uma etapa de ganho
POST/integrations/webhooksbash
curl -X POST "$NEXTCHAT_API/integrations/webhooks" \
  -H "Authorization: Bearer $NEXTCHAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Meu ERP","url":"https://erp.exemplo.com.br/nextchat","events":["message.received","attendance.closed"]}'

A resposta traz o segredo de assinatura whsec_… uma única vez: guarde-o. Até 20 endereços por empresa. Teste com POST /integrations/webhooks/{id}/test e veja as entregas em GET /integrations/webhooks/{id}/deliveries.

O que chega

Corpo entreguejson
{ "id": "evento-uuid", "type": "attendance.opened", "created_at": "2026-10-15T10:30:00Z", "tenant_id": "…", "data": { "…": "objeto do evento" } }

Cabeçalhos: X-NextChat-Event, X-NextChat-Event-Id, X-NextChat-Delivery, X-NextChat-Timestamp (segundos) e X-NextChat-Signature: sha256=<hex>.

Verificar a assinatura

A assinatura é o HMAC-SHA256, com o segredo, de "<timestamp>.<corpo bruto>". Rejeite se o timestamp tiver mais de 5 minutos.

Node.jsbash
import { createHmac, timingSafeEqual } from 'node:crypto';
const ok = (secret, ts, raw, sig) => {
  const mine = 'sha256=' + createHmac('sha256', secret).update(`${ts}.${raw}`).digest('hex');
  return mine.length === sig.length && timingSafeEqual(Buffer.from(mine), Buffer.from(sig));
};
Pythonbash
import hmac, hashlib
def ok(secret, ts, raw: bytes, sig: str) -> bool:
    mine = "sha256=" + hmac.new(secret.encode(), ts.encode() + b"." + raw, hashlib.sha256).hexdigest()
    return hmac.compare_digest(mine, sig)

Entrega e novas tentativas

Responda 2xx em até 8 segundos. Senão, o NextChat tenta de novo depois de 30 s, 2 min, 10 min, 1 h e 6 h. Depois de 10 entregas seguidas que falharam de vez, o endereço é desativado (reative com PATCH {active: true}). As entregas ficam 14 dias. Pode haver entrega repetida: use X-NextChat-Event-Id para ignorar as duplicadas.

Segurança do destino

Só https. Endereços de rede interna, loopback e de metadados de nuvem são recusados, e redirecionamentos não são seguidos. Números privados de WhatsApp nunca geram eventos, e eventos de cartão trazem só os campos públicos do cartão.

Endpoints

MétodoCaminhoAçãoPermissão
GET/integrations/webhooksListar webhookswebhooks:manage
POST/integrations/webhooksCadastrar webhook (devolve o segredo uma vez)webhooks:manage
GET/integrations/webhooks/eventsEventos disponíveiswebhooks:manage
PATCH/integrations/webhooks/{id}Editar ou reativar webhookwebhooks:manage
DELETE/integrations/webhooks/{id}Apagar webhookwebhooks:manage
POST/integrations/webhooks/{id}/rotate-secretRedefinir o segredo de assinaturawebhooks:manage
POST/integrations/webhooks/{id}/testEnviar evento de testewebhooks:manage
GET/integrations/webhooks/{id}/deliveriesÚltimas entregaswebhooks:manage
↑ ↓ navegar↵ abrirEsc fechar