Skip to main content

What is WhatsApp RAG Bot?

WhatsApp RAG Bot is a powerful, self-hosted customer service automation platform that combines the convenience of WhatsApp messaging with advanced AI capabilities. Built with PHP and MySQL, it uses Retrieval-Augmented Generation (RAG) to provide intelligent, context-aware responses to customer inquiries.

Key Features

RAG-Powered Responses

Upload your documents (PDF, DOCX, TXT) and let the bot provide accurate answers based on your knowledge base using OpenAI embeddings and vector search.

Dual Bot Modes

Switch between AI Mode for intelligent responses and Classic Mode for rule-based conversation flows with predefined decision trees.

Audio Transcription

Automatically transcribe WhatsApp audio messages using OpenAI Whisper API, converting voice notes into text for processing.

Google Calendar Integration

Built-in appointment scheduling with automatic calendar management, business hours validation, and multi-step booking flows.

Conversation Management

Track all conversations with message history, AI confidence scores, human handoff capability, and real-time dashboard monitoring.

Self-Hosted & Secure

Complete control over your data. Encrypted credentials, signature validation, and runs on your infrastructure (cPanel/SiteGround compatible).

Architecture Overview

The WhatsApp RAG Bot uses a modern architecture designed for scalability and intelligence:

Core Components

1

Webhook Handler

The webhook.php file receives incoming messages from Meta’s WhatsApp Business API, validates signatures, and routes messages to the appropriate processing logic.
2

RAG Pipeline

Documents are chunked, embedded using OpenAI’s text-embedding-ada-002 model, and stored as vectors in MySQL. Queries are matched using cosine similarity for context retrieval.
3

Conversation Service

Manages conversation state, message history, AI enable/disable status, and human handoff workflows with full audit trails.
4

WhatsApp Service

Handles all Meta Graph API interactions: sending messages, downloading media, marking messages as read, and webhook verification.

Technology Stack

{
  "require": {
    "php": "^7.4 || ^8.0",
    "guzzlehttp/guzzle": "^7.0",
    "phpoffice/phpword": "^0.18",
    "smalot/pdfparser": "^0.18"
  }
}

Database

  • MySQL 5.7+ with utf8mb4 support
  • Vector embeddings stored as BLOB fields
  • Optimized indexes for similarity search
  • Full-text search capabilities

AI Models

  • GPT-3.5-turbo or GPT-4 for response generation
  • text-embedding-ada-002 for document vectorization (1536 dimensions)
  • Whisper API for audio transcription

Use Cases

Automatically answer frequently asked questions, provide product information, and escalate complex issues to human agents when needed.
Allow customers to book, reschedule, or cancel appointments directly through WhatsApp with automatic Google Calendar synchronization.
Upload your product manuals, policies, or documentation and let customers query information conversationally.
Use the flow builder to create interactive conversation trees that qualify leads and route them appropriately.

System Requirements

Before installation, ensure your server meets these minimum requirements:
  • PHP: 7.4 or higher (8.0+ recommended)
  • MySQL: 5.7+ or MariaDB 10.2+
  • Memory: 512MB minimum (1GB recommended)
  • Extensions: curl, json, mbstring, mysqli, zip, xml
  • Web Server: Apache with mod_rewrite or Nginx
  • SSL Certificate: Required for WhatsApp webhook

Getting Help

If you encounter issues or have questions:

Next Steps

Ready to get started? Follow our Quickstart Guide to get your bot running in minutes, or dive into the complete Installation Guide for a production-ready setup.

Quickstart

Get up and running with a basic setup in 10 minutes

Installation

Complete production installation guide with all configuration options

Build docs developers (and LLMs) love