tigris / tigris
Tigris is a modern Telegram bot framework written in PHP
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-11-18 07:03:07 UTC
README
Tigris is a modern reactive event-driven Telegram bot framework written in PHP.
Usage
Without extending the Bot class
Create a bot instance
$bot = (new BotFactory())->create($apiToken);
Define your custom even handlers
$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!', ]); });
Run your bot
$bot->run();
Extending the Bot class
Extend the Tigris\Bot class to create your own bot implementation
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!', ]); }); } }
Run the bot instance
$bot = (new BotFactory(SampleBot::class))->create($apiToken); $bot->run();
License
MIT