maatify / telegram-bot
非官方的 Telegram SDK for PHP,它是 maatify.dev Telegram Bot 处理库,我们团队已知
2.0.0012
2024-08-05 06:01 UTC
Requires
- php: >=8.0
- ext-curl: *
- maatify/functions: ^1.2
- maatify/logger: ^1.0
README
安装
composer require maatify/telegram-bot
https://core.telegram.org/bots/api#available-methods // telegram api 参考资料
使用方法
实例
use Maatify\TelegramBot\TelegramBotManager; require __DIR__ . '/vendor/autoload.php'; $telegram = TelegramBotManager::obj(__YOUR_API_KEY__); // instance of bot manager
GetMe
获取机器人信息
一个简单的测试机器人认证令牌的方法。不需要参数。以 User 对象的形式返回机器人的基本信息。
$response = $telegram->Methods()->GetMe(); // get bot account information print_r($response);
注销
使用此方法在启动本地机器人之前从云机器人 API 服务器注销。您必须在本地运行机器人之前注销机器人,否则无法保证机器人会收到更新。成功调用后,您可以直接在本地服务器上登录,但将在 10 分钟内无法再次登录到云机器人 API 服务器。成功时返回 True。不需要参数。
$logout = $telegram->Methods()->Logout(); print_r($logout);
关闭
使用此方法在将机器人实例从一个本地服务器移动到另一个之前关闭机器人实例。在调用此方法之前需要删除 webhook,以确保在服务器重启后机器人不会被再次启动。在机器人启动后的前 10 分钟内,该方法将返回错误 429。成功时返回 True。不需要参数。
$close = $telegram->Methods()->Close(); print_r($close);
Webhook
- WEBHOOK 使用方法和示例 - WEBHOOK.md
发送者
- 发送文件、消息、动作示例 - SENDER.md
更新
- (获取更新列表,Webhook 应该不设置) 示例 - UPDATES.md
GetChat
通过 chat_id 获取聊天
$chat = $telegram->GetChat(123456); // set getChat by chat_id $by_chat = $chat->Get(); // get array of getChat $chat_id = $chat->GetID(); // get id from getChat by chat_id $chat_first_name = $chat->GetFirstName(); // get first_name from getChat $chat_last_name = $chat->GetLastName(); // get last_name from getChat $chat_username = $chat->GetUsername(); // get username from getChat $chat_type = $chat->GetType(); // get type from getChat $chat_active_username = $chat->GetActiveUsername(); // get array of active_username from getChat
getUserProfilePhotos
使用此方法获取用户个人照片列表。返回 UserProfilePhotos 对象。
try { $telegram->Downloader()->DownloadUserProfilePhotos($user_id); } catch (Exception $e) { print_r($e->getMessage()); }
登录页面示例
- 您可以使用您的机器人创建登录页面示例 - LOGIN.md