PHP code example of top-tl / toptl-php-telegram-bot

1. Go to this page and download the library: Download top-tl/toptl-php-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/ */

    

top-tl / toptl-php-telegram-bot example snippets


use TopTL\Client as TopTLClient;
use TopTL\PhpTelegramBot\TopTLPlugin;

$client = new TopTLClient('your-toptl-token');
$plugin = new TopTLPlugin($client, 'my_bot');

// In your bot's update handling loop:
foreach ($updates as $update) {
    $plugin->handleUpdate($update);
    // ... your command handling ...
}

// Post stats (call periodically, e.g. via cron):
$plugin->postStats();

// Check if a user voted:
if ($plugin->hasVoted($userId)) {
    // User has voted
}
bash
composer