windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
264 stars 117 forks source link

SOCKS proxy support? #43

Closed RingoAl closed 5 years ago

RingoAl commented 6 years ago

Hello. Is there any way to use bot through SOCKS proxy? As I can see, there is only an ability to change API URL. Thanks.

dvv commented 6 years ago

Точно так. Есть возможность сделать ssh на удаленный сервер?

RingoAl commented 6 years ago

Доступ по SSH есть. Хотите предложить iptables+redsocks ?

dvv commented 6 years ago

Нет. Прокидываете удаленный api.telegram.org:443 как локальный 8443, в hosts ставите адрес api.telegram.org как 127.0.0.1 и ставите https://api.telegram.org:8443 как url в узле telegram-receiver

RingoAl commented 6 years ago

Прокидываете удаленный api.telegram.org:443 как локальный 8443 При помощи чего?

dvv commented 6 years ago

ssh -L 8443:api.telegram.org:443 remote для начала

RingoAl commented 6 years ago

Видимо имелось в виду: ssh -f -N -L 8443:api.telegram.org:443 user@proxy.domain После чего уже echo "127.0.0.1 api.telegram.org" >> /etc/hosts после чего в ноде API URL https://api.telegram.org:8443 Костыль конечно, но вроде работает. Только для этого надо комп/виртуалку, где api.telegram.org доступен. Ну и к SOCKS это не имеет отношения

dvv commented 6 years ago

) главное работает и даёт время найти другие решения.

RingoAl commented 6 years ago

Это не для меня, для коллеги. У меня через IPv6 работает без Proxy. Коллегу, видимо, через себя прокину.

dvv commented 6 years ago

А вообще telegram node основан на request, который уважает опцию proxy, но автор узла ее не выставил в настройках узла. Можно его потребить в этом направлении, лучше готовыми коммитами )

RingoAl commented 6 years ago

Ну node-red-contrib-telegrambot основан на node-telegram-bot-api, а туда socks тоже ещё полноценно не прикрутили, если следить за этим issue https://github.com/yagop/node-telegram-bot-api/issues/562

dvv commented 6 years ago

Я про более глубокую зависимость, но таки да. Так что костылик пока необходим

windkh commented 6 years ago

Nice conversation, but if you don‘t mind switch to english so that others can read tjis in future in case they have the same problem. Thanks guys.

dvv commented 6 years ago

@windkh here they try to block ordinary access to https://api.telegram.org and we discuss possible ways to work this around. One option would be to expose via the proxy option of underlying request options. The default of process.env.http_proxy would be the sane default, I believe. The current workaround is to specify custom baseUrl (https://api.telegram.org:PORT), use ssh port forwarding, and hack dns for api.telegram.org to resolve to 127.0.0.1.

windkh commented 6 years ago

What about the outcome of this discussion? Should we change something in the bot or close this issue?

RingoAl commented 6 years ago

It would be great to have proxy options in bot settings. In current solutions we have to change system setting to access api.telegram.org

windkh commented 6 years ago

hm any idea how this can be achieved? What system settings do you mean? the one from the operating system or from node-red itself?

Mihara commented 5 years ago

@windkh: I came here wondering if node-red-contrib-telegrambot supports proxy settings and upon some googling, found this explanation how to invoke node-telegram-bot-api to connect through a proxy. It would be best if such settings were available, but I'm not deep enough into the javascript and node-red ecosystem yet to just offer you a PR.

The solution described in the discussion above is suboptimal, because it involves creating an SSH tunnel that redirects a local port to api.telegram.org through an off-site SSH server, and giving node-red-contrib-telegrambot a localhost URL with the said local port...

windkh commented 5 years ago

Thanks for the input. I will integrate this if I am able to set up that kind of proxy environment at my home... if not maybe you can help me with testing it?

Mihara commented 5 years ago

You can use ssh to set up such a proxy at localhost:1080 if you have an offsite server anywhere, or even another ssh-capable machine on your local network:

ssh <host> -N -D 0.0.0.0:1080

Failing that, I could test this for you, but turnaround time will make this a pain.

windkh commented 5 years ago

Ok

windkh commented 5 years ago

Hm that pull request is not released yet. I will contact the owner...

Mihara commented 5 years ago

According to the comment (my first post here had a direct link to it) the pull request is unnecessary to get socks proxy working, that was why it was not accepted.

windkh commented 5 years ago

Then I will have a closer look ....

windkh commented 5 years ago

Hi guys I release version 5.2.1 with code that hopefully solves that issue. I could not fully test this, so please support me in testing this. Waiting for your feedback.

Mihara commented 5 years ago

Appears to be working with no issue for me, thank you!

windkh commented 5 years ago

Thank you for testing. Well, there are different kind of proxys SOCKS5 and SOCKS4. What did you check?

Mihara commented 5 years ago

The one that SSH gives you -- specifically, I keep an autossh process with a permanent proxy out to a VPS. According to the ssh manpage, it responds as both SOCKS5 and SOCKS4, so I can't tell you just which particular version of the protocol got used.

windkh commented 5 years ago

Ok thanks

sepbiy commented 5 years ago

Здравствуйте,а поддержку ipv6 нельзя сюда прикрутить как в десктопной версии телеграма?

windkh commented 5 years ago

I tried to translate it using google: Hello, and ipv6 support can not be screwed here as in the desktop version of the telegram?

@sepbiy what do you mean ?

RingoAl commented 5 years ago

IPv6 support is working fine, but in my case it tries to connect by IPv4 by default. I had to add only IPv6 address to /etc/hosts to make it works.

sepbiy commented 5 years ago

I am using a 6in4 Hurricane Electric Tunnel Broker, but it does not work telegram.

windkh commented 5 years ago

Can you provide details? Polling mode? What does the log output say?

sepbiy commented 5 years ago

msg : string[52] "EFATAL: Error: connect ETIMEDOUT 149.154.167.220:443" 18.03.2019, 19:23:00 msg : string[43] "Timeout connecting to server. Trying again."

windkh commented 5 years ago

Polling Mode?

sepbiy commented 5 years ago

Poll Interval 300

windkh commented 5 years ago

Hm ... strange

sepbiy commented 5 years ago

Resolving api.telegram.org (api.telegram.org)... 2001:67c:4e8:f004::9, 149.154.167.220 Connecting to api.telegram.org (api.telegram.org)|2001:67c:4e8:f004::9|:80... failed: Connection refused.

Resolving core.telegram.org (core.telegram.org)... 2001:67c:4e8:1029::439:31, 2001:67c:4e8:1029:1:0:439:131, 149.154.167.99 Connecting to core.telegram.org (core.telegram.org)|2001:67c:4e8:1029::439:31|:80... connected.

windkh commented 5 years ago

So the first url refused but the second succeeded...

sepbiy commented 5 years ago

"EFATAL: Error: connect ETIMEDOUT 149.154.167.99:443"

ptath commented 5 years ago

So how to enable proxy support for mortal people? =)

And there is also MTP-Proxy especially for Telegram...

windkh commented 5 years ago

@ptath ... what do you mean? Or how can I help you?

ptath commented 5 years ago

@ptath ... what do you mean? Or how can I help you?

In Soviet Russia telegram is blocked 10 months ago. So Node-RED[11700]: error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect EHOSTUNREACH 149.154.167.220 is fine. On desktop/mobile we are generally using proxy.

So if nodered machine is directly connected to Russian internet, node-red-contrib-telegrambot cannot reach telegram servers and does not works.

Any idea how to configure it to use proxy in node-red?

windkh commented 5 years ago

First you need a proxy server IP that you can use. Do you have one?

Then you should activate SOCKS5 in the configuration node of telegram. Enter the proxy IP together with your credentials and after deploying it should work.

ptath commented 5 years ago

Oops. I've just realized that I'm using node-red-contrib-chatbot, which uses node-red-contrib-telegrambot =)

There is no such option, I'll take a look on original node-red-contrib-telegrambot, thanks.

windkh commented 5 years ago

No, both projects do not make use of each other. The author of the other one started his work on a very early version of the nodes in this project. At least the author noted that he got inspired by this one. But as I said both projects are independent.

ptath commented 5 years ago

No, both projects do not make use of each other. The author of the other one started his work on a very early version of the nodes in this project. At least the author noted that he got inspired by this one. But as I said both projects are independent.

So I was confused by google searching solution for my problem =) Sorry for bothering!

windkh commented 5 years ago

... your welcome. Hope that it will work for you.

Barabba11 commented 4 years ago

Hi everybody! Thanks for kind help, I'm in Russia and the module doesn't work, but the telegram app on my phone yes, why? There should be a way to make work also the module so.. I tried to use proxy but I wasn't sucessful, I searched around, for example I've found this site: https://telegramzy.ru/proxy/ the first proxy has 443 open, but they give here a key, and in the module it asked username and password. May someone kindly explain a simple way to make it work? Thank you a lot!

windkh commented 2 years ago

Issue is fixed in version 11.2.0