PHPackages                             renderbit/laravel-whatsapp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. renderbit/laravel-whatsapp

ActiveLibrary[Testing &amp; Quality](/categories/testing)

renderbit/laravel-whatsapp
==========================

Framework-agnostic PHP library for sending WhatsApp messages via Renderbit, with Laravel support.

1.1.0(1w ago)02.9kMITPHPPHP &gt;=8.1CI passing

Since Apr 16Pushed 1w ago3 watchersCompare

[ Source](https://github.com/RenderbitTechnologies/laravel-whatsapp)[ Packagist](https://packagist.org/packages/renderbit/laravel-whatsapp)[ Docs](https://github.com/renderbit/laravel-whatsapp)[ RSS](/packages/renderbit-laravel-whatsapp/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (10)Versions (5)Used By (0)

Laravel WhatsApp (renderbit/laravel-whatsapp)
=============================================

[](#laravel-whatsapp-renderbitlaravel-whatsapp)

[![Tests](https://github.com/RenderbitTechnologies/laravel-whatsapp/actions/workflows/tests.yml/badge.svg)](https://github.com/RenderbitTechnologies/laravel-whatsapp/actions/workflows/tests.yml)[![Packagist Version](https://camo.githubusercontent.com/8b55d9b1d236ff39545b5229f0055615fcc8a28786af30190b7cb3bfe1c0c8ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656e6465726269742f6c61726176656c2d77686174736170703f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/renderbit/laravel-whatsapp)[![License](https://camo.githubusercontent.com/9fdd7e99e2ba774b0b9a99dcced88610a6f0538eaa4fba07a9bfeab009133cd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72656e6465726269742f6c61726176656c2d77686174736170703f6c6f676f3d6f70656e736f75726365696e6974696174697665)](https://github.com/RenderbitTechnologies/laravel-whatsapp/blob/main/LICENSE)[![PHP](https://camo.githubusercontent.com/29147a418f0dc92a7f3491fdb743b59b5ec45ea5d36889b2a68a403f22a3ca08/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e312d3737374242343f6c6f676f3d706870)](https://camo.githubusercontent.com/29147a418f0dc92a7f3491fdb743b59b5ec45ea5d36889b2a68a403f22a3ca08/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e312d3737374242343f6c6f676f3d706870)[![Laravel](https://camo.githubusercontent.com/59f312f34c663004eef0059fab56cf5ae4fa7ca6c49c3535ff5c12e694203e30/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313025323025374325323031312d4646324432303f6c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/59f312f34c663004eef0059fab56cf5ae4fa7ca6c49c3535ff5c12e694203e30/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313025323025374325323031312d4646324432303f6c6f676f3d6c61726176656c)

A **framework-agnostic**, Laravel-ready PHP package for sending template-based WhatsApp messages via the Renderbit WhatsApp API.

🚀 Features
----------

[](#-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
--------------

[](#-installation)

```
composer require renderbit/laravel-whatsapp
```

### Requirements

[](#requirements)

DependencyVersionPHP&gt;= 8.1Laravel (optional)10.x | 11.xguzzlehttp/guzzle^7.9illuminate/support^10.0 | ^11.0psr/log^1.1 | ^2.0 | ^3.0psr/simple-cache^1.0 | ^2.0 | ^3.0⚙️ Laravel Setup
----------------

[](#️-laravel-setup)

> **Note:** This package uses [Laravel auto-discovery](https://laravel.com/docs/packages#package-discovery), so the service provider is registered automatically. No manual registration needed.

### 1. Publish Config (optional)

[](#1-publish-config-optional)

```
php artisan vendor:publish --tag=whatsapp-config
```

This publishes the config file and routes to your application:

- `config/whatsapp.php` — configuration values
- `routes/vendor/whatsapp-api.php` — DLR webhook route

### 2. Environment Configuration

[](#2-environment-configuration)

Add these to your `.env`:

```
WHATSAPP_API_BASE_URL=https://your-api-base-url.com
WHATSAPP_API_KEY=your-api-key
WHATSAPP_BUSINESS_NUMBER=918888888888
WHATSAPP_USERNAME=your-username
WHATSAPP_OLD_TOKEN=previous-token-if-refreshing
```

### Configuration Reference (`config/whatsapp.php`)

[](#configuration-reference-configwhatsappphp)

KeyEnv VariableDescription`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
-------

[](#-usage)

### In Laravel

[](#in-laravel)

#### Via Dependency Injection

[](#via-dependency-injection)

```
use Renderbit\LaravelWhatsapp\WhatsappClient;

class MessageController extends Controller
{
    public function send(WhatsappClient $whatsapp)
    {
        $response = $whatsapp->sendMessage(
            '919876543210',        // Phone number (no special chars)
            '1043144443',          // Template ID
            ['John Doe', '1500']   // Template parameters
        );

        if ($response['success']) {
            return back()->with('success', 'Message sent!');
        }

        return back()->with('error', $response['message']);
    }
}
```

#### Via Facade

[](#via-facade)

```
use Renderbit\LaravelWhatsapp\Facades\Whatsapp;

$response = Whatsapp::sendMessage('919876543210', '1043144443', ['Jane', '2500']);
```

#### Via `app()` Helper

[](#via-app-helper)

```
$response = app('whatsapp')->sendMessage('919876543210', '1043144443', ['Jane', '2500']);
```

#### Response Format

[](#response-format)

All `sendMessage()` calls return a uniform response array:

```
// Success
['success' => true,  'message' => 'Message delivered successfully.']

// Failure (authentication)
['success' => false, 'message' => 'Authentication token unavailable.']

// Failure (API error code)
['success' => false, 'message' => 'Invalid phone number'] // ErrorCodes::MAP[10001]

// Failure (HTTP/network error)
['success' => false, 'message' => 'API request failed. Check logs for details.']
```

### In Standalone PHP

[](#in-standalone-php)

```
use Renderbit\LaravelWhatsapp\WhatsappClient;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$logger = new Logger('whatsapp');
$logger->pushHandler(new StreamHandler('php://stdout'));
$cache = new FilesystemAdapter('whatsapp', 0, '/tmp/cache');

$client = new WhatsappClient([
    'api_base_url' => 'https://your-api-base-url.com',
    'api_key' => 'your-api-key',
    'whatsapp_business_number' => '918888888888',
    'whatsapp_username' => 'your-username',
    'old_token' => null,
], $logger, $cache);

$response = $client->sendMessage('919876543210', '1043144443', ['Alice', '3000']);
```

🔐 Token Management
------------------

[](#-token-management)

The `TokenManager` class handles all authentication token lifecycle automatically.

MethodDescription`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:**

1. `getToken()` checks PSR-16 cache for a valid (non-expired) token
2. If cached and valid, returns immediately
3. If expired or missing, calls `generateToken()` which requests a new token from the API
4. The new token and its expiry are stored in cache with the correct TTL (in seconds)
5. On HTTP 401 responses, `WhatsappClient::sendRequest()` automatically triggers `refreshToken()`

You can swap the cache backend to Redis, APCu, database, or any PSR-16 implementation.

📡 DLR Webhook
-------------

[](#-dlr-webhook)

The package registers a POST route for delivery reports:

```
POST /whatsapp/dlr

```

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:

```
// Don't publish routes — override in your app's RouteServiceProvider
```

🗺 Error Code Reference
----------------------

[](#-error-code-reference)

The package ships with **51 mapped error codes** in `Renderbit\LaravelWhatsapp\Constants\ErrorCodes`:

CodeMessage28694Invalid template parameters10001Invalid phone number52992Username / Password incorrect52995Daily Credit limit Reached57089Contract expired57090User credit expired57091User disabled65280Service is temporarily unavailable65535Message does not conform to DTD28673–28704Validation errors (destination, sender, template, etc.)2009–2026Template format errors9988Unknown failure38679–65536Campaign and system errorsYou can customize messages by extending or modifying the `ErrorCodes::MAP` array.

🧪 Testing
---------

[](#-testing)

```
composer install
vendor/bin/phpunit
```

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

[](#ci-matrix)

The package is tested via GitHub Actions across 6 configurations:

PHPLaravel8.1108.2108.2118.3108.3118.411📁 Project Structure
-------------------

[](#-project-structure)

```
renderbit/laravel-whatsapp
├── config/
│   └── whatsapp.php             # Package configuration
├── routes/
│   └── api.php                  # DLR webhook route
├── src/
│   ├── Constants/
│   │   └── ErrorCodes.php       # 51 API error code mappings
│   ├── Facades/
│   │   └── Whatsapp.php         # Laravel facade
│   ├── Http/
│   │   └── Controllers/
│   │       └── WhatsAppDLRController.php  # DLR webhook handler
│   ├── TokenManager.php         # Token lifecycle (cache/generate/refresh)
│   ├── WhatsappClient.php       # Main API client
│   └── WhatsappServiceProvider.php  # Laravel service provider
├── tests/
│   ├── TestCase.php             # Base test case (Mockery)
│   ├── LaravelTestCase.php      # Base test case (Orchestra Testbench)
│   ├── ErrorCodesTest.php
│   ├── TokenManagerTest.php
│   ├── WhatsappClientTest.php
│   ├── WhatsAppDLRControllerTest.php
│   ├── WhatsappFacadeTest.php
│   └── WhatsappServiceProviderTest.php
├── .github/workflows/
│   └── tests.yml                # CI/CD workflow
├── composer.json
├── phpunit.xml.dist
└── README.md

```

🧩 Extending &amp; Customization
-------------------------------

[](#-extending--customization)

- **Error messages** — Modify `src/Constants/ErrorCodes.php` to localize or customize API error messages
- **Cache backend** — The PSR-16 `CacheInterface` can be swapped for Redis, APCu, Memcached, or any compliant adapter
- **Logger** — The PSR-3 `LoggerInterface` supports Monolog, Loggly, Laravel's Log facade, etc.
- **DLR handling** — Extend `WhatsAppDLRController` to implement custom delivery report logic (store in DB, forward to webhook, etc.)
- **HTTP client** — `GuzzleHttp\Client` is used internally; customize timeouts/headers in `WhatsappClient::__construct()`

🤝 Contributing
--------------

[](#-contributing)

1. Fork the repository
2. Install dependencies: `composer install`
3. Write/run tests: `vendor/bin/phpunit`
4. Submit a pull request

Please ensure all tests pass and maintain at least the current coverage level.

📄 License
---------

[](#-license)

MIT © [Renderbit Technologies](https://github.com/RenderbitTechnologies/laravel-whatsapp)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance98

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~218 days

Total

3

Last Release

8d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16665819?v=4)[Renderbit Technologies](/maintainers/renderbit-technologies)[@renderbit-technologies](https://github.com/renderbit-technologies)

---

Top Contributors

[![soham2008xyz](https://avatars.githubusercontent.com/u/7334295?v=4)](https://github.com/soham2008xyz "soham2008xyz (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![AdityaVJ](https://avatars.githubusercontent.com/u/21195870?v=4)](https://github.com/AdityaVJ "AdityaVJ (6 commits)")

---

Tags

composer-packagegithub-actionslaravel-packagepackagistphp8phpunitwhatsapp-apiapilaravelmessagingwhatsapprenderbit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/renderbit-laravel-whatsapp/health.svg)

```
[![Health](https://phpackages.com/badges/renderbit-laravel-whatsapp/health.svg)](https://phpackages.com/packages/renderbit-laravel-whatsapp)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[nutgram/nutgram

The Telegram bot library that doesn't drive you nuts

737290.3k8](/packages/nutgram-nutgram)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
