sokil / php-viber-notifier
Allows to implement subscription on Viber's account and broadcast notifications to different groups of subscribed userss,
Requires
- php: >=7.3
- ext-json: *
- fig/http-message-util: ^1.1
Requires (Dev)
- php-coveralls/php-coveralls: ^2.2.0
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.6
- vimeo/psalm: ^4.3
Suggests
- fig/http-message-util: For supporting of PSR HTTP Clients
- psr/http-client: For supporting of PSR HTTP Clients
- psr/http-factory: For supporting of PSR HTTP Clients
- psr/http-message: For supporting of PSR HTTP Clients
- psr/http-server-handler: For supporting of PSR HTTP Clients
README
Allows to implement subscription on Viber's account and broadcast notifications to different groups (roles) of subscribed users.
Installation
composer require sokil/php-viber-notifier
WebHook
Viber informs server about events by webhook. It must be passed to Viber using API.
For Example:
#!/bin/sh
curl -XPOST -H 'X-Viber-Auth-Token: your-bot-api-token' "https://chatapi.viber.com/pa/set_webhook" -d '{"url": "https://server.com/chatbot/webhook/viber", "event_types": ["subscribed","unsubscribed","conversation_started"], "send_name": true, "send_photo" : true}'
Usage
To start sending notifications via Viber we need to create bot first.
When user joins Viber's chatbot, Viber sends postback request to our site with subscribed user details. Then we may send notifications to all subscribed users.
Users may have different roles, so we may broadcast different messages to different roles of users.
Subscribers repository
First we need to implement storage where subscribed Viber users and their roles will be stored.
Storage must implement SubscribersRepositoryInterface
.
Viber chat bot client
If you already have convigured Viber bot in your project, just create adapter by implementing interface ViberClientInterface
.
If you have no chatbot in you project, use basic implementation ViberClient
.