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

ActiveLibrary[API Development](/categories/api)

crenspire/laravel-whatsapp
==========================

Laravel WhatsApp Business API package

1.0.0(8mo ago)133.0k↓43.3%5[2 PRs](https://github.com/crenspire/laravel-whatsapp/pulls)MITPHPPHP ^8.2CI failing

Since Sep 8Pushed 8mo agoCompare

[ Source](https://github.com/crenspire/laravel-whatsapp)[ Packagist](https://packagist.org/packages/crenspire/laravel-whatsapp)[ Docs](https://github.com/crenspire/laravel-whatsapp)[ RSS](/packages/crenspire-laravel-whatsapp/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Laravel WhatsApp Business API Package
=====================================

[](#laravel-whatsapp-business-api-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7e3a6273d4f4f3ef2ac9c12062214ecdcd6b2b0e384fe7b6c07f2499998e9a42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372656e73706972652f6c61726176656c2d77686174736170702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crenspire/laravel-whatsapp)[![Total Downloads](https://camo.githubusercontent.com/5fc1d0d026fad4d19b131316f7140d5e536fc19c965bd2ff257651ca8225aa7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372656e73706972652f6c61726176656c2d77686174736170702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crenspire/laravel-whatsapp)[![Build Status](https://camo.githubusercontent.com/d00021f66d38e0e905b64de11a0af5cb8797d3a2c7a05ba05e2f5bcb0e0c7360/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6372656e73706972652f6c61726176656c2d77686174736170702f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/crenspire/laravel-whatsapp/actions)[![Test Coverage](https://camo.githubusercontent.com/89c98f1b4e5951754a467f23eb81b3b0d3b306f65fae78197d473e4cedd077f3/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6372656e73706972652f6c61726176656c2d77686174736170703f7374796c653d666c61742d737175617265)](https://codecov.io/gh/crenspire/laravel-whatsapp)[![PHP Version](https://camo.githubusercontent.com/daf4379f8b59d0237d413260f01d2fa0795da9a66b6f25d8628f44e97ece9085/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6372656e73706972652f6c61726176656c2d77686174736170703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crenspire/laravel-whatsapp)[![Laravel Version](https://camo.githubusercontent.com/ad763e4d77744ac691fdd18aa080470bbf4039c9b19cee21ac86bda481c44a98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6372656e73706972652f6c61726176656c2d77686174736170702f696c6c756d696e6174652f636f6e7472616374733f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crenspire/laravel-whatsapp)[![License](https://camo.githubusercontent.com/c2e50de01daf396b58c6fd7f683ebe5f6bd9417148300d898db636bcc828d989/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6372656e73706972652f6c61726176656c2d77686174736170703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crenspire/laravel-whatsapp)[![StyleCI](https://camo.githubusercontent.com/6ddee1f8d6ff780e905b86c3756d95ccac3a863623fb2f021f0d66a49ae3d952/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3132333435363738392f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/123456789)

A comprehensive Laravel package for integrating with the WhatsApp Business Cloud API. This package provides a clean, easy-to-use interface for sending messages, handling webhooks, managing media, and supporting multi-tenant applications.

Features
--------

[](#features)

- ✅ **Complete Message Types**: Text, media, templates, interactive messages (buttons, lists), contacts, location, stickers, reactions, flows, and product messages
- ✅ **Fluent API**: Builder patterns for easy message construction with `MessageBuilder` and `TemplateBuilder`
- ✅ **Webhook Support**: Secure webhook handling with signature verification and comprehensive message type processing
- ✅ **Media Management**: Upload, download, info retrieval, and deletion with automatic type detection via `MediaManager`
- ✅ **Business Profile Management**: Get and update business profile information via `BusinessProfileManager`
- ✅ **Multi-tenant Support**: Per-tenant configuration for phone numbers and access tokens
- ✅ **Rate Limiting**: Built-in rate limiting to respect WhatsApp API limits
- ✅ **Event System**: Laravel events for message status updates and incoming messages
- ✅ **Comprehensive Testing**: Full test coverage with realistic scenarios
- ✅ **Security**: Webhook verification and signature validation
- ✅ **Logging**: Detailed logging for debugging and monitoring
- ✅ **Clean Architecture**: Separated concerns with dedicated managers and builders

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

[](#installation)

### 1. Install the Package

[](#1-install-the-package)

```
composer require crenspire/laravel-whatsapp
```

### 2. Publish Configuration

[](#2-publish-configuration)

```
php artisan vendor:publish --tag=config --provider="Crenspire\\Whatsapp\\WhatsappServiceProvider"
```

### 3. Configure Environment Variables

[](#3-configure-environment-variables)

Add these variables to your `.env` file:

```
# WhatsApp Business API Configuration
WHATSAPP_BASE_URI=https://graph.facebook.com/v20.0
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
WHATSAPP_ACCESS_TOKEN=your_access_token

# Webhook Configuration
WHATSAPP_WEBHOOK_VERIFY_TOKEN=your_webhook_verify_token
WHATSAPP_WEBHOOK_SECRET=your_webhook_secret

# Optional Configuration
WHATSAPP_RATE_LIMIT=30
WHATSAPP_DEBUG=false
```

### 4. Set Up Webhook Routes

[](#4-set-up-webhook-routes)

The package automatically registers webhook routes. Make sure your webhook URL is configured in your WhatsApp Business API settings:

- **Verification URL**: `https://yourdomain.com/whatsapp/webhook`
- **Webhook URL**: `https://yourdomain.com/whatsapp/webhook`

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Crenspire\Whatsapp\Facades\Whatsapp;

// Send a text message
$response = Whatsapp::sendTextMessage('1234567890', 'Hello from Laravel!');

// Send a media message
$response = Whatsapp::sendMediaMessage('1234567890', 'media_id_123', 'image', 'Check this out!');

// Send a template message
$response = Whatsapp::sendTemplateMessage('1234567890', 'hello_world', ['John', 'Doe']);
```

### Using the Service Directly

[](#using-the-service-directly)

```
use Crenspire\Whatsapp\WhatsappService;

$whatsapp = app(WhatsappService::class);

$response = $whatsapp->sendTextMessage('1234567890', 'Hello World!');
```

Message Types
-------------

[](#message-types)

### Text Messages

[](#text-messages)

```
Whatsapp::sendTextMessage('1234567890', 'Hello World!');
```

### Media Messages

[](#media-messages)

```
// Send image with caption
Whatsapp::sendMediaMessage('1234567890', 'media_id_123', 'image', 'Check this out!');

// Send video
Whatsapp::sendMediaMessage('1234567890', 'media_id_456', 'video', 'Watch this video');

// Send document
Whatsapp::sendMediaMessage('1234567890', 'media_id_789', 'document', 'Important document');
```

### Template Messages

[](#template-messages)

```
// Send template with parameters
Whatsapp::sendTemplateMessage(
    '1234567890',
    'hello_world',
    ['John', 'Doe'],
    'en_US'
);
```

### Interactive Messages

[](#interactive-messages)

#### Button Messages

[](#button-messages)

```
$buttons = [
    ['id' => 'btn1', 'title' => 'Option 1'],
    ['id' => 'btn2', 'title' => 'Option 2'],
    ['id' => 'btn3', 'title' => 'Option 3']
];

Whatsapp::sendButtonMessage(
    '1234567890',
    'Choose an option:',
    $buttons,
    'Header Text',
    'Footer Text'
);
```

#### List Messages

[](#list-messages)

```
$sections = [
    [
        'title' => 'Category 1',
        'rows' => [
            [
                'id' => 'row1',
                'title' => 'Option 1',
                'description' => 'Description for option 1'
            ],
            [
                'id' => 'row2',
                'title' => 'Option 2',
                'description' => 'Description for option 2'
            ]
        ]
    ]
];

Whatsapp::sendListMessage(
    '1234567890',
    'Choose from the list:',
    'View Options',
    $sections,
    'Header Text',
    'Footer Text'
);
```

Media Management
----------------

[](#media-management)

### Upload Media

[](#upload-media)

```
$response = Whatsapp::uploadMedia('/path/to/image.jpg', 'image');
$mediaId = $response['id'];

// Use the media ID to send the image
Whatsapp::sendMediaMessage('1234567890', $mediaId, 'image', 'Uploaded image');
```

### Download Media

[](#download-media)

```
$filePath = Whatsapp::downloadMedia('media_id_123');
// File is saved to storage/app/whatsapp-media/media_id_123.jpg
```

Multi-tenant Support
--------------------

[](#multi-tenant-support)

Configure multiple WhatsApp Business accounts:

```
// In config/whatsapp.php
'tenants' => [
    'company1' => [
        'phone_number_id' => 'phone_number_1',
        'access_token' => 'access_token_1'
    ],
    'company2' => [
        'phone_number_id' => 'phone_number_2',
        'access_token' => 'access_token_2'
    ]
]
```

Use tenant-specific configuration:

```
// Send message using specific tenant
Whatsapp::sendTextMessage('1234567890', 'Hello!', 'company1');
```

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

[](#webhook-handling)

### Event Listeners

[](#event-listeners)

The package dispatches several events that you can listen to:

```
// In your EventServiceProvider
protected $listen = [
    \Crenspire\Whatsapp\Events\MessageSent::class => [
        // Your listener
    ],
    \Crenspire\Whatsapp\Events\MessageDelivered::class => [
        // Your listener
    ],
    \Crenspire\Whatsapp\Events\MessageRead::class => [
        // Your listener
    ],
    \Crenspire\Whatsapp\Events\MessageReceived::class => [
        // Your listener
    ],
    \Crenspire\Whatsapp\Events\MessageFailed::class => [
        // Your listener
    ],
];
```

### Example Event Listener

[](#example-event-listener)

```
