E
E
Evgeny Bykov2018-10-14 22:49:40
Java
Evgeny Bykov, 2018-10-14 22:49:40

Bot for telegram in JAVA, how to bypass blocking in code?

Good day! I wanted to write a telegram bot, but my ISP is desperately blocking it, so my program cannot connect to their servers. I am using TelegramLongPollingBot . How can I connect to the proxy through the code itself and work from there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2018-10-15
@Taraflex

Don't use LongPolling - not a solution for production, only webhooks.
In order not to spend on a domain, you can use a self-signed certificate for ip.
Certificate generation example
Host the bot on foreign servers.
For local development, use https://localtunnel.github.io/www/
The thing is terribly unstable, but of similar solutions, this is the only service that provides named subdomains for free.
To solve problems with crashes a little, run the program in a loop
Variant for windows

FOR /L %N IN () DO @lt --port <локальный порт> --subdomain <поддомен>

O
Oleg A, 2018-10-15
@OLEG4120

Use the latest version of the library, install the Tor browser and build for now like this:

TelegramBotsApi telegramBotsApi = new TelegramBotsApi();

// Set up Http proxy
DefaultBotOptions botOptions = ApiContext
        .getInstance(DefaultBotOptions.class);
botOptions.setProxyHost("127.0.0.1");
botOptions.setProxyPort(9150);
// Select proxy type: [HTTP|SOCKS4|SOCKS5] (default: NO_PROXY)
botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS5);

try {
    telegramBotsApi.registerBot(new Bot(BotConfig.BOT_TOKEN, BotConfig.BOT_USERNAME, botOptions));
} catch (TelegramApiRequestException e) {

}

public class Bot extends AbilityBot {
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question