Created a bot, started using the telegram api project is going with the help of maven, he threw a dependency

<dependency> <groupId>org.telegram</groupId> <artifactId>telegrambots</artifactId> <version>3.5</version> </dependency> 

Then I partially implemented the onUpdate, getBotUsername and getBotToken methods.

 @Override public void onUpdateReceived(Update update) { if(update.hasMessage() && update.getMessage().hasText()){ SendMessage message = new SendMessage().setChatId(update.getMessage().getChatId()); Message msg = update.getMessage(); String text = ""; message.setText(text); } else if(update.hasCallbackQuery()){ } } @Override public String getBotUsername() { return "name"; } @Override public String getBotToken() { return "token"; } 

in the main method

 ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = new TelegramBotsApi(); try { telegramBotsApi.registerBot(new ConnectToTelegramm()); } catch (TelegramApiRequestException e) { e.printStackTrace(); } 

and then error pops up

 фев 17, 2019 8:20:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Connection reset фев 17, 2019 8:20:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://api.telegram.org:443 фев 17, 2019 8:20:35 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Connection reset фев 17, 2019 8:20:35 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://api.telegram.org:443 фев 17, 2019 8:20:35 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Connection reset фев 17, 2019 8:20:35 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://api.telegram.org:443 org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error executing setWebook method at org.telegram.telegrambots.bots.TelegramLongPollingBot.clearWebhook(TelegramLongPollingBot.java:55) at org.telegram.telegrambots.TelegramBotsApi.registerBot(TelegramBotsApi.java:120) at Bots.main(Bots.java:15) Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) at org.telegram.telegrambots.bots.TelegramLongPollingBot.clearWebhook(TelegramLongPollingBot.java:43) ... 2 more 

Tell me what am I doing wrong?

  • Forget that Telegram is blocked on the territory of the Russian Federation. - Sergey Gornostaev
  • how can you get around this?) - i_burykin February
  • Use VPN or run the program not in the territory of the Russian Federation. - Sergey Gornostaev

2 answers 2

Your bot does not have access to api.telegram.org. This is most likely due to the blocking of access to telegrams on the territory of the Russian Federation. To bypass the blocking, you can use http proxy at the client level: Using Http Proxy In case your bot extends TelegramLongPollingBot , add a constructor with DefaultBotOptions

  public ConnectToTelegramm(DefaultBotOptions options){ super(options); } 

After that, in your main method, create a bot with the night points:

  ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = new TelegramBotsApi(); try { // Авторизация бота в прокси, после создания будет использоваться автоматически Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(PROXY_USER, PROXY_PASSWORD.toCharArray()); } }); // Создаем экземпляр настроек DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class); // Устанавливаем настройки прокси botOptions.setProxyHost(PROXY_HOST); botOptions.setProxyPort(PROXY_PORT); // Выбираем тип прокси: [HTTP|SOCKS4|SOCKS5] (по умолчанию: NO_PROXY) botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS5); telegramBotsApi.registerBot(new ConnectToTelegramm(botOptions)); } catch (TelegramApiRequestException e) { e.printStackTrace(); } 

You can also use socks proxy. His support has been added to this PR: https://github.com/rubenlagus/TelegramBots/pull/451

    Faced with this problem. Telegram is blocked in the Russian Federation: /
    Use VPN or Proxy.