tigris/tigris

Tigris is a modern Telegram bot framework written in PHP

0.2.5 2017-07-31 11:55 UTC

This package is not auto-updated.

Last update: 2024-04-08 03:56:25 UTC


README

Build Status Join the chat at https://gitter.im/tigris-php/tigris GitHub license

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