tigris / tigris
Tigris 是一个用 PHP 编写的现代 Telegram 机器人框架
0.2.5
2017-07-31 11:55 UTC
Requires
- php: >=7.0
- react/react: ^0.4.2
- tigris/telegram-bot-api: ~3.2
- yarcode/simple-events: *
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2024-09-23 06:23:02 UTC
README
Tigris 是一个用 PHP 编写的现代反应式事件驱动的 Telegram 机器人框架。
用法
不扩展 Bot 类
创建机器人实例
$bot = (new BotFactory())->create($apiToken);
定义自定义事件处理器
$bot = (new BotFactory())->create($apiToken); $bot->addListener(MessageEvent::EVENT_TEXT_MESSAGE_RECEIVED, function (MessageEvent $event) use ($bot) { // sending your first message $bot->getApi()->sendMessage([ 'chat_id' => $event->message->chat->id, 'text' => 'Hello World!', ]); });
运行你的机器人
$bot->run();
扩展 Bot 类
扩展 Tigris\Bot 类以创建自己的机器人实现
class SampleBot extends \Tigris\Bot { // bootstraping your bot public function bootstrap() { // registering event callback $this->addListener(MessageEvent::EVENT_TEXT_MESSAGE_RECEIVED, function (MessageEvent $event) { // sending your first message $this->getApi()->sendMessage([ 'chat_id' => $event->message->chat->id, 'text' => 'Hello World!', ]); }); } }
运行机器人实例
$bot = (new BotFactory(SampleBot::class))->create($apiToken); $bot->run();
许可证
MIT