Amazebot / bbot-rocketchat-boilerplate

bRocket is a bBot boilerplate for building Rocket.Chat bots
MIT License
13 stars 8 forks source link

Unable to connect behind proxy #6

Open exhuma opened 5 years ago

exhuma commented 5 years ago

I'm trying to run a new bot, but I get a connection timeout:

┌─[10:17:37] malbert@BBS-nexus ‹master*›
└─~/work/sandbox/cossbot› http_proxy=http://ict-proxy.dt.ept.lu:8080 https_proxy=http://ict-proxy.dt.ept.lu:8080 no_proxy=localhost,ipsw.dt.ept.lu npm start

> cossbot@1.0.0 start /home/users/malbert/work/sandbox/cossbot
> node index.js

info:   [core] cossbot loading  . . . . . ~(0_0)~
debug:  [adapter] loading adapter by name: rocketchat
debug:  [adapter] failed to load module, will try from path
debug:  [adapter] loading adapter by path: ./adapters/rocketchat
info:   [core] cossbot starting . . . . . ┌(O_O)┘ bzzzt whirr
info:   [server] listening, see public stats: http://127.0.0.1:3000/public
debug:  [adapter] starting message adapter: rocketchat-message-adapter
info:   [rocketchat] responds to name: cossbot
info:   [connect] Connecting
info:   [connect] Timeout (20000)
error:  [adapter] startup failed: Asteroid connection timeout
error:  [core] failed to start

Running a cURL command with the same proxy settings works:

┌─[10:20:52] malbert@BBS-nexus ‹master*›
└─~/work/sandbox/cossbot› http_proxy=http://ict-proxy.dt.ept.lu:8080 https_proxy=http://ict-proxy.dt.ept.lu:8080 no_proxy=localhost,ipsw.dt.ept.lu,.dtt.ptech.lu curl -I https://*******
HTTP/1.1 200 Connection established
Proxy-Agent: Fortinet-Proxy/1.0

HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Thu, 25 Jul 2019 08:20:56 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Instance-ID: ********
Access-Control-Allow-Origin: *
set-cookie: connect.sid=*****
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
badkaktus commented 5 years ago

same

exhuma commented 5 years ago

FWIW, I just tested it on a machine with direct Internet access and it works without any modification of the existing code. So the bot implementation itself seems fine.

exhuma commented 5 years ago

Digging through the code, it looks like bots use DDP to connect to the RocketChat server. I've never heard of DDP until today so I was doing some research:

Still not very lucky until now 🙁

timkinnane commented 5 years ago

@exhuma Thanks for sharing your issue and persisting with the problem. I'm unable to provide detailed support with Rocket.Chat connection issues, because there's just too much inconsistency between versions. I tried for a long time but it became infeasible as there's ongoing issues of stability with Rocket.Chat's socket connection handlers.

As you may have found, DDP is just a standard for communicating over websocket, like REST for web APIs. The Rocket.Chat SDK is used by the bot to connect over websocket - in their docks this layer is referred to as the "Realtime API", but the dependency is a DDP handler called Asteroid, which is the part that seems to have lost compatibility with Rocket.Chat in recent versions.

I am working on a totally rearchitected version of bBot that has removed this dependency and I've built my own connection layer instead of relying on the Rocket.Chat SDK. Unfortunately my time is very limited right now so progress is slow.

Depending on your needs and level of coding, you could have a look at the new connection util I made (Rocket Control), which has enough for building a simple bot without the full features of bBot. Though I haven't confirmed it's stability with recent versions.

If you need more context to continue working on it, please go ahead and open new issues, I'll do my best to provide some helpful direction.