zapwize / laravel
Laravel package for Zapwize WhatsApp Web API integration
Fund package maintenance!
Will-create
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/zapwize/laravel
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0
- illuminate/events: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/queue: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- ratchet/pawl: ^0.4.3
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
This package provides a simple and expressive way to interact with the Zapwize WhatsApp Web API in your Laravel applications. Send text messages, images, videos, documents, and more with ease.
Features
- Fluent and easy-to-use API
- Send various message types: text, image, video, audio, document, location, contact, poll
- Asynchronous message sending using Laravel Queues
- Webhook handling for incoming messages and status updates
- Secure webhook signature verification
- Automatic caching of server information for better performance
- Configurable logging and connection settings
Installation
You can install the package via composer:
composer require zapwize/laravel
Configuration
-
Publish the configuration file:
php artisan vendor:publish --provider="Zapwize\Laravel\ZapwizeServiceProvider" --tag="config"
This will create a
config/zapwize.php
file in your application. -
Add the following environment variables to your
.env
file:ZAPWIZE_API_KEY=your_zapwize_api_key # Optional queue settings ZAPWIZE_QUEUE_CONNECTION=database ZAPWIZE_QUEUE=zapwize
Requirements
- PHP 8.2 or higher
- Laravel 9, 10, 11 or 12
Usage
You can use the Zapwize
facade to access the client methods.
Sending Messages
Text Message
use Zapwize\Laravel\Facades\Zapwize; $response = Zapwize::sendMessage('1234567890', 'Hello from Laravel!');
Image Message
use Zapwize\Laravel\Facades\Zapwize; $media = [ 'url' => 'https://example.com/image.jpg', // or 'base64' => 'data:image/jpeg;base64,...' ]; $options = [ 'caption' => 'This is a caption.', ]; $response = Zapwize::sendImage('1234567890', $media, $options);
Video Message
use Zapwize\Laravel\Facades\Zapwize; $media = [ 'url' => 'https://example.com/video.mp4', ]; $options = [ 'caption' => 'This is a video.', 'gif' => false, // Set to true for GIF videos ]; $response = Zapwize::sendVideo('1234567890', $media, $options);
Audio Message
use Zapwize\Laravel\Facades\Zapwize; $media = [ 'url' => 'https://example.com/audio.mp3', ]; $response = Zapwize::sendAudio('1234567890', $media);
Document Message
use Zapwize\Laravel\Facades\Zapwize; $media = [ 'url' => 'https://example.com/document.pdf', 'filename' => 'MyDocument.pdf', ]; $response = Zapwize::sendDocument('1234567890', $media);
Location Message
use Zapwize\Laravel\Facades\Zapwize; $response = Zapwize::sendLocation('1234567890', 37.7749, -122.4194);
Contact Message
use Zapwize\Laravel\Facades\Zapwize; $contact = [ 'name' => 'John Doe', 'phone' => '0987654321', ]; $response = Zapwize::sendContact('1234567890', $contact);
Poll Message
use Zapwize\Laravel\Facades\Zapwize; $poll = [ 'name' => 'What is your favorite color?', 'options' => ['Red', 'Green', 'Blue'], 'selectableCount' => 1, ]; $response = Zapwize::sendPoll('1234567890', $poll);
Asynchronous Sending
To send messages without blocking the main thread, you can use the sendMessageAsync
method. Make sure your Laravel Queue is configured correctly.
use Zapwize\Laravel\Facades\Zapwize; Zapwize::sendMessageAsync('1234567890', 'This message is sent asynchronously.');
Webhooks
To handle incoming messages and status updates, you need to set up a webhook.
-
In your
config/zapwize.php
, setwebhook.enabled
totrue
and configure thewebhook.url
andwebhook.secret
. -
The package automatically registers the webhook route at
/zapwize/webhook
. You can customize this in the config file. -
Listen for the
Zapwize\Laravel\Events\MessageReceived
event to process incoming messages:In your
EventServiceProvider.php
:protected $listen = [ \Zapwize\Laravel\Events\MessageReceived::class => [ \App\Listeners\ProcessIncomingWhatsAppMessage::class, ], ];
Create the listener:
namespace App\Listeners; use Zapwize\Laravel\Events\MessageReceived; class ProcessIncomingWhatsAppMessage { public function handle(MessageReceived $event) { $messageData = $event->message; // Process the incoming message... } }
Other Methods
Check if a number is a WhatsApp number
use Zapwize\Laravel\Facades\Zapwize; $isWhatsAppNumber = Zapwize::isWhatsAppNumber('1234567890');
Get Server Information
use Zapwize\Laravel\Facades\Zapwize; $serverInfo = Zapwize::getServerInfo();
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.