waapi / waapi-laravel-sdk
WaAPI Laravel Package
Installs: 1 471
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 1
Open Issues: 1
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
- waapi/waapi-php-sdk: ^1.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2025-03-31 04:41:10 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
MediaUploadedEvent
MessageAcknowledgedEvent
MessageCreatedEvent
MessageEvent
MessageReactionEvent
MessageRevokedEveryoneEvent
MessageRevokedMeEvent
QrEvent
StateChangeEvent
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.