{"id":33963185,"url":"https://github.com/alserom/viber-php","last_synced_at":"2026-04-10T03:02:37.758Z","repository":{"id":56946365,"uuid":"181213265","full_name":"alserom/viber-php","owner":"alserom","description":"Unofficial library to work with Viber REST API and for develop a bot for the Viber platform.","archived":false,"fork":false,"pushed_at":"2022-03-21T02:54:40.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T11:28:00.822Z","etag":null,"topics":["api","bot","viber"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alserom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-13T18:32:34.000Z","updated_at":"2021-06-01T10:23:33.000Z","dependencies_parsed_at":"2022-08-21T02:40:30.317Z","dependency_job_id":null,"html_url":"https://github.com/alserom/viber-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alserom/viber-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alserom%2Fviber-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alserom%2Fviber-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alserom%2Fviber-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alserom%2Fviber-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alserom","download_url":"https://codeload.github.com/alserom/viber-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alserom%2Fviber-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27693331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bot","viber"],"created_at":"2025-12-12T22:28:09.421Z","updated_at":"2025-12-30T15:05:20.877Z","avatar_url":"https://github.com/alserom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP SDK for Viber REST API [![Latest Stable Version](https://img.shields.io/packagist/v/alserom/viber-php.svg?label=stable\u0026style=flat-square)](https://packagist.org/packages/alserom/viber-php) [![Latest Unstable Version](https://img.shields.io/packagist/vpre/alserom/viber-php.svg?label=unstable\u0026style=flat-square)](https://packagist.org/packages/alserom/viber-php#dev-master)\n\n[![Build Status](https://img.shields.io/travis/alserom/viber-php.svg?style=flat-square)](https://travis-ci.org/alserom/viber-php)\n[![Minimum PHP Version](https://img.shields.io/packagist/php-v/alserom/viber-php.svg?style=flat-square)](https://www.php.net/supported-versions.php)\n[![Coding Style](https://img.shields.io/badge/code%20style-PSR--12-informational.svg?style=flat-square)](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md)\n[![Software License](https://img.shields.io/github/license/alserom/viber-php.svg?style=flat-square)](LICENSE)\n\nUse 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/).\n\n\u003e 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.\n\n## Installation\n\n```bash\ncomposer require alserom/viber-php\n```\n\nFor properly work with this package you do also need to install a PSR-17 request/response factory and PSR-18 HTTP Client.  \nYou can find packages of these implementations here:\n- [List of PSR-17 implementations](https://packagist.org/providers/psr/http-factory-implementation)\n- [List of PSR-18 implementations](https://packagist.org/providers/psr/http-client-implementation)\n\nExample:\n\n```bash\ncomposer require nyholm/psr7 kriswallsmith/buzz\n```\n\n## Usage\n\nThis page will just show you the basics. For advanced usage, please read the full [documentation](docs/README.md).\n\nIf 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).\n\n### Create objects\n\n```php\n// Any PSR-17 implementation. In this case, we use 'nyholm/psr7' package.\n$psr17Factory = new \\Nyholm\\Psr7\\Factory\\Psr17Factory();\n\n// Any PSR-18 implementation. In this case, we use 'kriswallsmith/buzz' package.\n$psr18Client = new \\Buzz\\Client\\Curl($psr17Factory);\n\n/* A simple object for getting all PSR-17 factories.\n * If you have an object which implements all PSR-17 interfaces, you can use a static method. E.g:\n * $psr17 = \\Alserom\\Viber\\Psr17::useForAll($psr17Factory);\n */\n$psr17 = new \\Alserom\\Viber\\Psr17(\n    $psr17Factory, // \\Psr\\Http\\Message\\RequestFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\ResponseFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\ServerRequestFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\StreamFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\UploadedFileFactoryInterface\n    $psr17Factory  // \\Psr\\Http\\Message\\UriFactoryInterface\n);\n\n$token = 'YOUR-AUTHENTICATION-TOKEN';\n\n/* An object for work with Viber API.\n * As a fourth argument, you can pass an array of options. See the full documentation for more info.\n */\n$api = new \\Alserom\\Viber\\Api($token, $psr17, $psr18Client);\n\n/* An object for creating a logic of Viber bot.\n * As a second argument, you can pass an array of options. See the full documentation for more info.\n */\n$bot = new \\Alserom\\Viber\\Bot($api);\n```\n\n### Setting a Webhook\n\n```php\n$url = 'YOUR-HTTPS-WEBHOOK-URL';\n$webhook = new \\Alserom\\Viber\\Entity\\Webhook($url);\n\n// If you want that your bot receives user names instead of placeholder values.\n// $webhook-\u003esetSendName(true);\n\n// If you want that your bot receives user photos instead of placeholder values.\n// $webhook-\u003esetSendPhoto(true); \n\n// If you want to filter which events would get a callback for.\n// $webhook-\u003esetEventTypes(['delivered', 'seen', 'conversation_started']); \n\n$api-\u003esetWebhook($webhook);\n```\n\n### Sending message\n\nBuild a message from scratch:\n```php\n$message = new \\Alserom\\Viber\\Message('text');\n$message\n    -\u003esetText('Hello World!')\n    -\u003esetTo(new \\Alserom\\Viber\\Entity\\User('USER-IDENTIFIER-HERE'));\n\n// $response is a \\Alserom\\Viber\\Response\\Type\\SendMessageResponse object.\n$response = $api-\u003esendMessage($message);\n```\n\nOr use prepared entity:\n```php\n$entity = new \\Alserom\\Viber\\Entity\\Message\\Text();\n$entity-\u003esetText('Hello World!');\n\n$message = new \\Alserom\\Viber\\Message();\n$message-\u003esetTo(new \\Alserom\\Viber\\Entity\\User('USER-IDENTIFIER-HERE'));\n$message-\u003esetEntity($entity);\n\n$response = $api-\u003esendMessage($message);\n```\n\n### Registering events (Viber callbacks) handlers\n\n```php\n$handler = function (\\Alserom\\Viber\\Event\\EventInterface $event, \\Alserom\\Viber\\Api $api) {\n    // Your logic here\n};\n\n$bot-\u003eon('message', $handler);\n\n// Or use helper methods\n$bot-\u003eonMessage($handler);\n```\n\n### Handling Viber callbacks\n\nViber expecting you to return a response with HTTP status code 200 for be sure that callback was delivered.\nAlso, once a `conversation_started` callback is received you can send a welcome message to the user by returning a response with a prepared message.  \nThis package took care of this. The method `\\Alserom\\Viber\\Bot :: handle` will return the generated response, which remains simply to emit.\n\nYou can use [`nyholm/psr7-server`](https://github.com/Nyholm/psr7-server) package or any alternative to create server requests from PHP superglobals.  \nYou can use [`zendframework/zend-httphandlerrunner`](https://github.com/zendframework/zend-httphandlerrunner) package or any alternative to emitting PSR-7 responses.\n\n```bash\ncomposer require nyholm/psr7-server zendframework/zend-httphandlerrunner\n```\n\n```php\n$serverRequestCreator = new \\Nyholm\\Psr7Server\\ServerRequestCreator(\n    $psr17Factory, // \\Psr\\Http\\Message\\ServerRequestFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\UriFactoryInterface\n    $psr17Factory, // \\Psr\\Http\\Message\\UploadedFileFactoryInterface\n    $psr17Factory  // \\Psr\\Http\\Message\\StreamFactoryInterface\n);\n\n$serverRequest = $serverRequestCreator-\u003efromGlobals();\n\n// $response is a PSR-7 Response object\n$response = $bot-\u003ehandle($serverRequest);\n\n$emitter = new \\Zend\\HttpHandlerRunner\\Emitter\\SapiEmitter();\n$emitter-\u003eemit($response);\n```\n\n## TODO list\n\n- Write documentation\n- Create to more tests\n- See `@TODO` tags in the code\n\n## Contributing\n\nPull requests are welcome.\n\nBefore you make a PR, be sure that your code is suited to be merged. Just run several scripts:\n```bash\ncomposer test\ncomposer check-code\ncomposer check-style\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## See more\n\n- [Viber REST API](https://developers.viber.com/docs/api/rest-bot-api/)\n- [Viber Node.JS Bot API](https://viber.github.io/docs/api/nodejs-bot-api/)\n- [Viber Python Bot API](https://viber.github.io/docs/api/python-bot-api/)\n- [Tools, boilerplates and more from Viber API's open-source contributors. ](https://viber.github.io/community/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falserom%2Fviber-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falserom%2Fviber-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falserom%2Fviber-php/lists"}