Core: Blocked Telegram in Russia

Created on 17 Apr 2018  路  13Comments  路  Source: php-telegram-bot/core

As you know, telegrams were blocked in Russia and this caused difficulties in working with the bot. Can I add a proxy to the core when I request it?

Most helpful comment

As @jacklul already mentioned, just set the proxy client before handling the request.

Here is an example for using a local Tor proxy with SOCKS5:

$telegram = new Telegram(...);
...
Request::setClient(new Client([
    'base_uri' => 'https://api.telegram.org',
    'proxy'    => 'socks5://127.0.0.1:9050',
]));
...
$telegram->handle();

All 13 comments

I can edit it only in files libary or i can

Request::setClient(new \GuzzleHttp\Client([
                'base_uri' => 'https://api.telegram.org',
                'proxy' => 'http://proxy',
            ]));  

?

if i have proxy with login and password, structure of string like this:
http://login:password@ip:port ?

...
$telegram = new Telegram($apiKey, $botName);
Request::setClient(new \GuzzleHttp\Client([
        'base_uri' => 'https://api.telegram.org',
        'proxy' => 'http://111.111.111.111:1080',
]));
...

if i have proxy with login and password, structure of string like this:
http://login:password@ip:port ?
Yes

Thanks

You shouldn't edit it inside library, put the code I linked into your hook script /before handling updates.

As @jacklul already mentioned, just set the proxy client before handling the request.

Here is an example for using a local Tor proxy with SOCKS5:

$telegram = new Telegram(...);
...
Request::setClient(new Client([
    'base_uri' => 'https://api.telegram.org',
    'proxy'    => 'socks5://127.0.0.1:9050',
]));
...
$telegram->handle();

set.php:

try {
    // Create Telegram API object
    $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);

    $telegram = Request::setClient(new \GuzzleHttp\Client([    'proxy'    => 'socks5://alex:[email protected]:8088',]));

    // Set webhook
    $result = $telegram->setWebhook($hook_url);

    // Uncomment to use certificate
    //$result = $telegram->setWebhook($hook_url, ['certificate' => $path_certificate]);

...
PHP Fatal error: Uncaught Error: Class 'Request' not found in var/www/help.xxx.net/xxx/telegram/set.php:12

How to enable it right?

@kirush0280

  1. You have to import Request class first
  2. You do not need assign Request::setClient call to $telegram variable

Thank you. It works.

Also when your DNS traffic is spoofed you should to use 'proxy' => 'socks5h:// against socks5:// whithout h

Hi! @akalongman would you please tell what kind of Request it is, from which library?

@timurkayzer

\Longman\TelegramBot\Request

thanks it worked like a charm!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abbe-cipher picture abbe-cipher  路  4Comments

NabiKAZ picture NabiKAZ  路  4Comments

sineverba picture sineverba  路  3Comments

smaznet picture smaznet  路  4Comments

marcolino7 picture marcolino7  路  3Comments