PHP code example of shokhaa / tg-bot-lib

1. Go to this page and download the library: Download shokhaa/tg-bot-lib 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/ */

    

shokhaa / tg-bot-lib example snippets




use Shokhaa\BotLib\Bot;
use Shokhaa\BotLib\Example\ChatStartHandler;

   $bot = new Bot($requestBody, [
        'historyEnabled' => true,
        'token'          => 'telegram bot token',
        'db'             => [
            'dsn'      => 'pgsql:host=localhost;dbname=dbName',
            'user'     => 'databaseUser',
            'password' => 'databasePassword',
        ]
    ]);
    $bot->handler()->on(ChatStartHandler::class);
} catch (Throwable $exception) {
    throw new Exception($exception->getMessage());
}




use Shokhaa\BotLib\Bot;
use Shokhaa\BotLib\Example\ChatStartHandler;

   $bot = new Bot($requestBody, [
        'historyEnabled' => false,
        'token'          => 'telegram bot token',
    ]);
    $bot->handler()->on(ChatStartHandler::class);
} catch (Throwable $exception) {
    throw new Exception($exception->getMessage());
}