Download the PHP package renderbit/laravel-whatsapp without Composer
On this page you can find all versions of the php package renderbit/laravel-whatsapp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-whatsapp
Laravel WhatsApp (renderbit/laravel-whatsapp)
A framework-agnostic, Laravel-ready PHP package for sending template-based WhatsApp messages via the Renderbit WhatsApp API.
๐ Features
- โ Works with Laravel 10/11, Symfony, Slim, or any PHP 8.1+ app
- ๐ PSR-16 token caching โ automatic token generation, caching, and refresh with configurable TTL
- ๐ Template-based messaging โ pass template IDs with dynamic parameters
- ๐ง 51 built-in error codes โ maps API error codes to human-readable messages
- ๐งฐ PSR-compliant โ PSR-3 logging, PSR-16 caching, PSR-4 autoloading
- ๐ก DLR endpoint โ built-in delivery report webhook route
- ๐งช 100% test coverage โ PHPUnit test suite with CI on 6 matrix configurations
- ๐ Laravel auto-discovery โ service provider auto-registers, facade ready to use
๐ฆ Installation
Requirements
| Dependency | Version |
|---|---|
| PHP | >= 8.1 |
| Laravel (optional) | 10.x | 11.x |
| guzzlehttp/guzzle | ^7.9 |
| illuminate/support | ^10.0 | ^11.0 |
| psr/log | ^1.1 | ^2.0 | ^3.0 |
| psr/simple-cache | ^1.0 | ^2.0 | ^3.0 |
โ๏ธ Laravel Setup
Note: This package uses Laravel auto-discovery, so the service provider is registered automatically. No manual registration needed.
1. Publish Config (optional)
This publishes the config file and routes to your application:
config/whatsapp.phpโ configuration valuesroutes/vendor/whatsapp-api.phpโ DLR webhook route
2. Environment Configuration
Add these to your .env:
Configuration Reference (config/whatsapp.php)
| Key | Env Variable | Description |
|---|---|---|
api_base_url |
WHATSAPP_API_BASE_URL |
Base URL for the Renderbit WhatsApp API |
api_key |
WHATSAPP_API_KEY |
API key for authentication |
whatsapp_business_number |
WHATSAPP_BUSINESS_NUMBER |
Business phone number (sender) |
whatsapp_username |
WHATSAPP_USERNAME |
Username for the API |
old_token |
WHATSAPP_OLD_TOKEN |
Previous token (used during token refresh) |
๐งฑ Usage
In Laravel
Via Dependency Injection
Via Facade
Via app() Helper
Response Format
All sendMessage() calls return a uniform response array:
In Standalone PHP
๐ Token Management
The TokenManager class handles all authentication token lifecycle automatically.
| Method | Description |
|---|---|
getToken() |
Returns a valid token from cache or generates a new one |
refreshToken() |
Forces a token refresh using the old token |
manageToken('enable' \| 'disable' \| 'delete', $token) |
Manages token state |
How it works:
getToken()checks PSR-16 cache for a valid (non-expired) token- If cached and valid, returns immediately
- If expired or missing, calls
generateToken()which requests a new token from the API - The new token and its expiry are stored in cache with the correct TTL (in seconds)
- On HTTP 401 responses,
WhatsappClient::sendRequest()automatically triggersrefreshToken()
You can swap the cache backend to Redis, APCu, database, or any PSR-16 implementation.
๐ก DLR Webhook
The package registers a POST route for delivery reports:
The WhatsAppDLRController::receiveDLR() handler logs incoming delivery reports via Laravel's Log::info() and responds with {"status": "success"}.
To customize, extend the controller or disable the routes and define your own:
๐บ Error Code Reference
The package ships with 51 mapped error codes in Renderbit\LaravelWhatsapp\Constants\ErrorCodes:
| Code | Message |
|---|---|
| 28694 | Invalid template parameters |
| 10001 | Invalid phone number |
| 52992 | Username / Password incorrect |
| 52995 | Daily Credit limit Reached |
| 57089 | Contract expired |
| 57090 | User credit expired |
| 57091 | User disabled |
| 65280 | Service is temporarily unavailable |
| 65535 | Message does not conform to DTD |
| 28673โ28704 | Validation errors (destination, sender, template, etc.) |
| 2009โ2026 | Template format errors |
| 9988 | Unknown failure |
| 38679โ65536 | Campaign and system errors |
You can customize messages by extending or modifying the ErrorCodes::MAP array.
๐งช Testing
The test suite covers:
- WhatsappClient โ message sending, error handling, HTTP failures, token exhaustion
- TokenManager โ cache hit/miss, token generation, refresh, invalid actions
- WhatsAppDLRController โ DLR endpoint acceptance
- WhatsappServiceProvider โ config merge, singleton binding, facade alias, publishable tags
- Whatsapp Facade โ accessor resolution
- ErrorCodes โ all 51 error codes validated
CI Matrix
The package is tested via GitHub Actions across 6 configurations:
| PHP | Laravel |
|---|---|
| 8.1 | 10 |
| 8.2 | 10 |
| 8.2 | 11 |
| 8.3 | 10 |
| 8.3 | 11 |
| 8.4 | 11 |
๐ Project Structure
๐งฉ Extending & Customization
- Error messages โ Modify
src/Constants/ErrorCodes.phpto localize or customize API error messages - Cache backend โ The PSR-16
CacheInterfacecan be swapped for Redis, APCu, Memcached, or any compliant adapter - Logger โ The PSR-3
LoggerInterfacesupports Monolog, Loggly, Laravel's Log facade, etc. - DLR handling โ Extend
WhatsAppDLRControllerto implement custom delivery report logic (store in DB, forward to webhook, etc.) - HTTP client โ
GuzzleHttp\Clientis used internally; customize timeouts/headers inWhatsappClient::__construct()
๐ค Contributing
- Fork the repository
- Install dependencies:
composer install - Write/run tests:
vendor/bin/phpunit - Submit a pull request
Please ensure all tests pass and maintain at least the current coverage level.
๐ License
MIT ยฉ Renderbit Technologies
All versions of laravel-whatsapp with dependencies
guzzlehttp/guzzle Version ^7.9
illuminate/support Version ^10.0 || ^11.0
psr/log Version ^1.1 || ^2.0 || ^3.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0