waapi / waapi-laravel-sdk
WaAPI Laravel Package
Requires
- php: ^8.2
- illuminate/contracts: ^12.0|^13.0
- spatie/laravel-package-tools: ^1.14.0
- waapi/waapi-php-sdk: ^2.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8|^8.0
- nunomaduro/larastan: ^2.0.1|^3.0
- orchestra/testbench: ^10.0|^11.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0|^2.0
- phpstan/phpstan-phpunit: ^1.0|^2.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-30 18:49:25 UTC
README
Laravel Package to use with waapi.app.
Installation
You can install the package via composer:
composer require waapi/waapi-laravel-sdk
You can publish the config file with:
php artisan vendor:publish --tag="waapi-config"
This is the contents of the published config file:
return [ 'api_token' => env('WAAPI_API_TOKEN'), 'instance_id' => env('WAAPI_INSTANCE_ID'), ];
Please adapt your .env with your instance ID and Token which can be obtained from your API Tokens
Replace with your token and your instance ID
WAAPI_API_TOKEN=abcdefghijkl123456789 WAAPI_INSTANCE_ID=123
Usage
$waAPI = new WaAPI\WaAPI(); $waAPI->sendMessage('1222333444@c.us', 'Hello there!');
Webhook Listener
The package provides a webhooks endpoint to handle incoming webhooks. Simply update your instance with the event types you want to listen to and the endpoint.
Make sure your app is running on a publicly availabel domain. Locally the webhooks won't work.
app(WaAPI::class)->updateInstance( route('waapi.webhooks'), [ EventType::MESSAGE->value, EventType::QR->value ] );
Create an event listener to listen on the webhook events
new Message example:
php artisan make:listener WaAPIMessageListener --event=\\WaAPI\\WaAPI\\Events\\MessageEvent
QR Code change example:
php artisan make:listener WaAPIQrCodeListener --event=\\WaAPI\\WaAPI\\Events\\QrEvent
Register your listener in app/Providers/EventServiceProvider.php if autodiscovery for events is disabled
use App\Listeners\WaAPIInstanceReadyListener; use App\Listeners\WaAPIMessageListener; use WaAPI\WaAPI\Events\MessageEvent; use WaAPI\WaAPI\Events\QrEvent; [...] protected $listen = [ MessageEvent::class => [ WaAPIMessageListener::class, ], QrEvent::class => [ WaAPIQrCodeListener::class, ], ];
Example for WaAPIMessageListener:
<?php namespace App\Listeners; use WaAPI\WaAPI\Events\MessageEvent; use WaAPI\WaAPI\WaAPI; class WaAPIMessageListener { /** * Handle the event. */ public function handle(MessageEvent $message): void { if (!$message->isFromMe()) { app(WaAPI::class)->sendMessage($message->getFrom(), 'Hello to you too!'); } } }
Available events:
AuthenticatedEvent
AuthFailureEvent
DisconnectedEvent
GroupJoinEvent
GroupLeaveEvent
GroupUpdateEvent
InstanceReadyEvent
LoadingScreenEvent
MediaDownloadRetryEvent
MediaDownloadedEvent
MediaUploadedEvent
MessageAcknowledgedEvent
MessageCreatedEvent
MessageEvent
MessageReactionEvent
MessageRevokedEveryoneEvent
MessageRevokedMeEvent
QrEvent
StateChangeEvent
MediaDownloadRetryEvent (media_download_retry) fires once for an incoming media message whose download had
failed: data.media carries the file after a successful retry, or {status: 'error', error, detail, final: true},
and data.retry.outcome says which (delivered or failed). It is opt-in: select it on the instance or in a
webhook subscription.
MediaDownloadedEvent (media_downloaded) fires once for an incoming media message as soon as its file is
available — on the first download or after a retry — and carries data.message only; fetch the file with
downloadMedia(). A repeat for the same message id is rare but possible and safe to ignore. It works with every media mode and needs a message event (message, message_create or
message_edit) subscribed too.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.