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
Dev: Implemented http proxy authorization #435
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #435 +/- ##
============================================
- Coverage 13.99% 13.66% -0.33%
Complexity 355 355
============================================
Files 175 176 +1
Lines 6230 6240 +10
Branches 607 609 +2
============================================
- Hits 872 853 -19
- Misses 5251 5283 +32
+ Partials 107 104 -3
Continue to review full report at Codecov.
|
protected CloseableHttpClient createHttpClient() { | ||
CloseableHttpClient localClient = null; | ||
|
||
if (options.getCredentialsProvider() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why such order?
if(not null) {
} else (not not null) {
}
in my opinion is more difficult to understand than
if(null){
} else (not null) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for me it does not matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it was
if (not null) {}
else if (null) {}
@bvn13 получилось авторизоваться, но при попытке отправки сообщения получаю следующую ошибку Буду благодарен за любую помощь)
|
@vellrya попробуйте использовать этот прокси в браузере и в десктопном клиенте телеграма. у меня есть ощущение, что прокси не работает in english: Try to use your proxy server outside of telegram bot (i.e. browser or desktop telegram client). Seems it does not work correctly at all. |
@bvn13 можно ли как-то связаться с вами в телеграме, пожалуйста? Мой ник: @ryazantsev_val |
Please, keep discussion in English. |
What about socks5-proxy support? |
@Bogus-Coder I didn't find a glue for easiest using socks5-proxy yet. |
What about some Tor?) |
@bvn13 What if a proxy doesn't need authorisation? May one just skip setting the // botOptions.setCredentialsProvider(credsProvider);
botOptions.setHttpProxy(httpHost); |
@carlopantaleo yes, just skip it. Here is an example ApiContextInitializer.init();
// Create the TelegramBotsApi object to register your bots
TelegramBotsApi botsApi = new TelegramBotsApi();
// Set up Http proxy
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
HttpHost httpHost = new HttpHost(PROXY_HOST, PROXY_PORT);
RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(false).build();
botOptions.setRequestConfig(requestConfig);
botOptions.setHttpProxy(httpHost);
// Register your newly created AbilityBot
MyBot bot = new MyBot(BOT_TOKEN, BOT_NAME, botOptions);
botsApi.registerBot(bot); |
Maybe it's a stupid question, but I'm new to GitHub, so could you please explain, how I can add your implementation to my project? I guess, I should somehow add the dev branch to the project, but really don't know how. |
@TGhnS if you are russian, you could read my article here https://bvn13.tk/posts/java-telegram-bot-using-http-proxy otherwise, you may clone my repo https://github.com/bvn13/TelegramBots, build and install it with maven <!--TelegramAPI-->
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>3.6</version>
</dependency> or gradle:
Note to change priority of repos in gradle - local must be first:
|
botOptions.setHttpProxy(httpHost); |
and I really like to see some examples of the full main method. It might be some of my mistakes. Thx for helping, |
@dygy You didn't use my repo. Check my explanation above.
|
|
@dygy it's the same for gradle. Check if gradle use it. Place mavenLocal() on top of repolist:
|
still |
@rubenlagus should I write a wiki page for using proxy? |
@bvn13 If you write it, it would be great. You can add the changes to this pull request and I'll merge them together with the release. My idea is to merge everything today and get the version ready (today or tomorrow) |
Thank you, it works |
@rubenlagus I wrote and added wiki page, but I actually don't know if it would be linked correctly into sidebar. Could you check it? |
for those who encountered difficulties due to blocking Telegram in Russia - you can try to register your implemented bot with this proxy settings (for socks5 protocol): System.getProperties().put( "socksProxyHost", "host" ); if proxy server requires authentication add:
this method is not flexible, but in some cases it can be useful (my case). |
@jakeostis what if my bot works with other services placed in local network? I want my bot to use a proxy only for telegram servers, not for my local network or other services. |
last one gives me 1000000000000000000 errors but worked :D |
@bvn13 i absolutely agree. i have edited my comment. Hence, this solution is not flexible for everyone and implementation proxy in code will be much better |
@jakeostis @bvn13 I'm sure you don't have to set the system property to get it working. Try running your app with |
@IgnatBeresnev I'm sure it will work, but I don't need to push all the traffic of my bot application into socks5 proxy. I need to use proxy only for bot. Not for local network for instance. |
Usage example: