tg-bot-api/bot-api-base
Composer 安装命令:
composer require tg-bot-api/bot-api-base
包简介
Clear and simple Telegram bot API
关键字:
README 文档
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:
| Method | Allowed type | response |
|---|---|---|
add |
AddStickerToSetMethod | bool |
answer |
AnswerCallbackQueryMethod, AnswerInlineQueryMethod, AnswerPreCheckoutQueryMethod, AnswerShippingQueryMethod | bool |
create |
CreateNewStickerSetMethod | bool |
delete |
DeleteChatPhotoMethod, DeleteChatStickerSetMethod, DeleteMessageMethod, DeleteStickerFromSetMethod, DeleteWebhookMethod | bool |
edit |
EditMessageCaptionMethod, EditMessageLiveLocationMethod, EditMessageMediaMethod, EditMessageReplyMarkupMethod, EditMessageTextMethod | bool |
forward |
ForwardMessageMethod | MessageType |
kick |
KickChatMemberMethod | bool |
leave |
LeaveChatMethod | bool |
pin |
PinChatMessageMethod | bool |
promote |
PromoteChatMemberMethod | bool |
restrict |
RestrictChatMemberMethod | bool |
send |
SendPhotoMethod, SendAudioMethod, SendDocumentMethod, SendVideoMethod, SendAnimationMethod, SendVoiceMethod, SendVideoNoteMethod, SendGameMethod, SendInvoiceMethod, SendLocationMethod, SendVenueMethod, SendContactMethod, SendStickerMethod, SendMessageMethod, SendPollMethod, SendDiceMethod | MessageType |
set |
SetChatDescriptionMethod, SetChatPhotoMethod, SetChatStickerSetMethod, SetChatTitleMethod, SetGameScoreMethod, SetStickerPositionInSetMethod, SetWebhookMethod, SetPassportDataErrorsMethod, SetChatPermissionsMethod, SetChatAdministratorCustomTitleMethod, SetMyCommandMethod, SetStickerSetThumbMethod | bool |
stop |
StopMessageLiveLocationMethod | bool |
stopPoll |
StopPollMethod | Poll |
unban |
UnbanChatMemberMethod | bool |
unpin |
UnpinChatMessageMethod, UnpinAllChatMessagesMethod | bool |
upload |
UploadStickerFileMethod | FileType |
exportChatInviteLink |
ExportChatInviteLinkMethod | string |
sendChatAction |
SendChatActionMethod | bool |
getUpdates |
GetUpdatesMethod | UpdateType[] |
getMe |
GetMeMethod | UserType |
getMyCommands |
GetMyCommandsMethod | BotCommandType |
getUserProfilePhotos |
GetUserProfilePhotosMethod | UserProfilePhotosType |
getWebhookInfo |
GetWebhookInfoMethod | WebhookInfoType |
getChatMembersCount |
GetChatMembersCountMethod | int |
getChat |
GetChatMethod | ChatType |
getChatAdministrators |
GetChatAdministratorsMethod | ChatMemberType[] |
getChatMember |
GetChatMemberMethod | ChatMemberType |
getChatMenuButton |
GetChatMenuButtonMethod | MenuButtonType |
getGameHighScores |
GetGameHighScoresMethod | GameHighScoreType[] |
getStickerSet |
GetStickerSetMethod | StickerSetType |
getFile |
GetFileMethod | FileType |
sendMediaGroup |
SendMediaGroupMethod | MessageType[] |
getAbsoluteFilePath |
FileType | string |
logOut |
LogOutMethod | bool |
close |
CloseMethod | bool |
copyMessage |
CopyMessageMethod | MessageIdType |
call($method, [string $type]) |
any method class, [optional expected type] | array or excepted type object |
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.
tg-bot-api/bot-api-base 适用场景与选型建议
tg-bot-api/bot-api-base 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81.56k 次下载、GitHub Stars 达 222, 最近一次更新时间为 2019 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bot」 「php-bot」 「telegram」 「telegram-bot」 「Telegram-Bot-API」 「tg-bot-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tg-bot-api/bot-api-base 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tg-bot-api/bot-api-base 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tg-bot-api/bot-api-base 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
Laravel 5.6 Monolog custom telegram channel
PHP Wrapper for Telegram Bot API
VK driver for botman
Telegram bot integration with laravel
PHP class-based framework to create Telegram Bots using webhook.
统计信息
- 总下载量: 81.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 222
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-11