tg-bot-api / bot-api-base
简洁明了的Telegram机器人API
1.8.0
2022-05-17 22:58 UTC
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-09-18 04:23:35 UTC
README
支持Telegram机器人API 5.0(2020年11月4日)
安装
通过Composer
composer require tg-bot-api/bot-api-base --prefer-dist
使用方法
我们支持所有psr17和psr18实现,但将以guzzle6为例
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'));
您可以将它配置为在symfony中工作,例如,在这种方式。
如果您想使用自己的API服务器 - 您可以在bot api中将url设置为第4个参数
$bot = new \TgBotApi\BotApiBase\BotApi('<bot key>', $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer(), '<your-domain>');
允许的方法
实现了官方Api中引用的所有方法和类型
您可以使用BotApiComplete
实例作为辅助来调用官方Api中的所有方法,如下所示
$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'));
获取webhooks
WebhookFetcher的fetch()
方法处理Psr\Http\Message\RequestInterface或字符串,并始终返回UpdateType实例或抛出BadRequestException。
$fetcher = new \TgBotApi\BotApiBase\WebhookFetcher(new \TgBotApi\BotApiBase\BotApiNormalizer()); $update = $fetcher->fetch($request);
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
贡献
有关详细信息,请参阅CONTRIBUTING和CODE_OF_CONDUCT。
安全性
如果您发现任何安全相关的问题,请通过wformps@gmail.com发送电子邮件,而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。