Authentication
All API requests require authentication using your Project API Key:Find your API keys in your Project settings under “API Keys”. Keep these keys secure and never expose them in client-side code.
WhatsApp Webhooks
Kapso provides real-time webhooks for WhatsApp messaging events, enabling you to build powerful integrations and automate workflows based on WhatsApp conversations.Configuring WhatsApp Webhooks
- Navigate to your WhatsApp configuration settings
- Go to the “Webhooks” tab
- Click “Add Webhook” to create a new webhook endpoint
- Configure the following:
- URL: Your endpoint that will receive webhook notifications
- Events: Select which events you want to subscribe to
- Secret Key: Auto-generated or provide your own (used for HMAC signature verification)
- Custom Headers: Optional additional headers for authentication
WhatsApp Webhook Events
Message Received
whatsapp.message.received
Fired when a new WhatsApp message is received from a customer. Supports message buffering for batch delivery.Message Sent
whatsapp.message.sent
Fired when a message is successfully sent to WhatsAppMessage Delivered
whatsapp.message.delivered
Fired when a message is successfully delivered to the recipient’s deviceMessage Read
whatsapp.message.read
Fired when the recipient reads your messageMessage Failed
whatsapp.message.failed
Fired when a message fails to deliverConversation Created
whatsapp.conversation.created
Fired when a new WhatsApp conversation is initiatedConversation Ended
whatsapp.conversation.ended
Fired when a WhatsApp conversation ends (agent action, manual closure, or 24-hour inactivity)WhatsApp Webhook Headers
Every WhatsApp webhook request includes these headers:WhatsApp Webhook Payloads
Message Event Payload
For message-related events (received
, sent
, delivered
, read
, failed
):
Conversation Created/Ended Payload
For thewhatsapp.conversation.created
and whatsapp.conversation.ended
events:
For
whatsapp.conversation.ended
events, the conversation status will be “ended”. This event is triggered when:- An agent ends the conversation through an action
- A human manually closes the conversation
- The conversation automatically ends after 24 hours of inactivity
last_active_at
timestamp indicates when the conversation was last active.Message Types
Themessage_type
field can be one of:
text
- Plain text messageimage
- Image attachmentvideo
- Video attachmentaudio
- Audio/voice messagedocument
- Document attachmentlocation
- Location sharingtemplate
- WhatsApp template messageinteractive
- Interactive message (buttons, lists)reaction
- Message reactioncontacts
- Contact card sharing
Message Type-Specific Data
Themessage_type_data
field contains different information based on the message type:
Media Messages (image/video/document/audio)
Location Messages
Template Messages
Interactive Messages
Reaction Messages
WhatsApp Message Buffering
Message buffering allows you to receive multiplewhatsapp.message.received
events in a single batched webhook, reducing the load on your servers during high-volume conversations.
How It Works
- Debounce Pattern: Messages are collected in a buffer until the configured time window expires without receiving new messages
- Automatic Batching: Multiple messages from the same conversation are grouped together
- Immediate Delivery: Batches are sent when the maximum batch size is reached or the buffer window expires
- Per-Conversation Buffering: Each conversation has its own independent buffer
Configuration
When creating or editing a webhook, enable message buffering for thewhatsapp.message.received
event:
- Buffer Window: Time to wait before sending batched messages (1-60 seconds, default: 5)
- Maximum Batch Size: Maximum messages per batch (1-100, default: 50)
Batched Webhook Format
When messages are buffered, your endpoint receives the samewhatsapp.message.received
event type with an array of messages:
Important: When buffering is enabled, ALL messages are delivered in the batch format, even single messages. The
data
array will contain just one message if only one message was received during the buffer window. Always check the batch
field or X-Webhook-Batch
header to determine if you’re receiving a batched delivery.Verifying WhatsApp Webhooks
Always verify the webhook signature to ensure the request is authentic:Testing WhatsApp Webhooks
You can test your webhook endpoints directly from the Kapso interface:- Go to your WhatsApp webhook configuration
- Click the “Test Webhook” button
- Select an event type to test
- Review the sample payload that will be sent
- Click “Send Test” to trigger a test webhook
Webhook Reliability
Kapso implements several features to ensure reliable webhook delivery:- Retries: Failed webhooks are retried up to 3 times with fast exponential backoff (10 seconds, 40 seconds, 90 seconds)
- Total Time to Failure: Approximately 2.5 minutes from first attempt to final failure
- Timeout: Webhook requests timeout after 30 seconds (45 seconds for batched deliveries)
- Idempotency: Each event has a unique idempotency key to prevent duplicate processing
- Delivery Tracking: All webhook deliveries are logged with full request/response details
- Message Ordering: WhatsApp message webhooks are delivered in sequence order within conversations to maintain message chronology
- Batch Consistency: When buffering is enabled, messages are always delivered in batch format, even during retries. After max retries, the batch is marked as permanently failed.
WhatsApp Message Ordering
Kapso ensures WhatsApp messages are delivered to your webhooks in the correct order within each conversation:- Sequence-based Ordering: Each webhook delivery within a conversation is assigned a sequence number
- Automatic Queuing: Messages are automatically queued if earlier messages haven’t been delivered yet
- Ordering Timeout: After 30 seconds, messages are delivered regardless of ordering to prevent indefinite delays
- Applies To: Message received (
whatsapp.message.received
) and message sent (whatsapp.message.sent
) events - Per Conversation: Ordering is maintained within each conversation independently
Best Practices for WhatsApp Webhooks
- Handle Events Asynchronously: Process webhook data in background jobs to respond quickly
- Implement Idempotency: Use the
X-Idempotency-Key
header to prevent processing duplicates - Monitor Failures: Set up alerts for webhook delivery failures
- Secure Your Endpoint: Always verify signatures and use HTTPS
- Handle All Event Types: Even if you only need certain events now, handle all types gracefully
- Process Quickly: Respond within 5 seconds to avoid being marked as failed delivery
Agent Webhooks
Webhooks allow two-way communication: your systems can trigger Kapso agents, and Kapso agents can notify your systems.Incoming Webhooks (Triggering Agents)
Use incoming webhooks to start an agent’s execution flow from your application (e.g., backend, CRM).-
Endpoint: Each agent has a unique webhook URL.
-
Authentication: Include your Project API Key in the
X-API-Key
request header. -
Request Body (Optional): Send initial data in the JSON payload.
-
Example (Node.js):
Outbound Webhooks (Agent Notifications)
Configure your agents to send real-time notifications to your systems when important events occur during execution.Configuration
- Navigate to your agent’s “API & Webhooks” settings
- Add webhook endpoints for the events you want to monitor
- Configure a Secret Key for request verification
- Select which events to subscribe to
Supported Events
Execution Started
agent_execution_started
Fired when an agent begins processingExecution Ended
agent_execution_ended
Fired when an agent completes successfullyExecution Failed
agent_execution_failed
Fired when an agent encounters an errorHandoff Required
agent_execution_handoff
Fired when human intervention is neededSecurity & Verification
Every webhook request includes anX-Webhook-Signature
header containing an HMAC SHA-256 signature of the request body. Verify this signature using your configured Secret Key to ensure authenticity.
Webhook Payloads
All webhook payloads include base execution data plus event-specific information:Base Payload Structure
Event-Specific Data
Handoff Event includes handoff details:Webhook Best Practices
Important considerations:
- Respond quickly (within 5 seconds) with a 2xx status code
- Process webhook data asynchronously if needed
- Store the webhook secret securely
- Always verify webhook signatures
- Implement idempotency handling using the provided idempotency key