Webhooks
Recibe notificaciones en tiempo real cuando ocurren eventos en AstrApp.
Crear webhook
bash
curl -X POST https://api.astrapp.lat/api/v1/integrations/webhooks \
-H "Authorization: Bearer sk_live_xxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"url": "https://tu-app.com/webhooks/astrapp",
"events": ["training.completed", "model.deployed"],
"secret": "whsec_tu_secreto_seguro"
}'Eventos disponibles
Training
training.startedEntrenamiento iniciadotraining.progressProgreso actualizadotraining.completedEntrenamiento exitosotraining.failedEntrenamiento fallidoModels
model.createdModelo creadomodel.deployedModelo desplegadomodel.exportedModelo exportadoConversations
conversation.startedNueva conversacionconversation.endedConversacion terminadaconversation.feedbackFeedback recibidoVerificar firma
Siempre verifica la firma del webhook para asegurar que viene de AstrApp.
javascript
const crypto = require('crypto');
function verifyWebhook(payload, signature, secret) {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return signature === `sha256=${expectedSignature}`;
}
// En tu endpoint
app.post('/webhooks/astrapp', (req, res) => {
const signature = req.headers['x-astrapp-signature'];
const payload = JSON.stringify(req.body);
if (!verifyWebhook(payload, signature, WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}
// Procesar evento
const event = req.body;
console.log('Evento recibido:', event.event);
res.status(200).send('OK');
});Payload de ejemplo
json
{
"id": "evt_abc123",
"event": "training.completed",
"created_at": "2024-12-23T10:30:00Z",
"data": {
"job_id": "job_xyz789",
"project_id": "proj_1a2b3c4d",
"model_id": "model_final123",
"metrics": {
"accuracy": 0.92,
"loss": 0.08
}
}
}Siguiente
n8n