A complete multi-tenant SaaS platform for building and managing AI-powered WhatsApp bots with visual flow design, knowledge base integration, and agent inbox functionality.
- Multi-Tenant Architecture: Complete tenant isolation with subscription-based access
- Bot Builder: Create bots with flow-based conversation design
- AI Integration: Knowledge base-powered AI responses with customizable tone
- Agent Inbox: Human agents can take over conversations when needed
- Broadcast Campaigns: Send targeted messages to contact segments
- Analytics Dashboard: Track bot performance and usage metrics
- Webhook Integration: Connect with external services
- Public REST API: Programmatic access for sending messages
- Tenant management with custom branding
- User roles:
platform_admin,tenant_admin,agent,developer - Subscription plans with usage limits
- Usage tracking and quota enforcement
- Billing and invoice management
- Visual flow designer with multiple trigger types
- AI-powered responses with knowledge base search
- Conversation variables for context management
- Message templates with variable substitution
- Multiple WhatsApp channels per tenant
- Flow actions: send text, send media, ask questions, call AI, webhooks
- PHP: 7.0 or higher (compatible up to PHP 8.x)
- MySQL: 5.7 or higher
- Web Server: Apache or Nginx
- PHP Extensions: PDO, PDO_MySQL, mbstring, fileinfo
git clone <repository-url> ai-whatsapp-bot-builder
cd ai-whatsapp-bot-builderCopy the example environment file:
cp .env.example .envEdit .env and configure your database:
APP_URL=http://localhost
APP_DEBUG=true
DB_HOST=localhost
DB_PORT=3306
DB_NAME=ai_whatsapp_bot
DB_USER=root
DB_PASS=your_password
TIMEZONE=UTCCreate a MySQL database:
mysql -u root -pCREATE DATABASE ai_whatsapp_bot CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EXIT;Import the database schema with seed data:
mysql -u root -p ai_whatsapp_bot < database.sqlCreate a virtual host configuration:
<VirtualHost *:80>
ServerName whatsapp-bot.local
DocumentRoot /path/to/ai-whatsapp-bot-builder/public
<Directory /path/to/ai-whatsapp-bot-builder/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/whatsapp-bot-error.log
CustomLog ${APACHE_LOG_DIR}/whatsapp-bot-access.log combined
</VirtualHost>Enable Apache modules:
sudo a2enmod rewrite
sudo systemctl restart apache2server {
listen 80;
server_name whatsapp-bot.local;
root /path/to/ai-whatsapp-bot-builder/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}chmod -R 755 storage/uploads
chmod -R 755 storageOpen your browser and navigate to:
http://whatsapp-bot.local
Or your configured URL.
The database comes with pre-seeded demo accounts:
- Email: admin@platform.com
- Password: password
- Email: john@techcorp.com
- Password: password
- Email: sarah@techcorp.com
- Password: password
- Email: emma@marketingmasters.com
- Password: password
The platform provides a REST API for sending messages and receiving webhooks.
All API requests require an API key in the header:
X-API-Key: your_api_key_here
Generate API keys from: Settings → API Keys
Endpoint: POST /api/v1/send-message
Request:
{
"bot_id": 1,
"phone_number": "+15551234567",
"message": "Hello, I need help with pricing",
"contact_name": "John Doe"
}Response:
{
"success": true,
"conversation_id": 123,
"contact_id": 45,
"messages": [
{
"id": 789,
"type": "text",
"content": "Great! I can help you with pricing information..."
}
]
}Endpoint: POST /api/v1/webhook
Request (simulates incoming WhatsApp message):
{
"to_phone": "+15551234567",
"from_phone": "+15559876543",
"message": "Hello"
}Response:
{
"success": true
}/app
/controllers - Application controllers
/models - Database models
/views - View templates
/core - Core framework classes
/public
/assets
/css - Stylesheets
/js - JavaScript files
index.php - Application entry point
.htaccess - Apache rewrite rules
/config - Configuration files
/storage
/uploads - File uploads
/tests - Test files
/database.sql - Database schema
/README.md - This file
/.env.example - Example environment file
- Models: Handle database operations with tenant isolation
- Views: HTML templates with minimal PHP logic
- Controllers: Business logic and request handling
- Router: URL routing and dispatching
- CSRF Protection: All forms protected with CSRF tokens
- Password Hashing: bcrypt password hashing
- Prepared Statements: All database queries use PDO prepared statements
- Input Validation: Server-side validation for all user input
- Tenant Isolation: Strict data separation between tenants
- File Upload Validation: Type and size checking with MIME validation
Run the test suite:
php tests/AuthTest.php
php tests/TenantIsolationTest.php- Authentication Tests: User login, password verification
- Tenant Isolation Tests: Ensures proper data separation
- CRUD Tests: Basic model operations
- Subscription Tests: Quota enforcement and limits
-
Disable Debug Mode
- Set
APP_DEBUG=falsein.env
- Set
-
Secure Database Credentials
- Use strong passwords
- Restrict database user permissions
-
Configure SSL
- Use HTTPS in production
- Redirect HTTP to HTTPS
-
Set Proper Permissions
chmod -R 755 /path/to/project chmod -R 775 storage/uploads chown -R www-data:www-data /path/to/project
-
Optimize Performance
- Enable OPcache
- Configure MySQL query cache
- Use CDN for static assets
-
Backup Strategy
- Regular database backups
- Backup uploaded files
- Store backups off-site
-
Monitoring
- Set up error logging
- Monitor server resources
- Track application errors
The platform comes with 3 predefined plans:
- 1 Channel
- 2 Bots
- 500 Contacts
- 5,000 Messages/month
- 500MB Storage
- 3 Channels
- 10 Bots
- 5,000 Contacts
- 50,000 Messages/month
- 2GB Storage
- 10 Channels
- 50 Bots
- 50,000 Contacts
- 500,000 Messages/month
- 10GB Storage
- Create model in
/app/models/ - Create controller in
/app/controllers/ - Add routes in
/public/index.php - Create views in
/app/views/ - Update database schema
The bot engine is located in /app/core/BotEngine.php. You can:
- Add new flow action types
- Integrate with real AI services (OpenAI, Anthropic)
- Add custom trigger conditions
- Implement advanced NLP
Update the Channel model and bot engine to integrate with:
- WhatsApp Business API (Cloud API)
- Twilio
- MessageBird
- Other WhatsApp providers
Database connection error
- Verify database credentials in
.env - Ensure MySQL is running
- Check firewall settings
404 errors on all pages
- Enable mod_rewrite (Apache)
- Check
.htaccessfile exists - Verify DocumentRoot points to
/public
Permission denied errors
- Set correct folder permissions
- Ensure web server user owns files
Blank page / no errors
- Enable error reporting in PHP
- Check PHP error logs
- Set
APP_DEBUG=truein development
This is a demonstration project showcasing a complete SaaS architecture in pure PHP.
This project is provided as-is for educational and commercial use.
Built with:
- PHP 7.x - 8.x
- MySQL
- Vanilla JavaScript
- CSS3
AI WhatsApp Bot Builder - Build, Deploy, and Manage WhatsApp Bots at Scale