steadfast / telegram-bot-api
用PHP编写的Telegram Bot API
2.3.0
2018-09-24 21:26 UTC
Requires
- php: >=5.5.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-25 11:54:24 UTC
README
一个扩展的本地Telegram Bot API,无需依赖。支持所有方法和响应类型。
安装
composer require steadfast/telegram-bot-api
客户端使用
如何发送消息
use TelegramBot\Api\BotApi; $bot = new BotApi($bot_api_token); $bot->sendMessage($chat_id, $message_text);
服务器使用
处理命令
use TelegramBot\Api\Client; $bot = new Client($bot_api_token); $bot->command('ping', function ($message) use ($bot) { $bot->sendMessage($message->getChat()->getId(), 'pong!'); });
处理机器人被添加到群组的事件
use TelegramBot\Api\Client; $bot = new Client($bot_api_token); $bot->wasAddedToAGroup(function ($message) use ($bot) { $bot->sendMessage($message->getChat()->getId(), "Let's welcome our new member!"); });
处理机器人被移除出群组的事件
use TelegramBot\Api\Client; $bot = new Client($bot_api_token); $bot->wasRemovedFromAGroup(function ($message) use ($bot) { $bot->sendMessage($message->getChat()->getId(), "Say goodbye to our friend!"); });
处理任何事件
use TelegramBot\Api\Client; $bot = new Client($bot_api_token); $bot->on(function ($update) { echo $update->getUpdateId(); });