Skip to main content

Get Started in 10 Minutes

This quickstart guide will help you set up a fully functional WhatsApp bot with AI-powered responses in just a few steps.

Prerequisites

Before you begin, make sure you have:
  • PHP 7.4 or higher installed
  • MySQL 5.7+ database
  • A WhatsApp Business API account
  • An OpenAI API key
  • Composer for dependency management

Step 1: Clone and Install

1

Clone the repository

git clone https://github.com/JorgeForero02/Bot-whatsapp-php.git
cd Bot-whatsapp-php
2

Install dependencies

composer install
3

Set up the database

Create a MySQL database and import the schema:
mysql -u your_user -p your_database < database/schema.sql

Step 2: Configure Environment

Create a .env file or configure config/config.php with your credentials:
config/config.php
return [
    'database' => [
        'host' => 'localhost',
        'dbname' => 'whatsapp_rag_bot',
        'user' => 'your_db_user',
        'password' => 'your_db_password'
    ],
    'whatsapp' => [
        'phone_number_id' => 'YOUR_PHONE_NUMBER_ID',
        'access_token' => 'YOUR_WHATSAPP_ACCESS_TOKEN',
        'verify_token' => 'YOUR_VERIFY_TOKEN',
        'app_secret' => 'YOUR_APP_SECRET'
    ],
    'openai' => [
        'api_key' => 'YOUR_OPENAI_API_KEY',
        'model' => 'gpt-4o-mini',
        'embedding_model' => 'text-embedding-ada-002'
    ]
];
See Configuration Guide for detailed setup instructions.

Step 3: Set Up WhatsApp Webhook

1

Expose your local server

For local development, use ngrok to expose your server:
ngrok http 8000
Copy the HTTPS URL provided (e.g., https://abc123.ngrok.io)
2

Configure webhook in Meta

  1. Go to Meta Developer Console
  2. Navigate to your WhatsApp app > Configuration > Webhook
  3. Set callback URL: https://your-domain.com/webhook
  4. Set verify token: Match what you set in config
  5. Subscribe to messages webhook field
3

Verify webhook

Meta will send a GET request to verify. Your bot will automatically respond if configured correctly.

Step 4: Upload Knowledge Base

Upload documents to power your RAG system:
curl -X POST http://localhost:8000/api/upload \
  -F "document=@path/to/your/document.pdf"
The system will automatically:
  • Extract text from PDF, DOCX, or TXT files
  • Split into chunks for RAG processing
  • Generate embeddings using OpenAI
  • Store vectors in MySQL database

Step 5: Test Your Bot

Send a message to your WhatsApp number and watch your bot respond!
User: What are your business hours?
Bot: [AI-powered response based on your uploaded documents]

Next Steps

Configure System Settings

Customize bot personality and behavior

Set Up Calendar

Enable appointment scheduling

Build Custom Flows

Create rule-based conversation flows

View API Reference

Explore the complete API documentation

Troubleshooting

  • Ensure your verify token matches in both config and Meta console
  • Check that your webhook URL is publicly accessible
  • Verify SSL certificate is valid
  • Check webhook logs in logs/ directory
  • Verify WhatsApp credentials are correct
  • Ensure OpenAI API key has sufficient quota
  • Test database connection
  • Upload more relevant documents
  • Adjust confidence threshold in settings
  • Check document processing in database vectors table

Need more help?

Check the complete troubleshooting guide

Build docs developers (and LLMs) love