PHP code example of unreal4u / telegram-api

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

    

unreal4u / telegram-api example snippets




use Clue\React\Socks\Client;

$loop = Factory::create();
// Replace PROXY_ADDRESS and PROXY_PORT with the correct configuration
$proxy = new Client('socks5://' . PROXY_ADDRESS . ':' . PROXY_PORT, new Connector($loop));
$handler = new HttpClientRequestHandler($loop, [
    'tcp' => $proxy,
    'timeout' => 3.0,
    'dns' => false
]);

$this->tgLog = new TgLog(BOT_TOKEN, $handler);
// The rest is exactly the same as it normally is, see the examples folder for more information



use \unreal4u\TelegramAPI\HttpClientRequestHandler;
use \unreal4u\TelegramAPI\TgLog;
use \unreal4u\TelegramAPI\Telegram\Methods\SendMessage;

$loop = \React\EventLoop\Factory::create();
$handler = new HttpClientRequestHandler($loop);
$tgLog = new TgLog(BOT_TOKEN, $handler);

$sendMessage = new SendMessage();
$sendMessage->chat_id = A_USER_CHAT_ID;
$sendMessage->text = 'Hello world!';

$tgLog->performApiRequest($sendMessage);
$loop->run();