Overview
This guide walks you through setting up the WhatsApp RAG Bot for local development. You’ll use PHP’s built-in server and ngrok for webhook testing.Prerequisites
Before starting, ensure you have:PHP 7.4+
With required extensions installed
Composer
For dependency management
MySQL 5.7+
Or MariaDB 10.2+
ngrok
For webhook testing (optional)
Installation Steps
Step 1: Clone the Repository
Step 2: Install Dependencies
Install Composer packages
guzzlehttp/guzzle- HTTP clientphpoffice/phpword- DOCX processingsmalot/pdfparser- PDF processing- PSR interfaces and dependencies
Step 3: Database Setup
Import the schema
What does schema.sql create?
What does schema.sql create?
The schema includes:
documents- Uploaded files for RAGvectors- Embeddings for semantic searchconversations- Chat sessionsmessages- Message historysettings- Bot configurationbot_credentials- API credentials (encrypted)flow_nodes- Classic bot flowscalendar_flow_state- Calendar booking sessions- And more…
Step 4: Environment Configuration
Step 5: Create Required Directories
Step 6: Start the Development Server
The project includes
router.php for use with PHP’s built-in server during development.What does router.php do?
What does router.php do?
From It serves static files directly and routes all other requests to
router.php:index.php.Step 7: Access the Admin Panel
Open your browser and navigate to:Webhook Setup for Local Testing
Meta requires a public HTTPS URL for webhooks. Use ngrok to expose your local server.
Install and Configure ngrok
Install ngrok
Download from ngrok.com or install via package manager:
Configure Meta Webhook
Open Meta Developer Console
Go to developers.facebook.com and open your WhatsApp app.
Configure webhook
Navigate to WhatsApp > Configuration > WebhookSet:
- Callback URL:
https://abc123.ngrok.io/webhook - Verify Token: Same as
WHATSAPP_VERIFY_TOKENin your.envfile
Testing the Bot
Send a Test Message
Send message from WhatsApp
Use your personal WhatsApp to send a message to your bot’s phone number.Example: “Hello, can you help me?”
Test Webhook Locally
Development Tips
Hot Reload
PHP’s built-in server doesn’t support auto-reload. Restart the server after code changes:
Debug Mode
Enable detailed logging:.env
Database Inspection
Upload Test Documents
- Navigate to admin panel:
http://localhost:8080 - Go to Documents section
- Upload PDF or DOCX files
- Bot will process them for RAG
Common Issues
Connection refused to MySQL
Connection refused to MySQL
Problem: Can’t connect to databaseSolution:
Webhook verification fails
Webhook verification fails
Problem: Meta can’t verify webhookSolution:
- Ensure ngrok is running
- Verify token matches exactly (case-sensitive)
- Check PHP server is running
- Review webhook.php:84-103 for verification logic
Autoloader not found
Autoloader not found
Problem:
vendor/autoload.php not foundSolution:Permission denied on logs/
Permission denied on logs/
Problem: Can’t write to logs directorySolution:
Next Steps
Production Deployment
Deploy to production server
Troubleshooting
Common issues and solutions