PHPackages                             chat/whatsapp-integration - 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. chat/whatsapp-integration

ActiveLibrary[API Development](/categories/api)

chat/whatsapp-integration
=========================

A package for integrating WhatsApp features into Laravel 5.8 applications.

2.0.4(1y ago)0146MITPHPPHP ^7.1.3

Since Oct 23Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Agnes-Kalunda/whatsapp-integration)[ Packagist](https://packagist.org/packages/chat/whatsapp-integration)[ RSS](/packages/chat-whatsapp-integration/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (8)Versions (14)Used By (0)

WhatsApp Integration Package
============================

[](#whatsapp-integration-package)

This is a Composer package that integrates basic WhatsApp features into laravel apps using WhatsApp API with Twilio as the Business provider.This package handles the functionalities for sending WhatsApp messages and handling incoming messages in Laravel 5.8+ applications.

[![Latest Stable Version](https://camo.githubusercontent.com/f1f19a084e8008f21925c10cb10fba197f20803d463dd5e35553bc725a1e8eb7/68747470733a2f2f706f7365722e707567782e6f72672f636861742f77686174736170702d696e746567726174696f6e2f762f737461626c65)](https://packagist.org/packages/chat/whatsapp-integration)[![License](https://camo.githubusercontent.com/7517aa0506ad6f6ed24d0d3ea9d431ef4876c41140d2ee4dce6a8d741e88f46b/68747470733a2f2f706f7365722e707567782e6f72672f636861742f77686174736170702d696e746567726174696f6e2f6c6963656e7365)](https://packagist.org/packages/chat/whatsapp-integration)

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Template Messages](#template-messages)
    - [Handling Webhooks](#handling-webhooks)
- [API Integration Examples](#api-integration-examples)
- [Error Handling](#error-handling)
- [Testing](#testing)
- [License](#license)

Features
--------

[](#features)

- Send WhatsApp messages
- Template message support
- Media message handling
- Webhook processing
- Rate limiting
- Comprehensive error handling
- Validation
- Easy integration

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

[](#requirements)

- PHP &gt;= 7.1.3
- Laravel &gt;= 5.8
- Twilio Account with WhatsApp capabilities
- Composer

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

[](#installation)

1. Install the package via Composer:

```
composer require chat/whatsapp-integration
```

2. Add the service provider in `config/app.php` (Laravel will auto-discover it):

```
'providers' => [
    // ...
    Chat\WhatsappIntegration\WhatsAppIntegrationServiceProvider::class,
]
```

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

[](#configuration)

1. Publish the configuration file:

```
php artisan vendor:publish --provider="Chat\WhatsappIntegration\WhatsAppIntegrationServiceProvider" --tag="whatsapp-config"
```

2. Add the following to your `.env` file:

```
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_FROM_NUMBER=your_whatsapp_number  # Format: +1234567890
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Chat\WhatsappIntegration\WhatsApp;
use Chat\WhatsappIntegration\Exceptions\WhatsAppException;

public function sendMessage(WhatsApp $whatsapp)
{
    try {
        $result = $whatsapp->sendMessage(
            '+1234567890',  // recipient's number
            'Hello from Laravel!'
        );

        // Success
        $messageSid = $result->sid;
        $status = $result->status;

    } catch (WhatsAppException $e) {
        // Handle error
        logger()->error('WhatsApp Error: ' . $e->getMessage());
    }
}
```

### Template Messages

[](#template-messages)

```
try {
    $result = $whatsapp->sendMessage(
        '+1234567890',
        'Your order has been confirmed',
        'HX350d429d32e64a552466cafecbe95f3c', // template ID
        json_encode(['1' => 'today', '2' => '3pm']) // variables
    );
} catch (WhatsAppException $e) {
    // Handle error
}
```

### Handling Webhooks

[](#handling-webhooks)

```
try {
    $result = $whatsapp->handleWebhook(
        $request->all(),
        $request->fullUrl(),
        $request->header('X-Twilio-Signature')
    );

    $messageBody = $result['Body'];
    $fromNumber = $result['From'];
    $mediaUrls = $result['MediaUrls'];

} catch (WhatsAppException $e) {
    // Handle error
}
```

API Integration Examples
------------------------

[](#api-integration-examples)

Here's how to integrate the package with your Laravel application's API:

1. Create a controller:

```
