PHPackages                             amsaid/larawhat - 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. [API Development](/categories/api)
4. /
5. amsaid/larawhat

ActiveLibrary[API Development](/categories/api)

amsaid/larawhat
===============

A Laravel package for the WhatsApp Cloud API — send messages, manage templates, handle webhooks, and more.

00PHP

Since Apr 24Pushed 1mo agoCompare

[ Source](https://github.com/amsaid/larawhat)[ Packagist](https://packagist.org/packages/amsaid/larawhat)[ RSS](/packages/amsaid-larawhat/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Larawhat — WhatsApp Cloud API for Laravel
=========================================

[](#larawhat--whatsapp-cloud-api-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/04878e03c26df7e0d42c9b1c81fd15b2076c6157fe9d5c64a68fb6d8f0ce719b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d736169642f6c617261776861742e737667)](https://packagist.org/packages/amsaid/larawhat)[![PHP Version](https://camo.githubusercontent.com/dda8df66a4c5e98de23a1d0df014697e5da56cfd15a66286bf09fac3c19920e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616d736169642f6c617261776861742e737667)](https://php.net)[![Laravel](https://camo.githubusercontent.com/977ed8891f0c3f376e098db6a13fd1aa413d5d0c4e380d9a550a475e52696470/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3131253230253743253230313225323025374325323031332d7265642e737667)](https://laravel.com)

A Laravel package for the **WhatsApp Cloud API** (Meta). Send messages, manage templates, handle incoming webhooks, and control your business profile — all with a clean, fluent Laravel interface.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.x, 12.x, or 13.x

Installation
------------

[](#installation)

```
composer require amsaid/larawhat
```

Publish the configuration file:

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

Configuration
-------------

[](#configuration)

Set these environment variables in your `.env` file:

```
WHATSAPP_ACCESS_TOKEN=EAAT...
WHATSAPP_PHONE_NUMBER_ID=123456789
WHATSAPP_BUSINESS_ACCOUNT_ID=987654321
WHATSAPP_WEBHOOK_VERIFY_TOKEN=my-verify-token
WHATSAPP_API_VERSION=v22.0
```

VariableDescriptionRequired`WHATSAPP_ACCESS_TOKEN`Permanent or temporary access token from Meta Developer Console✅`WHATSAPP_PHONE_NUMBER_ID`ID of the phone number sending messages✅`WHATSAPP_BUSINESS_ACCOUNT_ID`WABA ID (needed for templates &amp; phone number management)For some endpoints`WHATSAPP_WEBHOOK_VERIFY_TOKEN`Token to verify your webhook in Meta ConsoleFor webhooks`WHATSAPP_API_VERSION`API version (defaults to `v22.0`)❌`WHATSAPP_WEBHOOK_PATH`Webhook URI path (defaults to `/api/whatsapp/webhook`)❌### Webhook setup

[](#webhook-setup)

In the [Meta Developer Console](https://developers.facebook.com/), configure your webhook callback URL:

```
https://your-app.com/api/whatsapp/webhook

```

Use the same `WHATSAPP_WEBHOOK_VERIFY_TOKEN` value. The route is auto-registered and handles both the GET verification challenge and POST event delivery.

Usage
-----

[](#usage)

### Facade

[](#facade)

```
use Larawhat\Facades\Larawhat;
```

### Send a text message

[](#send-a-text-message)

```
Larawhat::sendText('+1234567890', 'Hello from Laravel!');
```

With URL preview:

```
Larawhat::sendText('+1234567890', 'Check this out: https://example.com', previewUrl: true);
```

### Using message objects

[](#using-message-objects)

```
use Larawhat\Messages\TextMessage;

$message = new TextMessage('Hello via message object!');
$response = Larawhat::sendMessage($message, '+1234567890');
```

### Send media

[](#send-media)

```
use Larawhat\Messages\MediaMessage;

// By media ID (upload first)
Larawhat::sendMessage(
    MediaMessage::fromId('media-id-here', 'image', 'Nice photo!'),
    '+1234567890',
);

// By URL
Larawhat::sendMessage(
    MediaMessage::fromUrl('https://example.com/photo.jpg', 'image', 'Check this out'),
    '+1234567890',
);
```

### Send a template

[](#send-a-template)

```
use Larawhat\Messages\TemplateMessage;

$message = (new TemplateMessage('hello_world', 'en_US'))
    ->addBodyParameter('John');

Larawhat::sendMessage($message, '+1234567890');
```

### Interactive messages

[](#interactive-messages)

**Buttons:**

```
use Larawhat\Messages\InteractiveMessage;

$message = InteractiveMessage::buttons(
    body: 'Would you like to proceed?',
    buttons: [
        ['id' => 'yes', 'title' => '✅ Yes'],
        ['id' => 'no', 'title' => '❌ No'],
    ],
    header: 'Confirm Action',
    footer: 'Powered by Larawhat',
);

Larawhat::sendMessage($message, '+1234567890');
```

**List:**

```
$message = InteractiveMessage::list(
    body: 'Select an option:',
    buttonText: 'View Options',
    sections: [
        [
            'title' => 'Categories',
            'rows' => [
                ['id' => 'support', 'title' => 'Support', 'description' => 'Get help'],
                ['id' => 'sales', 'title' => 'Sales', 'description' => 'Talk to sales'],
            ],
        ],
    ],
    header: 'Menu',
    footer: 'Choose wisely',
);

Larawhat::sendMessage($message, '+1234567890');
```

### Send location

[](#send-location)

```
use Larawhat\Messages\LocationMessage;

$message = new LocationMessage(48.8566, 2.3522, 'Paris', 'France');
Larawhat::sendMessage($message, '+1234567890');
```

### Send contact

[](#send-contact)

```
use Larawhat\Messages\ContactsMessage;

$message = (new ContactsMessage)
    ->addPerson('John Doe', '+11234567890', '1234567890');

Larawhat::sendMessage($message, '+1234567890');
```

### Mark message as read

[](#mark-message-as-read)

```
Larawhat::markAsRead('wamid.message-id-here');
```

### Media management

[](#media-management)

```
// Upload a file
$response = Larawhat::uploadMedia(storage_path('app/photos/photo.jpg'), 'image/jpeg');
$mediaId = $response->json('id');

// Get media metadata
$media = Larawhat::getMedia($mediaId);

// Download media
$file = Larawhat::downloadMedia($mediaId);
Storage::put('downloads/photo.jpg', $file->body());

// Delete media
Larawhat::deleteMedia($mediaId);
```

### Business profile

[](#business-profile)

```
// Get profile
$profile = Larawhat::businessProfile();

// Update profile
Larawhat::updateBusinessProfile([
    'about' => 'We are open 9-5.',
    'description' => 'Your friendly neighbourhood business.',
    'websites' => ['https://example.com'],
]);
```

### Phone numbers

[](#phone-numbers)

```
// List all phone numbers
$numbers = Larawhat::phoneNumbers();

// Get specific phone number
$number = Larawhat::phoneNumber('123456789');
```

### Message templates

[](#message-templates)

```
// List templates
$templates = Larawhat::templates();

// Create a template
Larawhat::createTemplate([
    'name' => 'order_confirmation',
    'language' => 'en_US',
    'category' => 'UTILITY',
    'components' => [
        [
            'type' => 'BODY',
            'text' => 'Your order {{1}} has been confirmed!',
        ],
    ],
]);

// Delete a template
Larawhat::deleteTemplate('order_confirmation');
```

Webhook Handling
----------------

[](#webhook-handling)

### Built-in route (auto-registered)

[](#built-in-route-auto-registered)

The package registers a `GET` &amp; `POST` route at `/api/whatsapp/webhook` (configurable via `WHATSAPP_WEBHOOK_PATH`).

- **GET** — handles Meta's verification challenge automatically.
- **POST** — receives incoming events. The route always returns `200 {"status": "handled"}`.

### Custom callback handling

[](#custom-callback-handling)

Use the `Larawhat::webhook()` handler to register callbacks. Add this to your `AppServiceProvider::boot()` or a dedicated service provider:

```
use Larawhat\Facades\Larawhat;

// Must reference the same instance — we use resolve() to avoid boot order issues
$this->app->booted(function () {
    Larawhat::webhook()
        ->onMessage(function ($webhook) {
            // Handle incoming message
            Log::info('Message from: '.$webhook->from());
            Log::info('Text: '.$webhook->textBody());

            // Auto-reply
            Larawhat::sendText($webhook->from(), 'Thanks for your message!');
        })
        ->onStatus(function ($webhook) {
            foreach ($webhook->statuses() as $status) {
                Log::info("Message {$status['id']} status: {$status['status']}");
            }
        })
        ->onAny(function ($webhook) {
            Log::debug('Webhook received', $webhook->payload());
        });
});
```

### The WebhookRequest API

[](#the-webhookrequest-api)

```
$webhook->isValid();          // Check if payload is well-formed
$webhook->from();             // Sender's phone number
$webhook->messageType();      // 'text', 'image', 'interactive', etc.
$webhook->textBody();         // Text content (if text message)
$webhook->messages();         // Array of all messages
$webhook->statuses();         // Array of status updates
$webhook->interactiveReply(); // Button/list reply data
$webhook->phoneNumberId();    // Phone number that received the message
$webhook->payload();          // Raw payload array
```

Response handling
-----------------

[](#response-handling)

All API methods that contact Meta return an `Illuminate\Http\Client\Response` instance. Check success:

```
$response = Larawhat::sendText('+1234567890', 'Hello!');

if ($response->successful()) {
    $wamId = $response->json('messages')[0]['id'] ?? null;
}
```

Errors are thrown as exceptions:

- `Larawhat\Exceptions\AuthenticationException` — 401/403
- `Larawhat\Exceptions\RateLimitException` — 429
- `Larawhat\Exceptions\LarawhatException` — other errors

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2808296?v=4)[amsaid](/maintainers/amsaid)[@amsaid](https://github.com/amsaid)

### Embed Badge

![Health badge](/badges/amsaid-larawhat/health.svg)

```
[![Health](https://phpackages.com/badges/amsaid-larawhat/health.svg)](https://phpackages.com/packages/amsaid-larawhat)
```

###  Alternatives

[facebook/php-business-sdk

PHP SDK for Facebook Business

90923.5M35](/packages/facebook-php-business-sdk)[exsyst/swagger

A php library to manipulate Swagger specifications

35916.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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