user7804781
user7804781

Reputation: 316

"Failed RTM connect" error when trying to connect to Slack with RTM API

I'm using the following Python code from Slack's "Migrating to 2.x" github docs

from slackclient import SlackClient

slack_token = os.environ["SLACK_API_TOKEN"]
client = SlackClient(slack_token)

def say_hello(data):
    if 'Hello' in data['text']:
        channel_id = data['channel']
        thread_ts = data['ts']
        user = data['user']

        client.api_call('chat.postMessage',
            channel=channel_id,
            text="Hi <@{}>!".format(user),
            thread_ts=thread_ts
        )

if client.rtm_connect():
    while client.server.connected is True:
        for data in client.rtm_read():
            if "type" in data and data["type"] == "message":
                say_hello(data)
else:
    print "Connection Failed"

For the SLACK_API_TOKEN, I am using the Bot User OAuth Access Token for my app, found here: enter image description here

The error I am getting is the following:

Failed RTM connect
Traceback (most recent call last):
  File "/Users/.../slackbot/slackbot_env/lib/python3.8/site-packages/slackclient/client.py", line 140, in rtm_connect
    self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
  File "/Users/.../slackbot/slackbot_env/lib/python3.8/site-packages/slackclient/server.py", line 168, in rtm_connect
    raise SlackLoginError(reply=reply)
slackclient.server.SlackLoginError
Connection Failed

Why am I getting this error?!?!?!

Other context:

Why am I focusing on debugging the example for 1.x? My code was previously working using rtm_connect / 1.x using the same commands as the example code, and without any code changes it has stopped working. My code and the example code yield the same errors, so I'm using the sample code to make debugging easier. I'd like to fix this before starting the process of migrating to 2.x, so I can start with working code before embarking on a long series of changes that can introduce their own errors.

Upvotes: 2

Views: 3234

Answers (2)

vreyespue
vreyespue

Reputation: 781

I do not think this issue is related to the Bot User OAuth Access Token, in my view you are using the right one (xoxb-). However, this issue might be related to the Slack App. Note that RTM isn't supported for the new Slack App granular scopes (see python client issue #584 and node client issue #921). If you want to use RTM, you should create rather a classic slack app with the OAuth Scope bot.

Upvotes: 3

Willy Chen
Willy Chen

Reputation: 31

I not sure if this is the reason, but I ran into the same issues before. The answer I found on the Slack Github is that new xoxob-* doesn't support RTM.

Please reference this web: - https://github.com/slackapi/python-slackclient/issues/326.

So I use my OAuth Access Token instead of Bot User OAuth Access Token.

Upvotes: 1

Related Questions