vntrungld / laravel-zalo-bot
Laravel integration for the Zalo Bot Platform API — facade, webhook handling, notification channel, and Artisan commands.
Requires
- php: ^8.1
- ext-json: *
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- vntrungld/zalo-bot-php-sdk: @dev
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2026-07-07 11:11:52 UTC
README
Laravel integration for the Zalo Bot Platform API,
wrapping vntrungld/zalo-bot-php-sdk.
Install
composer require vntrungld/laravel-zalo-bot php artisan vendor:publish --tag=zalo-bot-config
Set in .env:
ZALO_BOT_TOKEN="{id}:{secret}" ZALO_BOT_SECRET_TOKEN="a-long-webhook-secret"
Sending messages
use Vntrungld\LaravelZaloBot\Facades\ZaloBot; ZaloBot::sendMessage($chatId, 'Xin chào!');
Or inject ZaloBot\Client directly.
Webhook
A POST /zalo-bot/webhook route is registered automatically (configurable via
ZALO_BOT_WEBHOOK_PATH). It verifies the X-Bot-Api-Secret-Token header and
dispatches an event:
Security: if
ZALO_BOT_SECRET_TOKENis unset while the webhook is enabled, signature verification is skipped and the endpoint accepts unauthenticated requests. Always setZALO_BOT_SECRET_TOKENin production.
use Vntrungld\LaravelZaloBot\Events\ZaloUpdateReceived; Event::listen(function (ZaloUpdateReceived $e) { $text = $e->update->message->text; // ... });
Register the URL with Zalo:
php artisan zalo-bot:webhook:set https://your-app.test/zalo-bot/webhook php artisan zalo-bot:webhook:info php artisan zalo-bot:webhook:delete
Notifications
use Illuminate\Notifications\Notification; use Vntrungld\LaravelZaloBot\Notifications\ZaloMessage; class Reminder extends Notification { public function via($notifiable): array { return ['zalo']; } public function toZalo($notifiable): ZaloMessage { return ZaloMessage::text('Cuộc hẹn lúc 3 giờ chiều'); } }
Route the notifiable by adding routeNotificationForZalo() returning the chat
id, or call ->to($chatId) on the message.
License
MIT.