Skip to content

Bot System

Aziel edited this page Dec 16, 2025 · 2 revisions

AZ-WAP includes a reusable AI bot system that operates independently from WhatsApp. This architecture allows the bot to be used with multiple communication channels.

Key Advantage: External Reusability

The bot system is not tied to WhatsApp. It can:

  • Process messages from any source
  • Generate responses independently
  • Be triggered via API for external integrations
  • Maintain conversation context across channels
┌─────────────────────────────────────────────┐
│              Bot System (Core)              │
│  ┌───────────────────────────────────────┐  │
│  │  • AI Provider (Gemini)               │  │
│  │  • System Prompt                      │  │
│  │  • Knowledge Base                     │  │
│  │  • Memory/Context                     │  │
│  └───────────────────────────────────────┘  │
└─────────────────┬───────────────────────────┘
                  │
    ┌─────────────┼─────────────┐
    ▼             ▼             ▼
┌────────┐  ┌──────────┐  ┌──────────┐
│WhatsApp│  │ Chatwoot │  │ External │
│        │  │          │  │   API    │
└────────┘  └──────────┘  └──────────┘

Creating a Bot

POST /bots
Content-Type: application/json

{
  "name": "Sales Assistant",
  "description": "Handles sales inquiries",
  "provider": "gemini",
  "api_key": "your-gemini-api-key",
  "model": "gemini-2.0-flash",
  "system_prompt": "You are a helpful sales assistant...",
  "audio_enabled": true,
  "image_enabled": true,
  "memory_enabled": true
}

Bot Configuration

Field Description
name Bot display name
provider AI provider (gemini)
api_key Provider API key
model Model to use
system_prompt Base instructions for the AI
knowledge_base Additional context/documentation
timezone Timezone for date/time awareness
audio_enabled Process audio messages
image_enabled Process image messages
memory_enabled Maintain conversation history

Assigning Bot to Instance

PUT /instances/{id}/bot
{
  "bot_id": "bot-uuid"
}

Internal Bot Control

AZ-WAP's bot system handles message processing internally, which means:

Benefits

  1. No External Bot Dependencies: You don't need Chatwoot's agent bot
  2. Faster Response Times: Direct processing without external API hops
  3. Duplicate Prevention: Single source of truth for message handling
  4. Unified Logic: Same bot works across WhatsApp and other channels

How It Works

  1. Message arrives (WhatsApp, webhook, etc.)
  2. AZ-WAP routes to assigned bot
  3. Bot processes and generates response
  4. Response is sent to all configured destinations:
    • Back to WhatsApp (if from WhatsApp)
    • To Chatwoot (if enabled)
    • To webhooks (if configured)

Using Bot Externally

The bot can process messages without WhatsApp:

POST /bot/{bot_id}/chat
Content-Type: application/json

{
  "session_id": "unique-session-id",
  "message": "Hello, I need help with..."
}

This allows you to:

  • Build custom chat interfaces
  • Integrate with other platforms
  • Use the same AI logic across your application

Credential Management

For security, you can store API keys separately:

POST /credentials
{
  "name": "Gemini Production",
  "kind": "gemini",
  "api_key": "your-api-key"
}

Then reference by ID in bot configuration:

{
  "credential_id": "credential-uuid"
}