Node-telegram-bot-api: How to deal with russian telegram blocking?

Created on 16 Apr 2018  路  16Comments  路  Source: yagop/node-telegram-bot-api

How to bypass the telegram block in russia?

proxy question

Most helpful comment

@Osrx
You can use SOCKS5 proxy with the socks5-https-client lib. Example:

const TelegramBot = require('node-telegram-bot-api')
const Agent = require('socks5-https-client/lib/Agent')

const bot = new TelegramBot(process.env.TELEGRAM_API_TOKEN, {
    polling: true,
    request: {
        agentClass: Agent,
        agentOptions: {
            socksHost: process.env.PROXY_SOCKS5_HOST,
            socksPort: parseInt(process.env.PROXY_SOCKS5_PORT),
            // If authorization is needed:
            // socksUsername: process.env.PROXY_SOCKS5_USERNAME,
            // socksPassword: process.env.PROXY_SOCKS5_PASSWORD
        }
    }
})

I use this solution to continue developing bot on my local PC (I'm in Russia, so without proxy I can not start bots) and it works.

All 16 comments

I quickly looked through code, and found that all API interactions rely on request-promise package, which supports connection through proxy

var request = require('request-promise').defaults({
    proxy:'http://username:password@host:port',
    strictSSL :false
  });

I quickly looked through code, and found that all API interactions rely on request-promise package, which supports connection through proxy

How to use it in bot?

request-promise is a wrapper around npm request - see proxy settings
You should try manually edit in /src/telegram.js at line 10:

const request = require('request-promise').defaults(/* http proxy settings here */);

Notice: it supports HTTP(s) proxies only, not socks

Thank you. This works

You should try manually edit in /src/telegram.js at line 10:

Also you can use TelegramBot options like this:

const bot = new TelegramBot(config.get('telegram_token'), {
  polling: true,
  request: {
    // Proxy settings here
    proxy: 'http:/***',
  }
});

@samohovets Thank you. This work too.

Please suggest which proxy to use?Is there any good free proxies?
@samohovets , @sand123 which proxies do u use? Do you use chargeable proxies?

Please add support of SOCKS5 proxy.
Socks proxy used as standard proxy method in Telegram app, so it will be more easy to find.

@Osrx
You can use SOCKS5 proxy with the socks5-https-client lib. Example:

const TelegramBot = require('node-telegram-bot-api')
const Agent = require('socks5-https-client/lib/Agent')

const bot = new TelegramBot(process.env.TELEGRAM_API_TOKEN, {
    polling: true,
    request: {
        agentClass: Agent,
        agentOptions: {
            socksHost: process.env.PROXY_SOCKS5_HOST,
            socksPort: parseInt(process.env.PROXY_SOCKS5_PORT),
            // If authorization is needed:
            // socksUsername: process.env.PROXY_SOCKS5_USERNAME,
            // socksPassword: process.env.PROXY_SOCKS5_PASSWORD
        }
    }
})

I use this solution to continue developing bot on my local PC (I'm in Russia, so without proxy I can not start bots) and it works.

@nskondratev can you please advise which proxies to use?
Do you use free proxy?

@IzaGz I set up proxy server on DigitalOcean droplet, which costs $5 per month.

one click to bypass Telegram block
https://telegram.solutions

I use proxy how @nskondratev supposes and have the error: "Unhandled rejection RequestError: Error: connect ECONNREFUSED 127.0.0.1:1080". How can the library call localhost?

@IzaGz you can use Tor Browser as SOCKS5 proxy.
Jast start Tor Browser and use 127.0.0.1:9150 as proxy adress.

@nskondratev
This code works correctly:

var options = {
    url: "https://api.telegram.org/bot1111111...11/getMe",
    agentClass: Agent,
    agentOptions: {
        socksHost: config.proxy.socksHost, 
        socksPort: config.proxy.socksPort,
        socksUsername: config.proxy.socksUsername,
        socksPassword: config.proxy.socksPassword
    }
}
request(options, function (error, res, html) {
  if (!error && res.statusCode == 200) {
    console.log(html)
  }else {
    console.log(error)
  }
})

But when i am trying to use "socks5-https-client" with 'node-telegram-bot-api':

const bot = new TelegramBot(config.bot.token, {
    polling: true,
    request: {
        agentClass: Agent,
        agentOptions: {
            socksHost: config.proxy.socksHost,
            socksPort: config.proxy.socksPort,
            // If authorization is needed:
             socksUsername: config.proxy.socksUsername,
             socksPassword: config.proxy.socksPassword
        }
    }
});

timeout error occurs.

Could you please help to understand why proxy is not working with 'node-telegram-bot-api'?

@IldarMurzenkov hi, what is the "config" ? Have same problem "error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED 127.0.0.1:1080"}"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacopocappelli1989 picture jacopocappelli1989  路  4Comments

saeedhei picture saeedhei  路  4Comments

qunatumwhiskey picture qunatumwhiskey  路  4Comments

mbrammer picture mbrammer  路  3Comments

abbddo picture abbddo  路  3Comments