Webhooks
Receive real-time notifications when events happen in your avatars.
What are Webhooks?
Webhooks are HTTP callbacks that notify your server when events occur. Instead of polling our API, we push data to your endpoint.
Setting Up Webhooks
Via Dashboard
- Go to Dashboard > Settings > Webhooks
- Click Add Webhook
- Enter your endpoint URL
- Select events to subscribe to
- Click Save
Via API
POST /v1/webhooks
{
"url": "https://your-server.com/webhooks/avatarium",
"events": ["conversation.started", "message.created", "conversation.ended"],
"secret": "your-webhook-secret"
}Available Events
Conversation Events
| Event | Description |
|---|---|
conversation.started | New conversation began |
conversation.ended | Conversation completed or timed out |
conversation.escalated | Human escalation triggered |
Message Events
| Event | Description |
|---|---|
message.created | New message in conversation |
message.failed | Message processing failed |
Avatar Events
| Event | Description |
|---|---|
avatar.updated | Avatar settings changed |
avatar.deleted | Avatar was deleted |
Safety Events
| Event | Description |
|---|---|
safety.escalation | Human escalation triggered |
safety.topic_blocked | Blocked topic detected |
safety.filter_triggered | Content filter activated |
Webhook Payload
All webhooks include:
{
"id": "evt_abc123",
"type": "message.created",
"timestamp": "2024-01-15T10:30:00Z",
"data": {
"conversationId": "conv_xyz789",
"avatarId": "avt_def456",
"message": {
"id": "msg_ghi012",
"role": "user",
"content": "Hello!"
}
}
}Verifying Webhooks
We sign all webhooks with your secret. Verify the signature to ensure authenticity:
const crypto = require('crypto');
function verifyWebhook(payload, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expected)
);
}
// In your webhook handler
app.post('/webhooks/avatarium', (req, res) => {
const signature = req.headers['x-avatarium-signature'];
const isValid = verifyWebhook(req.body, signature, process.env.WEBHOOK_SECRET);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
// Process the webhook
const event = JSON.parse(req.body);
console.log('Received event:', event.type);
res.status(200).send('OK');
});Retry Policy
If your endpoint fails to respond with 2xx:
- Immediate retry – After 5 seconds
- Second retry – After 30 seconds
- Third retry – After 5 minutes
- Final retry – After 1 hour
After 4 failures, the webhook is marked as failing. We'll notify you via email.
Best Practices
- Respond quickly – Return 200 immediately, process async
- Handle duplicates – Use the event
idto deduplicate - Verify signatures – Always validate webhook authenticity
- Use HTTPS – Required for production webhooks
- Monitor failures – Set up alerts for webhook errors
Testing Webhooks
Use our test endpoint to simulate events:
curl -X POST https://api.avatarium.ai/v1/webhooks/test \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"event": "message.created", "webhookId": "wh_abc123"}'Or use the Send Test button in Dashboard > Webhooks.