Webhooks & Events

Receive real-time notifications when events occur in your Twig AI organization.

What are Webhooks?

Webhooks are HTTP callbacks that notify your application when specific events happen. Instead of polling for changes, Twig AI pushes updates to your server.

Benefits:

  • Real-time notifications

  • No polling required

  • Efficient resource usage

  • Event-driven architecture

Supported Events

Interaction Events

Event
Description
Payload

interaction.created

New question asked

Interaction object

interaction.completed

Response generated

Interaction + response

interaction.feedback

User provided feedback

Interaction + feedback

Agent Events

Event
Description
Payload

agent.created

New agent created

Agent object

agent.updated

Agent configuration changed

Agent object + changes

agent.deleted

Agent removed

Agent ID

Data Source Events

Event
Description
Payload

datasource.created

New data source added

DataSource object

datasource.processed

Processing completed

DataSource + stats

datasource.failed

Processing failed

DataSource + error

User Events

Event
Description
Payload

user.created

New user added

User object

user.updated

User details changed

User object + changes

Setting Up Webhooks

Via UI

  1. Navigate to SettingsWebhooks

  2. Click Create Webhook

  3. Configure:

    • URL: Your endpoint (must be HTTPS)

    • Events: Select events to receive

    • Secret: Auto-generated signing secret

  4. Click Create

  5. Test webhook

  6. Save

Via API

Response:

Webhook Payload

Standard Format

All webhooks follow this structure:

Event Examples

Interaction Completed:

Data Source Processed:

Receiving Webhooks

Endpoint Implementation

Node.js/Express:

Python/Flask:

Security

Signature Verification

Always verify webhook signatures:

HTTPS Required

  • All webhook URLs must use HTTPS

  • Valid SSL certificate required

  • Self-signed certificates not accepted

IP Whitelisting

Webhook requests come from:

Add to firewall whitelist if needed.

Best Practices

1. Respond Quickly

✅ Return 200 OK immediately ✅ Process asynchronously ✅ Use job queue for heavy processing

2. Handle Retries

✅ Implement idempotency ✅ Store event IDs to detect duplicates ✅ Handle same event multiple times safely

3. Error Handling

4. Logging

✅ Log all webhook receipts ✅ Track processing time ✅ Monitor failure rates

Retry Logic

Automatic Retries

Twig AI automatically retries failed webhooks:

Attempt
Delay
Total Time

1

Immediate

0s

2

5 seconds

5s

3

30 seconds

35s

4

5 minutes

5m 35s

5

1 hour

1h 5m 35s

After 5 attempts, webhook is marked as failed.

Handling Failed Webhooks

View failed webhooks:

  1. Settings → Webhooks

  2. Select webhook

  3. View "Failed Deliveries"

  4. Retry manually if needed

Testing Webhooks

Test Mode

Sends test event to your endpoint.

Local Development

Use tools like ngrok for local testing:

Event Simulator

Monitoring

Webhook Metrics

Track these metrics:

  • Delivery success rate

  • Average response time

  • Retry rate

  • Error types

Dashboard

Alerts

Configure alerts for:

  • Failed deliveries > 10

  • Response time > 5s

  • Success rate < 95%

Troubleshooting

Webhook Not Received

Check:

  1. Webhook is active

  2. URL is correct and accessible

  3. HTTPS with valid certificate

  4. Events are subscribed

  5. Firewall allows Twig IPs

Signature Verification Fails

Check:

  1. Using correct secret

  2. Payload not modified

  3. Using raw body (not parsed JSON)

  4. Comparing hex digests correctly

High Failure Rate

Check:

  1. Server is responding within 10s

  2. Returning 200 OK status

  3. Not throwing errors

  4. Handling retries correctly

Next Steps

Last updated