Webhook Integration for Developers
Learn how to build production-ready webhook handlers to receive and process real-time call events from Hamsa voice agents.Prerequisites:
- Webhook URL configured in dashboard (Setup Guide)
- Basic understanding of HTTP POST requests and JSON
- Node.js, Python, or your preferred backend framework
Understanding Webhook Data
Custom Parameters (Echo Pattern)
The most powerful feature of Hamsa webhooks is the echo pattern. All custom parameters you send during agent initiation are echoed back in the webhook response. What You Send:Event Structure
All webhook events follow this structure:Call Ended Event (Most Important)
Thecall.ended event contains complete conversation data:
Implementing Webhook Handlers
Node.js/Express Implementation
- Basic Handler
- Call Ended Handler
Python/Flask Implementation
- Basic Handler
- Call Ended Handler
Advanced Topics
Async Processing with Queues
Always process webhooks asynchronously to avoid timeouts:Idempotency
Prevent duplicate processing:Error Handling
Comprehensive error handling:Common Use Cases
CRM Integration
Notification System
Troubleshooting
Cannot Match Webhook to Record
Problem: Missing application_id in outcomeResult Solution:Missing or Null Fields
Problem: Expected fields are null or undefined Solution:Duplicate Events
Problem: Receiving same event multiple times Solution: Implement idempotency (see above section)Best Practices
Performance- Always respond within 5 seconds
- Use async processing for time-consuming operations
- Implement queue-based processing for production
- Verify Bearer token on every request
- Use HTTPS only
- Store tokens securely in environment variables
- Rotate tokens periodically
- Implement idempotency to handle duplicates
- Add comprehensive error logging
- Monitor webhook delivery rates
- Set up alerting for failures
- Always validate echoed identifiers exist
- Handle null/undefined fields gracefully
- Parse complex data (arrays, objects) from JSON strings
- Store recordings and transcripts for audit trails