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.receivedFired when a new WhatsApp message is received from a customer. Supports message buffering for batch delivery.Message Sent
whatsapp.message.sentFired when a message is successfully sent to WhatsAppMessage Delivered
whatsapp.message.deliveredFired when a message is successfully delivered to the recipient’s deviceMessage Read
whatsapp.message.readFired when the recipient reads your messageMessage Failed
whatsapp.message.failedFired when a message fails to deliverConversation Created
whatsapp.conversation.createdFired when a new WhatsApp conversation is initiatedConversation Ended
whatsapp.conversation.endedFired when a WhatsApp conversation ends (agent action, manual closure, or 24-hour inactivity)Conversation Inactive
whatsapp.conversation.inactiveFired when no messages (inbound/outbound) for configured minutes (1-1440, default 60)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.Conversation Inactive Payload
For thewhatsapp.conversation.inactive event:
For
whatsapp.conversation.inactive events:since_messagecontains the last message in the conversation (inbound or outbound)directionindicates whether the last message was from customer (“inbound”) or you (“outbound”)inactivity.minutesshows your configured threshold- Calculate deadline:
since_message.created_at+inactivity.minutes - Idempotency key is SHA-256 hash of webhook ID + message ID
- Any new message before the timer fires cancels the event automatically
- Won’t fire for ended conversations or historical imports
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-Keyheader 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
Project Webhooks
Project-level webhooks notify you about project-wide events like customer onboarding.Configuring Project Webhooks
Configure project webhooks in the Kapso web app:- Open the sidebar and click Webhooks
- Go to the Project webhooks tab
- Click Add Webhook
- Enter your HTTPS endpoint URL
- Copy the auto-generated secret key for signature verification
- Accept POST requests
- Return 200 status within 10 seconds
- Handle duplicate events (idempotent)
Project Webhook Events
WhatsApp Config Created
whatsapp.config.createdFired when a customer successfully connects their WhatsApp through a setup linkProject Webhook Headers
Every project webhook request includes:Project Webhook Payloads
WhatsApp Config Created Payload
For thewhatsapp.config.created event:
The
whatsapp.config.created event provides complete context about:- The WhatsApp configuration that was created
- The project and customer it belongs to
- The setup link that was used (if any)
- The phone number associated with the config
- Whether it’s a sandbox or coexistence setup
- Update your database when customers complete onboarding
- Trigger welcome messages or onboarding flows
- Track customer activation metrics
- Sync WhatsApp connection status with your systems
Verifying Project Webhooks
Project webhooks use the same HMAC SHA-256 signature verification as WhatsApp webhooks. See Verifying WhatsApp Webhooks above for examples.Project Webhook Reliability
Project webhooks use the same reliability features as WhatsApp webhooks:- Retries: Failed webhooks are retried up to 3 times with fast exponential backoff (10s, 40s, 90s)
- Total Time to Failure: Approximately 2.5 minutes from first attempt to final failure
- Timeout: Webhook requests timeout after 30 seconds
- Idempotency: Each event has a unique idempotency key to prevent duplicate processing
- Delivery Tracking: All webhook deliveries are logged with full request/response details
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-Keyrequest 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_startedFired when an agent begins processingExecution Ended
agent_execution_endedFired when an agent completes successfullyExecution Failed
agent_execution_failedFired when an agent encounters an errorHandoff Required
agent_execution_handoffFired 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

