airboxhq / airbox-laravel
Laravel integration for the Airbox API: WhatsApp and Instagram messages through one REST API.
Requires
- php: ^8.2
- airboxhq/airbox-php: ^0.2
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
WhatsApp and Instagram messages through one REST API, from Laravel.
Version 0.2.0 covers the whole API: messages, templates, media, contacts, channels and the test endpoint.
Install
composer require airboxhq/airbox-laravel
Laravel 11 or newer. The package registers itself. Put your key in .env:
AIRBOX_API_KEY=your-key
Make the client
The facade reaches one client, made from your config:
use Airbox\Laravel\Facades\Airbox;
Or inject the client: public function __construct(private \Airbox\Client $airbox) {}.
A test key sends to the simulator, so you can try every call before connecting a number. The shortcuts take camelCase (mediaId) or the API's snake_case. send() sends its body as given.
Messages
$message = Airbox::messages()->sendText( ['to' => '+77011234567', 'body' => 'Your order is ready'], ['idempotency_key' => 'order-1042'], ); $status = Airbox::messages()->get($message['id'])['status'];
sendText answers on the channel the customer last wrote on. Pass 'channel' => 'whatsapp' to choose one. sendImage, sendVideo, sendAudio and sendVoice take a url or a mediaId. send takes the whole body of POST /messages.
Templates
$templates = Airbox::templates()->list(); Airbox::templates()->send('order_ready', [ 'to' => '+77011234567', 'language' => 'ru', 'parameters' => ['1042'], ]);
Media
$media = Airbox::media()->upload(storage_path('app/order.jpg')); Airbox::messages()->sendImage(['to' => '+77011234567', 'mediaId' => $media['id']]); $bytes = Airbox::media()->download($media['id']);
upload takes a path or a string of bytes. For bytes, pass ['filename' => 'order.jpg', 'content_type' => 'image/jpeg'] as the second argument.
Contacts
Airbox::contacts()->grantConsent('+77011234567'); Airbox::contacts()->withdrawConsent('+77011234567');
Record consent only when the customer really gave it.
Channels
$channels = Airbox::channels()->list();
Test
Airbox::test()->inbound([ 'from' => '+77011234567', 'text' => ['body' => 'Hello! When will my order be ready?'], 'name' => 'Asel', ]);
Only a test key may call it. A live key gets the test_key_required error.
Configuration
php artisan vendor:publish --tag=airbox-config copies config/airbox.php, which reads AIRBOX_API_KEY (or
the older WHATSAPP_API_KEY) and AIRBOX_BASE_URL.
Errors
A refused request throws Airbox\AirboxException with the API's own errorCode, the HTTP status and the requestId to quote to support.
License
MIT