PHPackages                             alserom/viber-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. alserom/viber-php

ActiveLibrary[API Development](/categories/api)

alserom/viber-php
=================

Unofficial library to work with Viber REST API and for develop a bot for the Viber platform.

1.0.0(7y ago)1841MITPHPPHP ^7.1.3

Since Apr 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/alserom/viber-php)[ Packagist](https://packagist.org/packages/alserom/viber-php)[ Docs](https://github.com/alserom/viber-php)[ RSS](/packages/alserom-viber-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (13)Versions (2)Used By (0)

PHP SDK for Viber REST API [![Latest Stable Version](https://camo.githubusercontent.com/0d34ab4e7d48d020a6ba65c232d1c9f086f1fb7be73d179a1f866ef304667dfb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c7365726f6d2f76696265722d7068702e7376673f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/alserom/viber-php) [![Latest Unstable Version](https://camo.githubusercontent.com/25d29bc777958add95bb3d724c62f2a10028205c7f7b61110f77c9c034fb76e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f616c7365726f6d2f76696265722d7068702e7376673f6c6162656c3d756e737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/alserom/viber-php#dev-master)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-sdk-for-viber-rest-api--)

[![Build Status](https://camo.githubusercontent.com/b9ac42b0aa3934dde78c9482028e357b0ae0b430beb69e805b031cb42f11ce45/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616c7365726f6d2f76696265722d7068702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/alserom/viber-php)[![Minimum PHP Version](https://camo.githubusercontent.com/a694df1be18fd7e9189c65c302a1fa312a6334098b5cd82057f2e34202cf0db2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c7365726f6d2f76696265722d7068702e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/supported-versions.php)[![Coding Style](https://camo.githubusercontent.com/2fc2e06696732debe1ad40988fdeae5e9dad3110a8d20508b91d13702217ae4b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5053522d2d31322d696e666f726d6174696f6e616c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md)[![Software License](https://camo.githubusercontent.com/ae846dba59c1a89d1178f143fe86afff92630cc78965ee86cf391e8a8c5c51ec/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c7365726f6d2f76696265722d7068702e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Use this library to develop a bot for the Viber platform or simple work with [Viber REST API](https://developers.viber.com/docs/api/rest-bot-api/).

> Note: For work with Viber API, you must have an authentication token. Go to [partners.viber.com](https://partners.viber.com), create bot account and get token.

Installation
------------

[](#installation)

```
composer require alserom/viber-php
```

For properly work with this package you do also need to install a PSR-17 request/response factory and PSR-18 HTTP Client.
You can find packages of these implementations here:

- [List of PSR-17 implementations](https://packagist.org/providers/psr/http-factory-implementation)
- [List of PSR-18 implementations](https://packagist.org/providers/psr/http-client-implementation)

Example:

```
composer require nyholm/psr7 kriswallsmith/buzz
```

Usage
-----

[](#usage)

This page will just show you the basics. For advanced usage, please read the full [documentation](docs/README.md).

If you want to quickly try this library on practice, you can use the code from repository [viber-bot-examples](https://github.com/alserom/viber-bot-examples).

### Create objects

[](#create-objects)

```
// Any PSR-17 implementation. In this case, we use 'nyholm/psr7' package.
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

// Any PSR-18 implementation. In this case, we use 'kriswallsmith/buzz' package.
$psr18Client = new \Buzz\Client\Curl($psr17Factory);

/* A simple object for getting all PSR-17 factories.
 * If you have an object which implements all PSR-17 interfaces, you can use a static method. E.g:
 * $psr17 = \Alserom\Viber\Psr17::useForAll($psr17Factory);
 */
$psr17 = new \Alserom\Viber\Psr17(
    $psr17Factory, // \Psr\Http\Message\RequestFactoryInterface
    $psr17Factory, // \Psr\Http\Message\ResponseFactoryInterface
    $psr17Factory, // \Psr\Http\Message\ServerRequestFactoryInterface
    $psr17Factory, // \Psr\Http\Message\StreamFactoryInterface
    $psr17Factory, // \Psr\Http\Message\UploadedFileFactoryInterface
    $psr17Factory  // \Psr\Http\Message\UriFactoryInterface
);

$token = 'YOUR-AUTHENTICATION-TOKEN';

/* An object for work with Viber API.
 * As a fourth argument, you can pass an array of options. See the full documentation for more info.
 */
$api = new \Alserom\Viber\Api($token, $psr17, $psr18Client);

/* An object for creating a logic of Viber bot.
 * As a second argument, you can pass an array of options. See the full documentation for more info.
 */
$bot = new \Alserom\Viber\Bot($api);
```

### Setting a Webhook

[](#setting-a-webhook)

```
$url = 'YOUR-HTTPS-WEBHOOK-URL';
$webhook = new \Alserom\Viber\Entity\Webhook($url);

// If you want that your bot receives user names instead of placeholder values.
// $webhook->setSendName(true);

// If you want that your bot receives user photos instead of placeholder values.
// $webhook->setSendPhoto(true);

// If you want to filter which events would get a callback for.
// $webhook->setEventTypes(['delivered', 'seen', 'conversation_started']);

$api->setWebhook($webhook);
```

### Sending message

[](#sending-message)

Build a message from scratch:

```
$message = new \Alserom\Viber\Message('text');
$message
    ->setText('Hello World!')
    ->setTo(new \Alserom\Viber\Entity\User('USER-IDENTIFIER-HERE'));

// $response is a \Alserom\Viber\Response\Type\SendMessageResponse object.
$response = $api->sendMessage($message);
```

Or use prepared entity:

```
$entity = new \Alserom\Viber\Entity\Message\Text();
$entity->setText('Hello World!');

$message = new \Alserom\Viber\Message();
$message->setTo(new \Alserom\Viber\Entity\User('USER-IDENTIFIER-HERE'));
$message->setEntity($entity);

$response = $api->sendMessage($message);
```

### Registering events (Viber callbacks) handlers

[](#registering-events-viber-callbacks-handlers)

```
$handler = function (\Alserom\Viber\Event\EventInterface $event, \Alserom\Viber\Api $api) {
    // Your logic here
};

$bot->on('message', $handler);

// Or use helper methods
$bot->onMessage($handler);
```

### Handling Viber callbacks

[](#handling-viber-callbacks)

Viber expecting you to return a response with HTTP status code 200 for be sure that callback was delivered. Also, once a `conversation_started` callback is received you can send a welcome message to the user by returning a response with a prepared message.
This package took care of this. The method `\Alserom\Viber\Bot :: handle` will return the generated response, which remains simply to emit.

You can use [`nyholm/psr7-server`](https://github.com/Nyholm/psr7-server) package or any alternative to create server requests from PHP superglobals.
You can use [`zendframework/zend-httphandlerrunner`](https://github.com/zendframework/zend-httphandlerrunner) package or any alternative to emitting PSR-7 responses.

```
composer require nyholm/psr7-server zendframework/zend-httphandlerrunner
```

```
$serverRequestCreator = new \Nyholm\Psr7Server\ServerRequestCreator(
    $psr17Factory, // \Psr\Http\Message\ServerRequestFactoryInterface
    $psr17Factory, // \Psr\Http\Message\UriFactoryInterface
    $psr17Factory, // \Psr\Http\Message\UploadedFileFactoryInterface
    $psr17Factory  // \Psr\Http\Message\StreamFactoryInterface
);

$serverRequest = $serverRequestCreator->fromGlobals();

// $response is a PSR-7 Response object
$response = $bot->handle($serverRequest);

$emitter = new \Zend\HttpHandlerRunner\Emitter\SapiEmitter();
$emitter->emit($response);
```

TODO list
---------

[](#todo-list)

- Write documentation
- Create to more tests
- See `@TODO` tags in the code

Contributing
------------

[](#contributing)

Pull requests are welcome.

Before you make a PR, be sure that your code is suited to be merged. Just run several scripts:

```
composer test
composer check-code
composer check-style
```

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

See more
--------

[](#see-more)

- [Viber REST API](https://developers.viber.com/docs/api/rest-bot-api/)
- [Viber Node.JS Bot API](https://viber.github.io/docs/api/nodejs-bot-api/)
- [Viber Python Bot API](https://viber.github.io/docs/api/python-bot-api/)
- [Tools, boilerplates and more from Viber API's open-source contributors. ](https://viber.github.io/community/)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2571d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0deb77952c2be4970c633e85eec012e6361a3ff302983a4c05937b4a8f4dd645?d=identicon)[alserom](/maintainers/alserom)

---

Top Contributors

[![alserom](https://avatars.githubusercontent.com/u/6888689?v=4)](https://github.com/alserom "alserom (6 commits)")

---

Tags

apibotviberapibotviber

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alserom-viber-php/health.svg)

```
[![Health](https://phpackages.com/badges/alserom-viber-php/health.svg)](https://phpackages.com/packages/alserom-viber-php)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M648](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[windwalker/framework

The next generation PHP framework.

25639.1k1](/packages/windwalker-framework)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[neos/flow

Flow Application Framework

862.0M450](/packages/neos-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
