Skip to main content
Master webhook integrations to connect your chatbot to any AI provider or custom backend. This comprehensive guide covers everything from basic OpenAI/Anthropic setup to advanced patterns like A/B testing, async processing, and custom AI pipelines.

What You’ll Learn

By the end of this guide, you’ll understand:
  • How webhook integrations work in Chatbot Platform
  • Request and response payload formats
  • Setting up OpenAI, Anthropic, and custom backends
  • Authentication and security best practices
  • Error handling and retry strategies
  • Advanced patterns like A/B testing and async processing
  • Performance optimization techniques

Prerequisites

Before starting, you should:
  • Have a bot created in Chatbot Platform
  • Understand HTTP POST requests and JSON
  • Have API keys for your AI provider (OpenAI, Anthropic, etc.)
  • Know basic webhook/API concepts
  • Have access to deploy a simple proxy service (optional for advanced setups)

How Webhook Integrations Work

The Flow

Why Webhooks?

Webhooks give you full control:
  • Choose any AI provider: OpenAI, Anthropic, Cohere, custom models
  • Add custom logic: RAG, knowledge base search, data lookups
  • A/B test models: Compare GPT-4 vs Claude, different prompts
  • Transform data: Add/remove context, format responses
  • Implement guardrails: Content filtering, safety checks
  • Track analytics: Log every request and response

Request Payload Format

Every webhook integration receives this standard payload:

Field Descriptions

messages (array): OpenAI-format conversation history
  • Includes system prompt if configured
  • Contains conversation context based on your window setting
  • Latest message is always last
conversation_id (string): Unique ID for this conversation thread user (object): Information about the user
  • id: Platform-specific user ID
  • platform: telegram | slack | discord | whatsapp
  • name: User’s display name
  • username: Platform username (if available)
bot (object): Your bot’s information
  • id: Bot ID in Chatbot Platform
  • name: Bot’s configured name
metadata (object): Platform-specific data
  • channel: Platform name
  • channel_id: Channel configuration ID
  • chat_id: Platform-specific chat identifier
  • message_id: Platform-specific message ID
  • timestamp: When message was received (ISO 8601)

Response Format

Your webhook must return JSON with a content field:

Simple Response

Response with Metadata

The metadata object is optional but useful for:
  • Tracking which model was used
  • Logging token usage and costs
  • Debugging performance issues
  • A/B test analytics
  • Custom business metrics

Step 1: Basic Integration Setup

Let’s create a basic integration that connects to OpenAI.
1

Create Integration

In your bot’s Integrations tab:
  1. Click Create Integration
  2. Enter basic info:
    • Name: “OpenAI GPT-4”
    • Webhook URL: https://your-api.com/openai-proxy (we’ll build this)
    • Timeout: 30 seconds
    • Weight: 100
Integration form

Integration configuration

2

Add Headers

Add authentication headers:
Note: These headers are sent to YOUR webhook, not directly to OpenAI.
3

Save Integration

Click Create to save the integration.

Step 2: Build an OpenAI Proxy

Since OpenAI’s API doesn’t accept our payload format directly, you need a simple proxy service.

Node.js/Express Example

Python/Flask Example

PHP/Laravel Example

Step 3: Build an Anthropic Proxy

Anthropic (Claude) requires a slightly different format.

Node.js Example

Advanced Patterns

Pattern 1: Knowledge Base Search (RAG)

Add retrieval augmented generation to ground responses in your documentation:

Pattern 2: A/B Testing

Test different models or prompts:

Pattern 3: Custom Business Logic

Add custom processing before/after AI:

Pattern 4: Async Processing with Callbacks

For long-running tasks, return immediately and deliver response later:

API Examples

For complete API documentation, see the OpenAPI specification.

Security Best Practices

Use HTTPS

Always use HTTPS endpoints to encrypt data in transit

Validate Requests

Verify requests come from Chatbot Platform

Secure API Keys

Never expose API keys in code or logs

Rate Limiting

Implement rate limiting on your webhook

Request Validation

Verify requests are from Chatbot Platform:

API Key Management

Store API keys securely:

Error Handling

Never expose internal errors to users:

Performance Optimization

Caching

Cache frequent responses:

Streaming Responses

For faster perceived performance (coming soon):

Connection Pooling

Reuse HTTP connections:

Troubleshooting

Timeout Errors

Symptoms: Requests timeout before completion Solutions:
  • Increase timeout in integration settings
  • Optimize AI calls (lower max_tokens, faster model)
  • Use async processing for slow operations
  • Check network latency between services

Authentication Failures

Symptoms: 401/403 errors Solutions:
  • Verify API keys are correct
  • Check header names match provider requirements
  • Ensure no extra spaces in header values
  • Test API key directly with provider’s API

Malformed Response

Symptoms: Bot returns error to user Solutions:
  • Verify response includes content field
  • Check response is valid JSON
  • Ensure Content-Type header is application/json
  • Test webhook with curl manually

High Costs

Symptoms: Unexpected AI API bills Solutions:
  • Reduce context window size
  • Use cheaper models for simple queries
  • Implement caching for common questions
  • Add token limits (max_tokens parameter)
  • Monitor usage with metadata logging

Next Steps

Add Grounded Responses

Use Agentic Loops for data-backed answers

A/B Testing

Compare multiple integrations

Async Replies

Handle long-running processes

Custom Headers

Advanced header configuration