zelenin / telegram-bot-api
Telegram Bot API 客户端
1.5.0
2016-08-25 13:40 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
Suggests
- ext/pcntl: Usage of signal handler
This package is not auto-updated.
Last update: 2024-09-11 15:19:00 UTC
README
安装
Composer
安装此扩展的首选方式是通过 Composer。
运行以下命令:
php composer.phar require "zelenin/telegram-bot-api" "~1.0"
或者添加以下内容到你的 composer.json
文件中的 require 部分:
"zelenin/telegram-bot-api": "~1.0"
用法
$api = ApiFactory::create($token); try { $response = $api->sendMessage([ 'chat_id' => $chatId, 'text' => 'Test message' ]); print_r($response); $response = $api->sendPhoto([ 'chat_id' => $myId, 'photo' => fopen('/home/www/photo.jpg', 'r') ]); print_r($response); } catch (\Zelenin\Telegram\Bot\Exception\NotOkException $e) { echo $e->getMessage(); }
有关其他方法的说明,请参阅 Bot API 文档。
守护进程
$api = ApiFactory::create($token); $daemon = new \Zelenin\Telegram\Bot\Daemon\NaiveDaemon($api); $daemon ->onUpdate(function (\Zelenin\Telegram\Bot\Type\Update $update) { print_r($update); }); $daemon->run();