I am having the weirdest error when trying to connect to the RTM API from Slack.
I am implementing a simple bot in node, and I am using socket.io to handle the web socket connection. However, it always throws the error { [Error: xhr poll error] type: 'TransportError', description: 404 }
My code looks like this:
requester.GET({target: 'https://slack.com/api/rtm.start'}, [{key: 'token', value: config.token}], function(data) {
data = JSON.parse(data)
if (data.ok) {
let socket = require('socket.io-client')(data.url)
socket.on('connect', function(){})
socket.on('event', function(data){})
socket.on('disconnect', function(){})
socket.on('connect_error', function(err) {
console.log(err)
})
} else {
console.log(data)
}
})
requester
is a file I wrote myself, handling simple HTTP calls, like GET here.
The thing is, I am using the URL returned by Slack the moment I get it, so why am I getting a code 404 ? What am I doing wrong ?
I don't think socket.io-client
does what you want... I believe it's a client to talk to a server that's using socket.io
(which Slack isn't). I believe socket.io-client
is trying to make an HTTP request to the URL. You should be specifically using a WebSocket client. Maybe try the ws library?