Skip to main content

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.
What You’ll Learn:
  • 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

Instant notifications as calls progress, from start to completion

Call Data

Full transcripts, recordings, and extracted information

Custom Parameters

Pass ANY custom data that gets echoed back for identification

Secure Delivery

HTTPS-only with Bearer token authentication support

How It Works - Complete Flow

The flow works in three stages: Initiation: Your application sends configuration with agentId 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

What are they?Custom parameters are ANY data you send during agent initiation. They serve two crucial purposes:
  1. Provide context to the agent during the conversation
  2. Get echoed back in webhook responses for matching records
Example:
All these fields will be available in the webhook’s outcomeResult object.
Types of Events:
  • call.started - Call begins
  • call.answered - Call connected
  • transcription.update - Real-time speech updates
  • tool.executed - Agent uses a tool
  • call.ended - Call completes (includes full data)
Each event contains relevant data for that stage of the call lifecycle.
How it works:
  1. You send: { params: { application_id: "12345" } }
  2. Agent conducts call
  3. You receive: { outcomeResult: { application_id: "12345", ... } }
This pattern allows you to match webhook responses to your database records without maintaining state.
What is it?The outcomeResult object in webhook responses contains:
  • Echoed data - All your custom params (unchanged)
  • Outcome data - Information collected by the agent
This combination lets you identify the record AND get the collected information in one payload.

Stage 2: Setup & Configuration

Prerequisites

Before setting up webhooks, ensure you have:
1

A publicly accessible server

Your webhook endpoint must be reachable from the internet. Use ngrok for local development.
2

HTTPS enabled

All webhook URLs must use HTTPS. HTTP endpoints will be rejected.
3

A web framework

Express.js, Flask, FastAPI, or any framework that can handle POST requests.
4

Basic authentication setup

Prepare to implement Bearer token authentication (recommended for production).

Setting Up Your Webhook URL

Webhook URL Requirements

HTTPS Required:
  • All webhook URLs must use HTTPS protocol
  • HTTP endpoints will be rejected
  • Self-signed certificates are not supported
  • Certificate must be valid and not expired
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:
Configuration
Not recommended for production. Anyone who discovers your webhook URL can send requests to it.
Use for production environments:
Configuration
Generating Secure Tokens:
Token Format Requirements:
  • 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

1

Navigate to Agent Configuration

Go to your agent’s configuration page in the Hamsa dashboard
2

Find Call Webhook Section

Scroll to the Call Webhook section and click to expand
3

Enter Webhook URL

Input your publicly accessible HTTPS webhook URL
4

Configure Authentication

Choose authentication method and enter your Bearer token if applicable
5

Save Configuration

Save your agent configuration to activate the webhook
Webhooks are configured per agent. Each agent can have its own webhook URL and authentication settings.

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

Important: The params object can contain ANY fields you want. All fields you pass here will be:
  1. Available to the agent during the conversation
  2. Echoed back to you in the webhook response inside outcomeResult

Data Types Supported in params

Best Practice: For complex data (arrays, objects), convert to JSON strings before passing.

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

The call.ended event contains the complete conversation data:

Field Descriptions

Top-Level Event Fields: Conversation Data 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 the params 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):
Note: The exact fields depend on your agent’s configuration and outcome schema. Check with your Hamsa agent setup to see what fields are extracted.

Stage 4: Implementation

Creating Your Webhook Endpoint

Node.js/Express Implementation

Python/Flask Implementation

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

Idempotency

Prevent duplicate processing of webhook events:

Redis-Based Idempotency

Database-Based Idempotency

Security Best Practices

Security Checklist:
  • ✅ Always use HTTPS endpoints
  • ✅ Implement Bearer token authentication
  • ✅ Validate all incoming data
  • ✅ Use strong, randomly generated tokens
  • ✅ Rotate tokens periodically
  • ✅ Log authentication failures
  • ✅ Rate limit webhook endpoint
  • ✅ Monitor for suspicious patterns

Token Management

Rate Limiting

IP Whitelisting (Optional)

Use Cases & Patterns

CRM Integration

Analytics Dashboard

Notification System


Stage 6: Troubleshooting & Support

Common Issues

Symptoms:
  • No webhook events arriving at your endpoint
  • Call completes but no POST request received
Possible Causes:
  1. Webhook URL is not publicly accessible
  2. Webhook URL not configured in Hamsa dashboard
  3. Firewall/security rules blocking POST requests
  4. Server not running or crashed
  5. HTTPS certificate invalid
Solutions:
For Local Development:
Symptoms:
  • Receiving webhook data but can’t identify which record it belongs to
  • Missing application_id or user_id in outcomeResult
Causes:
  • Not passing unique identifier in params during initiation
  • Identifier not being echoed correctly
  • Wrong field name being checked
Solutions:
Debugging Tips:
Symptoms:
  • Receiving 401 Unauthorized responses
  • Webhook attempts shown in logs but rejected
Causes:
  • Bearer token mismatch
  • Token format incorrect
  • Missing “Bearer” prefix
  • Token changed in dashboard but not in code
Solutions:
Symptoms:
  • Receiving some events but not all
  • call.started received but not call.ended
Causes:
  1. Webhook endpoint returning errors for some events
  2. Timeout (not responding within 5 seconds)
  3. Network connectivity issues during specific events
  4. Processing logic throwing errors for certain event types
Solutions:
Symptoms:
  • Receiving the same event multiple times
  • Database records being created twice
Cause:
  • Webhook retries due to slow responses
  • Network issues causing retransmission
  • Not implementing idempotency
Solution:
Symptoms:
  • Expected fields are null or undefined
  • Outcome data not present
Causes:
  • 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
Solutions:
Symptoms:
  • Arrays or objects sent in params are not preserved correctly
  • Receiving stringified data or corrupted structures
Cause:
  • Not converting complex data to JSON strings before sending
Solution:

Testing Your Webhook

Local Testing with cURL

Monitoring & Logging


Integration Checklist

Before Going Live

1

Data Structure Planning

Define what custom params you’ll send in 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.
2

Webhook Setup

Create webhook endpoint (POST route). Make endpoint publicly accessible (use ngrok for testing). Configure webhook URL in Hamsa dashboard. Test webhook receives POST requests. Verify webhook returns 200 OK within 5 seconds. Implement Bearer token authentication.
3

Implementation

Implement event type handling (call.started, call.ended, etc.). Add data extraction from outcomeResult. Implement database updates. Add transcript parsing. Handle recording URL storage. Test with missing/null fields.
4

Error Handling

Validate incoming payload structure. Handle authentication failures. Implement proper error logging. Add timeout handling. Test error scenarios.
5

Advanced Features

Implement async processing (queue-based). Add idempotency checks. Set up rate limiting. Add monitoring and alerting. Implement retry logic.
6

Testing

Test with sample initiation data. Verify all custom params are echoed correctly. Test transcript parsing. Test recording URL access. Test with missing/null fields. Test error handling (invalid data, missing identifiers). Load test with multiple concurrent webhooks.
7

Production Deployment

Use HTTPS for webhook endpoint. Use strong Bearer token authentication. Add webhook authentication verification. Add comprehensive logging and monitoring. Set up error alerts. Document your integration. Train team on monitoring.

Summary

Key Takeaways

Initiation Data

Send configuration with agentId and params containing ANY custom data

Echo Pattern

All fields in params are echoed back in webhook’s outcomeResult

Identifiers

Always include unique identifiers to match webhooks to your records

Event Types

Handle different event types: started, answered, transcription, ended

Quick Response

Always respond with 200 OK within 5 seconds to avoid timeouts

Async Processing

Use queues for time-consuming operations after acknowledging receipt

Idempotency

Implement duplicate detection using callId + eventType + timestamp

Validation

Always validate echoed identifiers and handle missing fields

Security

Use HTTPS, Bearer tokens, and validate all incoming data

Quick Reference

Data Flow:
Integration Phases:

Next Steps

Webhooks Feature

Detailed webhook events reference

API Integration

Integrate with external APIs using tools

Voice Agents SDK

Complete SDK documentation

Data Collection

Advanced data extraction patterns

Need Help?

Contact Support

Get technical assistance from our team

Documentation

Browse complete documentation
Document Version: 2.0
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.