kiran99 / laravel-whatsapp
A Laravel package for sending WhatsApp messages using the WhatsApp Cloud API.
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0||^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A simple Laravel package for sending WhatsApp messages using the official WhatsApp Cloud API.
Features
- Send text messages
- Send template messages
- Easy environment-based configuration
- Dedicated exceptions for API and configuration errors
Requirements
- PHP 8.3+
- Laravel 11, 12, or 13, according to the package's Composer constraints
- A Meta developer app configured with WhatsApp Cloud API access
Installation
Install the package via Composer:
composer require kiran99/laravel-whatsapp
Publish the configuration file:
php artisan vendor:publish --tag=laravel-whatsapp-config
Configuration
Add your credentials to the .env file:
WHATSAPP_ACCESS_TOKEN=your_access_token WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id WHATSAPP_API_VERSION=v22.0
Replace the example values with your actual Meta credentials and a supported Graph API version.
Usage
Import the facade:
use kiran99\LaraWhatsApp\Facades\WhatsApp;
Send a text message
$response = WhatsApp::sendText( '919876543210', 'Hello from Laravel!' );
Send a template message
$response = WhatsApp::sendTemplate( '919876543210', 'order_ready', 'en_US', ['Kiran', 'ORD-1001'] );
Use an approved template name, its configured language code, and parameters matching the template body.
Phone numbers should use international format with digits only, without spaces or a leading +.
Error Handling
The package provides two exceptions:
WhatsAppConfigurationException— missing or invalid configuration.WhatsAppException— WhatsApp API or request errors.
use kiran99\LaraWhatsApp\Exceptions\WhatsAppException; use kiran99\LaraWhatsApp\Exceptions\WhatsAppConfigurationException; try { $response = WhatsApp::sendText( '919876543210', 'Hello from Laravel!' ); } catch (WhatsAppConfigurationException | WhatsAppException $e) { report($e); }
Security
Keep your access token private. Never commit your .env file or API credentials to version control.
License
This package is open-sourced software licensed under the MIT license.