hatem-elsheref / whatsapp-business
WhatsApp Business SaaS Platform for Laravel - Multi-tenant, OAuth, WhatsApp Cloud API integration
Package info
github.com/hatem-elsheref/whatsapp-business
pkg:composer/hatem-elsheref/whatsapp-business
1.0.7
2026-03-29 20:20 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.8
- laravel/framework: ^10.0|^11.0|^12.0
- laravel/sanctum: ^4.0
- pusher/pusher-php-server: ^7.2
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
A comprehensive WhatsApp Business SaaS package for Laravel with multi-tenant support, OAuth authentication, conversation management, and more.
Installation
- Add the package to your Laravel project:
composer require hatem-elsheref/whatsapp-business
- Run migrations (migrations run automatically):
php artisan migrate
- Seed default admin user (optional):
php artisan db:seed --class=WhatsAppBusinessSeeder
Configuration
- Publish the configuration:
php artisan vendor:publish --tag=whatsapp-config
- Add these environment variables to your
.envfile:
# Meta/WhatsApp Cloud API META_APP_ID=your_app_id META_APP_SECRET=your_app_secret META_API_VERSION=v18.0 META_OAUTH_REDIRECT_URI=https://yourapp.com/api/wa/oauth/callback # Webhook WA_WEBHOOK_VERIFY_TOKEN=your_random_verify_token # Pusher (for real-time notifications) PUSHER_APP_ID=your_app_id PUSHER_APP_KEY=your_app_key PUSHER_APP_SECRET=your_app_secret PUSHER_CLUSTER=mt1
Features
- Multi-Tenant Architecture: Each customer has their own isolated data
- Facebook OAuth: Customers connect via Facebook Login
- Manual Setup: Enter App ID, App Secret, and Access Token directly
- Multi-Number Support: Connect multiple WhatsApp numbers
- Conversation Management: Full inbox system with assignment
- Template Messages: Send WhatsApp-approved templates
- Conversation Flows: Build automated flows with triggers
- Ticketing System: Convert conversations to support tickets
- Analytics Dashboard: Track messages, conversations, agent performance
- Real-time Updates: Via Pusher/Laravel Echo
- Agent Management: Multi-agent support with roles
API Endpoints
Public Endpoints
GET /api/wa/webhook- Webhook verificationPOST /api/wa/webhook- Handle incoming messagesGET /api/wa/oauth/redirect- Redirect to Facebook OAuthGET /api/wa/oauth/callback- OAuth callbackPOST /api/wa/oauth/manual-setup- Manual setup with access token
Protected Endpoints (require Sanctum token)
Auth
POST /api/wa/auth/login- LoginPOST /api/wa/auth/logout- LogoutGET /api/wa/auth/me- Get current user
Conversations
GET /api/wa/conversations- List conversationsGET /api/wa/conversations/{id}- Get conversationGET /api/wa/conversations/{id}/messages- Get messagesPOST /api/wa/conversations/{id}/messages- Send messagePOST /api/wa/conversations/{id}/assign- Assign agentPOST /api/wa/conversations/{id}/archive- ArchivePOST /api/wa/conversations/{id}/block- Block
Templates
GET /api/wa/templates- List templatesGET /api/wa/templates/sync- Sync from MetaGET /api/wa/templates/{id}- Get templatePOST /api/wa/templates/{id}/send- Send template
Phone Numbers
GET /api/wa/phone-numbers- List numbersGET /api/wa/phone-numbers/sync- Sync from MetaGET /api/wa/phone-numbers/{id}- Get numberPOST /api/wa/phone-numbers/{id}/webhook/test- Test webhookDELETE /api/wa/phone-numbers/{id}- Remove number
Quick Replies
GET /api/wa/quick-replies- List quick repliesPOST /api/wa/quick-replies- CreatePUT /api/wa/quick-replies/{id}- UpdateDELETE /api/wa/quick-replies/{id}- Delete
Flows
GET /api/wa/flows- List flowsPOST /api/wa/flows- Create flowGET /api/wa/flows/{id}- Get flowPUT /api/wa/flows/{id}- Update flowDELETE /api/wa/flows/{id}- Delete flowPOST /api/wa/flows/{id}/toggle- Enable/disablePOST /api/wa/flows/{id}/steps- Update steps
Tickets
GET /api/wa/tickets- List ticketsPOST /api/wa/tickets- Create ticketGET /api/wa/tickets/{id}- Get ticketPUT /api/wa/tickets/{id}- Update ticketPOST /api/wa/tickets/{id}/assign- Assign agentPOST /api/wa/tickets/{id}/resolve- Resolve ticketPOST /api/wa/tickets/{id}/close- Close ticket
Agents
GET /api/wa/agents- List agentsPOST /api/wa/agents- Create agentPUT /api/wa/agents/{id}- Update agentDELETE /api/wa/agents/{id}- Delete agent
Notifications
GET /api/wa/notifications- List notificationsPUT /api/wa/notifications/{id}/read- Mark as readPUT /api/wa/notifications/read-all- Mark all as read
Analytics
GET /api/wa/analytics/overview- Dashboard overviewGET /api/wa/analytics/messages- Message statsGET /api/wa/analytics/conversations- Conversation statsGET /api/wa/analytics/agents- Agent performance
Usage
Sending a Message
use WhatsApp\Business\Services\ConversationService; $service = app(ConversationService::class); $message = $service->sendMessage( $conversation, 'Hello, how can I help you?', $agentId );
Starting a Flow
use WhatsApp\Business\Services\FlowEngine; $flowEngine = app(FlowEngine::class); $flowEngine->startFlow($flow, $conversation);
Manual Setup (Without OAuth)
use WhatsApp\Business\Services\OAuthService; $service = app(OAuthService::class); $result = $service->manualSetup($customerId, [ 'app_id' => 'your_app_id', 'app_secret' => 'your_app_secret', 'access_token' => 'your_permanent_access_token', ]);
Broadcasting (Real-time)
The package includes Laravel Echo compatible broadcasting channels:
Channel Structure
whatsapp.customer.{id}- Customer-specific eventswhatsapp.conversation.{id}- Conversation updateswhatsapp.agent.{id}- Agent notifications
Frontend Integration
import Echo from 'laravel-echo'; import Pusher from 'pusher-js'; window.Echo = new Echo({ broadcaster: 'pusher', key: import.meta.env.VITE_PUSHER_APP_KEY, cluster: import.meta.env.VITE_PUSHER_CLUSTER, }); Echo.private(`whatsapp.agent.${agentId}`) .listen('message.new', (e) => { console.log('New message:', e.message); }) .listen('notification.new', (e) => { console.log('New notification:', e.notification); });
Database Tables
The package creates the following tables:
wa_customers- Customer accountswa_agents- Agent accountswa_phone_numbers- WhatsApp phone numberswa_templates- Message templateswa_quick_replies- Quick reply messageswa_flows- Automated conversation flowswa_flow_steps- Flow stepswa_flow_user_data- User flow progresswa_conversations- Customer conversationswa_messages- Messageswa_tickets- Support ticketswa_ticket_messages- Ticket messageswa_notifications- Notificationswa_analytics_events- Analytics events
Default Credentials
After seeding:
- Admin:
admin@whatsapp.local/admin123 - Agent:
agent@whatsapp.local/agent123
Testing
composer test
Or with Orchestra Testbench:
vendor/bin/phpunit
Auto-Discovery
Laravel 5.5+ auto-discovers the service providers. No manual registration needed.
License
MIT License