PHP code example of appto-team / telegram-bot

1. Go to this page and download the library: Download appto-team/telegram-bot 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/ */

    

appto-team / telegram-bot example snippets


// app/GreetBot/GreetBot.php
final class GreetBot extends Bot
{
    protected function boot(): void
    {
        $this->onCommand('start', StartCommand::class);
    }
}

// app/GreetBot/Commands/StartCommand.php
final class StartCommand implements CommandHandler
{
    public function handle(UpdateContext $context): void
    {
        $context->reply('Привет! Я на связи 👋');
    }
}

// config/telegram-bot.php
'bots' => [
    'greet' => [
        'token' => env('TELEGRAM_BOT_TOKEN'),
        'webhook_secret' => env('TELEGRAM_BOT_WEBHOOK_SECRET'),
        'handler' => \App\GreetBot\GreetBot::class,
    ],
],

// app/GreetBot/GreetBot.php
final class GreetBot extends Bot
{
    protected function boot(): void
    {
        $this->onCommand('start', StartCommand::class);
    }
}

// app/GreetBot/Commands/StartCommand.php
final class StartCommand implements CommandHandler
{
    public function handle(UpdateContext $context): void
    {
        $context->reply('Hi! I\'m here 👋');
    }
}

// config/telegram-bot.php
'bots' => [
    'greet' => [
        'token' => env('TELEGRAM_BOT_TOKEN'),
        'webhook_secret' => env('TELEGRAM_BOT_WEBHOOK_SECRET'),
        'handler' => \App\GreetBot\GreetBot::class,
    ],
],
bash
php artisan telegram:poll greet
bash
php artisan telegram:poll greet