laravel-whatsapp maintained by kiran99
Laravel WhatsApp
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.