tg-bot-api / bot-api-base
Clear and simple Telegram bot API
Installs: 59 267
Dependents: 2
Suggesters: 0
Security: 0
Stars: 225
Watchers: 17
Forks: 70
Open Issues: 4
Requires
- php: >7.3
- ext-fileinfo: *
- ext-json: *
- phpdocumentor/reflection-docblock: ^4.3|^5.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- symfony/property-access: ^3.4|^4.3|^5.0|^6.0
- symfony/property-info: ^3.4|^4.3|^5.0|^6.0
- symfony/serializer: ^3.4|^4.3|^5.0|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13
- phpro/grumphp: ^1.1.0
- phpstan/phpstan: ^0.10.6|^0.12.20
- phpunit/phpunit: ^8.5
- povils/phpmnd: ^2.0
- sebastian/phpcpd: ^5.0
- squizlabs/php_codesniffer: ^3.4
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.4
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- dev-master / 1.0.x-dev
- 1.0.2
- 1.0.1
- 1.0.0
- 0.4.0-beta
- 0.3.0-beta
- 0.2.0-beta
- 0.1.0-beta
- dev-feature/+48-update-readme-and-rename-workflow
- dev-feature/+48-replace-travis-to-github-actions
- dev-Big-Shark-patch-1
- dev-feature/+30-add-posibility-to-reply-webhook
This package is auto-updated.
Last update: 2024-12-18 04:49:28 UTC
README
Supported Telegram Bot API 5.0 (November 4, 2020)
Installation
Via Composer
composer require tg-bot-api/bot-api-base --prefer-dist
Usage
We support all psr17 and psr18 implementations, but we will use guzzle6 for example
composer require php-http/guzzle6-adapter http-interop/http-factory-guzzle --prefer-dist
$botKey = '<bot key>'; $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $streamFactory = new Http\Factory\Guzzle\StreamFactory(); $client = new Http\Adapter\Guzzle6\Client(); $apiClient = new \TgBotApi\BotApiBase\ApiClient($requestFactory, $streamFactory, $client); $bot = new \TgBotApi\BotApiBase\BotApi($botKey, $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer()); $userId = '<user id>'; $bot->send(\TgBotApi\BotApiBase\Method\SendMessageMethod::create($userId, 'Hi'));
You can configure it to work in symfony, for example, in this way.
If you want to use your own api server - you can set url as 4th param in bot api
$bot = new \TgBotApi\BotApiBase\BotApi('<bot key>', $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer(), '<your-domain>');
Allowed methods:
Implemented all methods and types referenced by official Api
You can use BotApiComplete
instance as helper to call
all methods from official Api like this:
$botKey = '<bot key>'; $requestFactory = new Http\Factory\Guzzle\RequestFactory() $streamFactory = new Http\Factory\Guzzle\StreamFactory(); $client = new Http\Adapter\Guzzle6\Client(); $apiClient = new \TgBotApi\BotApiBase\ApiClient($requestFactory, $streamFactory, $client); $bot = new \TgBotApi\BotApiBase\BotApiComplete($botKey, $apiClient, new \TgBotApi\BotApiBase\BotApi\BotApiNormalizer()); $userId = '<user id>'; $bot->sendMessage(\TgBotApi\BotApiBase\Method\SendMessageMethod::create($userId, 'Hi'));
Fetching webhooks
Method fetch()
of WebhookFetcher handling Psr\Http\Message\RequestInterface or string and always returns instance of UpdateType or throwing BadRequestException.
$fetcher = new \TgBotApi\BotApiBase\WebhookFetcher(new \TgBotApi\BotApiBase\BotApiNormalizer()); $update = $fetcher->fetch($request);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email wformps@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.