Overview
This comprehensive guide walks you through integrating with Hamsa Voice Agent webhooks, from initial setup to production deployment. Whether you’re just getting started or implementing advanced patterns, this guide has you covered.- How to set up and configure webhook endpoints
- Understanding webhook data structures and events
- Implementing secure and reliable webhook handlers
- Best practices for production deployments
- Troubleshooting common issues
Stage 1: Getting Started
What Are Webhooks?
Webhooks allow your applications to receive real-time notifications about call events, transcriptions, and conversation outcomes. When a voice call completes or specific events occur, Hamsa sends HTTP POST requests to your configured endpoint with relevant data.Real-time Events
Call Data
Custom Parameters
Secure Delivery
How It Works - Complete Flow
The flow works in three stages: Initiation: Your application sends configuration withagentId and custom params (identifiers, context data).
Call: User interacts with AI agent, which collects information through conversation.
Webhook: Hamsa POSTs results to your endpoint with transcript, recording, outcome data, and your original params echoed back.
Key Concepts
Custom Parameters (params)
Custom Parameters (params)
- Provide context to the agent during the conversation
- Get echoed back in webhook responses for matching records
outcomeResult object.Webhook Events
Webhook Events
call.started- Call beginscall.answered- Call connectedtranscription.update- Real-time speech updatestool.executed- Agent uses a toolcall.ended- Call completes (includes full data)
Echo Pattern
Echo Pattern
- You send:
{ params: { application_id: "12345" } } - Agent conducts call
- You receive:
{ outcomeResult: { application_id: "12345", ... } }
Outcome Result
Outcome Result
outcomeResult object in webhook responses contains:- Echoed data - All your custom params (unchanged)
- Outcome data - Information collected by the agent
Stage 2: Setup & Configuration
Prerequisites
Before setting up webhooks, ensure you have:A publicly accessible server
HTTPS enabled
A web framework
Basic authentication setup
Setting Up Your Webhook URL
Webhook URL Requirements
Valid Examples:Local Development Setup
For local development, use ngrok to expose your localhost:Configuring Authentication
Option 1: No Authentication (Development Only)
Use for development or testing:Option 2: Bearer Token Authentication (Recommended)
Use for production environments:- Must include the word “Bearer” followed by your token
- Example:
Bearer sk_live_abc123xyz789 - Token should be long and randomly generated
- Never commit tokens to source control
Adding Webhook to Your Agent
Navigate to Agent Configuration
Find Call Webhook Section
Enter Webhook URL
Configure Authentication
Save Configuration
Stage 3: Understanding Data Structures
Agent Initiation - What You Send
When initiating the agent, you send a configuration object with the following structure:Configuration Fields Reference
The params Object - Your Custom Data
params object can contain ANY fields you want. All fields you pass here will be:- Available to the agent during the conversation
- Echoed back to you in the webhook response inside
outcomeResult
Recommended Pattern
Data Types Supported in params
Complete Initiation Example
Webhook Events - What You Receive
Event Types Reference
Your webhook receives various events throughout a call’s lifecycle:Standard Event Structure
All webhook events follow this structure:Call Ended Event - The Most Important
Thecall.ended event contains the complete conversation data:
Field Descriptions
Top-Level Event Fields:data.data):
Transcription Array Format
Each element represents one turn in the conversation:Understanding outcomeResult
The outcomeResult object is where the magic happens - it contains both your echoed parameters AND newly collected outcome data.
Echoed Parameters (What You Sent)
These are the exact same parameters you included in theparams object when initiating the agent. They come from your application and are returned unchanged in the webhook payload, allowing you to match the webhook to your database records.
Outcome Data (New from Call)
These fields are generated during the voice call based on the conversation between the agent and the user. They come from the agent’s analysis of the call and are defined in your agent’s outcome configuration.Common Extracted Fields
These are fields commonly extracted by Hamsa agents (depending on your agent’s configuration):Stage 4: Implementation
Creating Your Webhook Endpoint
Node.js/Express Implementation
- Basic Handler
- Call Ended Handler
Python/Flask Implementation
- Basic Handler
- Call Ended Handler
Processing Events
Handling Different Event Types
Error Handling
Comprehensive Error Handling
Validation Helper
Stage 5: Advanced Topics
Async Processing
For production systems, always process webhooks asynchronously to avoid timeouts and ensure reliability.Queue-Based Processing
- Bull Queue (Node.js)
- Celery (Python)
Idempotency
Prevent duplicate processing of webhook events:Redis-Based Idempotency
Database-Based Idempotency
Security Best Practices
Token Management
Rate Limiting
IP Whitelisting (Optional)
Use Cases & Patterns
CRM Integration
Analytics Dashboard
Notification System
Stage 6: Troubleshooting & Support
Common Issues
Webhook not receiving data
Webhook not receiving data
- No webhook events arriving at your endpoint
- Call completes but no POST request received
- Webhook URL is not publicly accessible
- Webhook URL not configured in Hamsa dashboard
- Firewall/security rules blocking POST requests
- Server not running or crashed
- HTTPS certificate invalid
Cannot match webhook to your record
Cannot match webhook to your record
- Receiving webhook data but can’t identify which record it belongs to
- Missing application_id or user_id in outcomeResult
- Not passing unique identifier in
paramsduring initiation - Identifier not being echoed correctly
- Wrong field name being checked
Missing Events
Missing Events
- Receiving some events but not all
call.startedreceived but notcall.ended
- Webhook endpoint returning errors for some events
- Timeout (not responding within 5 seconds)
- Network connectivity issues during specific events
- Processing logic throwing errors for certain event types
Duplicate Events
Duplicate Events
- Receiving the same event multiple times
- Database records being created twice
- Webhook retries due to slow responses
- Network issues causing retransmission
- Not implementing idempotency
Missing or Null Fields in outcomeResult
Missing or Null Fields in outcomeResult
- Expected fields are
nullorundefined - Outcome data not present
- Agent didn’t collect that information during call
- Field name mismatch with agent configuration
- User didn’t provide the information
- Agent configuration doesn’t include that extraction
Complex Data Not Preserved (Arrays/Objects)
Complex Data Not Preserved (Arrays/Objects)
- Arrays or objects sent in
paramsare not preserved correctly - Receiving stringified data or corrupted structures
- Not converting complex data to JSON strings before sending
Testing Your Webhook
Local Testing with cURL
Monitoring & Logging
Integration Checklist
Before Going Live
Data Structure Planning
params (identifiers, context). Document your params structure for your team. Plan how you’ll use echoed data to match records. Decide what outcome data you expect from agent. Ensure identifiers are unique and persistent.Webhook Setup
Implementation
Error Handling
Advanced Features
Testing
Production Deployment
Summary
Key Takeaways
Initiation Data
agentId and params containing ANY custom dataEcho Pattern
params are echoed back in webhook’s outcomeResultIdentifiers
Event Types
Quick Response
Async Processing
Idempotency
Validation
Security
Quick Reference
Data Flow:Next Steps
Webhooks Feature
API Integration
Voice Agents SDK
Data Collection
Need Help?
Contact Support
Documentation
Last Updated: 2025-12-08
Hamsa SDK Version: Compatible with @hamsa-ai/voice-agents-sdk v2.x+For support, contact Hamsa Support or refer to official SDK documentation.