This repository contains quick examples of how to build Viber bots with usage alserom/viber-php library.
Do not recommend to use these examples in production, as it not the best code which you can write.
These instructions will get you a copy of the project up and running on your local machine.
- You should install Docker Compose OR be ready to configure web-server, PHP (>=7.1) and work with composer.
- You must have an active Viber account on a platform which supports Public Accounts / bots.
- You must have an active bot account.
- Download or clone the repository.
git clone https://github.com/alserom/viber-bot-examples
cd viber-bot-examples
- Copy
.env.dist
to.env
file.
cp .env.dist .env
- Edit
.env
file, placing your account authentication token toAPI_TOKEN
and one of the available bots toBOT_EXAMPLE
. See Available bots section. - Start up an example with Docker Compose.
sudo docker-compose up --build
- Configure your web-server that document root will be
<your-path-here>/viber-bot-examples/src/public
path. - Edit
src/config.php
file, placing your account authentication token toAPI_TOKEN
and webhook URL toWEBHOOK_URL
.
WEBHOOK_URL
must be URL with valid and official SSL certificate from a trusted CA. Ngrok can help with it.
- Edit
src/public/index.php
file, manually included PHP file with one of the available bots. See Available bots section. - Install project dependencies with composer
cd src
composer install
- Set up webhook for the bot, running
setup.php
script. This can be done with a composer script.
composer setup
Next, you can analyze .php
files in the src
directory for a better understanding of how to build bots.
- base.php - Base things, which need to creating
$api
and$bot
instances. - setup.php - Example of how to set webhook.
- bots/*/bot.php - Main bot logic.
- public/index.php - Example of how to handling Viber callbacks (server requests) and return a response.
Name | Path | Description |
---|---|---|
annoying | src/bots/annoying/bot.php |
Simple echo bot |
weather | src/bots/weather/bot.php |
Demonstrates working with keyboards |
isitup | src/bots/isitup/bot.php |
Similar functionality as in the official example from Viber |
This project is licensed under the MIT License - see the LICENSE file for details.