Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with russian telegram blocking? #562

Closed
IzaGz opened this issue Apr 16, 2018 · 16 comments
Closed

How to deal with russian telegram blocking? #562

IzaGz opened this issue Apr 16, 2018 · 16 comments

Comments

@IzaGz
Copy link

IzaGz commented Apr 16, 2018

How to bypass the telegram block in russia?

@sand123
Copy link

sand123 commented Apr 17, 2018

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
  });

@bortnikov
Copy link

bortnikov commented Apr 17, 2018

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?

@sand123
Copy link

sand123 commented Apr 17, 2018

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

@bortnikov
Copy link

Thank you. This works

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

@samohovets
Copy link

samohovets commented Apr 17, 2018

Also you can use TelegramBot options like this:

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

@bortnikov
Copy link

bortnikov commented Apr 17, 2018

@samohovets Thank you. This work too.

@IzaGz
Copy link
Author

IzaGz commented Apr 17, 2018

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

@Osrx
Copy link

Osrx commented Apr 17, 2018

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

@nskondratev
Copy link

@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.

@IzaGz
Copy link
Author

IzaGz commented Apr 18, 2018

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

@nskondratev
Copy link

nskondratev commented Apr 18, 2018

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

@dappinsight
Copy link

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

@telegrambotdeveloper
Copy link

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?

@baitun
Copy link

baitun commented Sep 29, 2018

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

@IldarMurzenkov
Copy link

IldarMurzenkov commented Dec 7, 2018

@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'?

@likeavenus
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests