PHP code example of hybridgram / tgbot-laravel

1. Go to this page and download the library: Download hybridgram/tgbot-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hybridgram / tgbot-laravel example snippets




use HybridGram\Facades\TelegramRouter;
use HybridGram\Core\Routing\RouteData\TextMessageData;
use HybridGram\Core\Routing\RouteData\PollData;
use HybridGram\Telegram\Poll\PollType;
use HybridGram\Telegram\TelegramBotApi;

TelegramRouter::group(['for_bot' => 'main'], function (\HybridGram\Core\Routing\TelegramRouteBuilder $builder) {
    $builder->onTextMessage(function (TextMessageData $message) {
        $api = app(TelegramBotApi::class);
        $api->sendMessage($message->getChatId(), "Echo: {$message->text}");
    });
    // you can use any of route
//   $builder->onPoll(function (PollData $poll) {
//        $api = app(TelegramBotApi::class);
//        $api->sendMessage(
//            $poll->getChatId(),
//            "Poll received ({$poll->poll->type}) with " . count($poll->poll->options) . " options"
//        );
//    }, pollType: PollType::REGULAR);
});
bash
php artisan hybridgram:polling --hot-reload