PHP code example of romanlazko / laravel-telegram

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

    

romanlazko / laravel-telegram example snippets


namespace App\Telegram\MyBot\Commands;

use Romanlazko\LaravelTelegram\Command;
use Romanlazko\LaravelTelegram\Models\Types\Chat;

class DefaultCommand extends Command
{
    public function execute(Chat $chat)
    {
        $this->apiMethod('sendMessage');
        $this->text('My first command!');
        $this->chatId($chat->id);
        $this->parseMode('Markdown');

        return $this->send();
    }

    public function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
    {
        return match ($parameterName) {
            'update' => [$this->getObject()],
            'message' => [$this->evaluate(fn ($update) => $update->message ?? $update->callback_query->message)],
            'chat' => [$this->evaluate(fn ($message) => $message->chat)],
            default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
        };
    }
}
bash
php artisan vendor:publish --tag=laravel-telegram-migrations
bash
php artisan telegram:bot YOUR_BOT_TOKEN

app/Providers/Telegram/BotNameProvider.php
bash
php artisan telegram:set-webhook telegram_bot_id
bash
php artisan telegram:command DefaultCommand

app/Telegram/BotName/Commands/DefaultCommand.php