Documentation Index
Fetch the complete documentation index at: https://docs.killb.com/llms.txt
Use this file to discover all available pages before exploring further.
Configuração Passo a Passo
Criar Endpoint
Construa endpoint POST para receber webhooksapp.post('/webhooks/killb', async (req, res) => {
// Lidar com webhook
res.status(200).json({ received: true });
});
Verificar Assinaturas
Implemente verificação HMACconst crypto = require('crypto');
const verifySignature = (payload, signature, secret) => {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return signature === expected;
};
Registrar Webhook
Configure na KillBPOST /api/v2/webhooks
{
"url": "https://api.seuapp.com/webhooks/killb",
"secret": "sua-chave-secreta",
"events": ["RAMP", "USER"]
}
Testar
Crie ramp de teste e verifique recebimento de webhook
Implementação Completa
const express = require('express');
const crypto = require('crypto');
const app = express();
// IMPORTANTE: Use corpo bruto para verificação de assinatura
app.use('/webhooks/killb', express.raw({type: 'application/json'}));
app.post('/webhooks/killb', async (req, res) => {
try {
// 1. Verificar assinatura
const signature = req.headers['x-signature-sha256'];
const payload = req.body.toString();
const expectedSignature = crypto
.createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(payload)
.digest('hex');
if (signature !== expectedSignature) {
console.error('Assinatura inválida');
return res.status(401).json({ error: 'Assinatura inválida' });
}
// 2. Reconhecer imediatamente
res.status(200).json({ received: true });
// 3. Processar assincronamente
const event = JSON.parse(payload);
processWebhookAsync(event).catch(console.error);
} catch (error) {
console.error('Erro de webhook:', error);
res.status(500).json({ error: 'Processamento falhou' });
}
});
app.listen(3000);
Testando Localmente
Use ngrok para testes locais:
# Iniciar servidor local
npm start
# Expor via ngrok
ngrok http 3000
# Usar URL ngrok
# https://abc123.ngrok.io/webhooks/killb
Próximos Passos
Referência de Eventos
Todos os tipos de evento de webhook
Segurança
Proteja seus webhooks