mprince / laravel8-viber-bot
Viber bot for Laravel
Requires
- php: ^7.4|^8.0
- php-curl-class/php-curl-class: ^9.1
Requires (Dev)
- phpunit/phpunit: ^9.5.4
This package is auto-updated.
Last update: 2024-11-29 06:29:05 UTC
README
Installation
This package can be installed through Composer.
composer require mprince/laravel8-viber-bot
In Laravel 5.5 and above the package will autoregister the service provider. In Laravel 5.4 you must install this service provider.
// config/app.php 'providers' => [ ... Paragraf\ViberBot\ViberBotServiceProvider::class, ... ];
Changelog
Please see CHANGELOG for more information what has changed recently.
Configuration
You need to set in .env
and setup webhook
.
Env
VIBERBOT_API=your_viber_token VIBERBOT_NAME=name VIBERBOT_PHOTO=photo
You can find Viber token on Viber Partners after creating bot on Info tab.
WebHook
You must run artisan command for webhoook with url parameter
php artisan viber-bot:webhook https://example-url.com/some-route
Note: It must be full url and must be HTTPS.
Config file
Optionally, you can publish the config file of this package with this command:
php artisan vendor:publish --provider="Paragraf\ViberBot\ViberBotServiceProvider"
The following config file will be published in config/viberbot.php
Usage
When the installation is done you have access to Bot
and Client
class.
Bot class
With bot class you naivgate your ViberBot how to work.
(new Bot($request, new TextMessage())) ->on(new MessageEvent($request->timestamp, $request->message_token, new ViberUser($request->sender['id'],$request->sender['name']), $request->message)) ->hears("Hi!") ->replay("Hello World!") ->send();
Note: If viber user not set name
you will get error.
You can change responding type Message and Event who listen that event.
List of Events:
- ConversationStartedEvent
- DeliveredEvent
- FailedEvent
- MessageEvent
- SeenEvent
- SubscribedEvent
- UnsubscribedEvent
Note:
If you don't want to listen all events you can change event_types
in config/viberbot.php
.
If you change you must run again php artisan viber-bot:webhook your-url
in oreder to apply changes.
List of Messages:
- TextMessage
- BroadcastMessage
- ContactMessage
- FileMessage
- KeyboardMessage
- LocationMessage
- PictureMessage
- StickerMessage
- URLMessage
- VideoMessage
- WelcomeMessage
- CarouselMessage - ToDo
Client class
Client class, provide to you extra utility.
(new Client())->broadcast('Hello', User::all(), 'viber_id');
Note: $method
in broadcast()
must point to viber_id. Also getOnlineStatus()
need viber_ids
.
If you want more information about Viber API or how something works check Viber REST API
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email nemanja.ivankovic@paragraf.rs instead of using the issue tracker.