PHP code example of webpajooh / telebot

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

    

webpajooh / telebot example snippets


try {
    $tg = new TeleBot('YOUR_BOT_TOKEN');
} catch (Throwable $th) {...}

$tg->editMessageText([...])

$tg->listen('/start', function () use ($tg) {
    $tg->sendMessage([
        'chat_id' => $tg->user->id,
	'text' => 'Hello, world!',
    ]);
}, false);

$tg->listen('set_age_%d', function ($age) use ($tg) {
    // TODO
});

Logger::log($tg->user->id);
tl($tg->user->id); // Does the same thing

$keyboard = (new InlineKeyboard())
    ->addCallbackButton('📕 Help', 'help_callback')
    ->addUrlButton('📱 Share', 'https://t.me/share/url?url=https://t.me/your_awesome_bot&text=Some text')
    ->chunk(1)
    ->rightToLeft()
    ->get();

$tg->sendMessage([
    // Other parameters
    'reply_markup' => $keyboard,
]);

$tg->setDefaults('sendMessage', ['parse_mode' => 'html']); // You will not need passing parse_mode anymore
$tg->setDefaults(['sendMessage', 'banChatMember'], ['chat_id' => $chatId]);
$tg->setDefaults('*', ['chat_id' => $chatId]); // a default parameter for all methods

TeleBot::extend('isReply', function () {
    return property_exists($this->message, 'reply_to_message');
});

if ($tg->isReply()) { ... }