Skip to content
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

“Failed RTM connect” error when trying to connect to Slack with RTM API #609

Closed
5 of 9 tasks
vgutierrez9 opened this issue Jan 28, 2020 · 15 comments
Closed
5 of 9 tasks
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info rtm-client Version: 1x Version: 2x

Comments

@vgutierrez9
Copy link

Description

I have a slack app that I built using the RTM API, that was working fine last time I used it (in December). Now, without any code changes since then, when I try to run it RTM fails to connect.

I stumbled across the Migrating to 2.x wiki, and I'm seeing the same error with rtm_connect when I try to run the example 1.x code as I do when I run mine. I found people having similar issues, but unlike them, I am not on a Windows machine, and I am fairly certain I am using the correct token.

I've outlined the issue in detail in a SO question here

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version: slackclient==1.3.2

python version: Python 3.8.0

OS version(s): Mac OS 10.14.6

Steps to reproduce:

Please see details, like steps taken and environment info and other context, outlined in StackOverflow question

Expected result:

What you expected to happen: RTM connects successfully

Actual result:

What actually happened: RTM connection fails

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

@Havdiak
Copy link

Havdiak commented Feb 3, 2020

same story, but on linux

@stevengill
Copy link
Member

Hmm. Question, did either of you update your apps to the new granular scopes? Granular scopes don't support RTM. That might be why you are seeing this. You can still create a classic slack app if you need to test this at https://api.slack.com/rtm#create_a_classic_slack_app.

@stevengill stevengill added the needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info label Feb 3, 2020
@Havdiak
Copy link

Havdiak commented Feb 17, 2020

So the conclusion will be that slack strongly recommends updating your applications with Update to Granular Scopes and soom all apps must use granular permissions, but they do not have RTM functionality for bot users?

What should I do if I create an application of a new type (because the old type can no longer be created) and I want the bot to write to my messages?

I tried this:
slackclient==2.5.0

import os
import slack


@slack.RTMClient.run_on(event='message')
def say_hello(**payload):
    data = payload['data']
    web_client = payload['web_client']
    rtm_client = payload['rtm_client']
    if 'Hello' in data.get('text', []):
        channel_id = data['channel']
        thread_ts = data['ts']
        user = data['user']

        web_client.chat_postMessage(
            channel=channel_id,
            text=f"Hi <@{user}>!",
            thread_ts=thread_ts
        )

slack_token = os.environ["SLACK_API_TOKEN"]
rtm_client = slack.RTMClient(token=slack_token)
rtm_client.start()

SLACK_API_TOKEN is xoxb token from slack application with granular permissions

and I get

...
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'not_allowed_token_type'}
...
    wait_time = exception.response["headers"]["Retry-After"]
TypeError: 'NoneType' object is not subscriptable

@BigOtis
Copy link

BigOtis commented Feb 18, 2020

Are there any plans to support RTM-type functionality with the new granular scopes with this Python app? Just trying to get an idea of what direction we should go. I am not sure if Classic apps will be sunset in the near future...

@stevengill
Copy link
Member

@BigOtis No plans to support RTM with granular scopes. If you are building an internal integration (not planning on distributing to App Directory), you can keep using classic slack apps and RTM without much worry. No plans to sunset classic slack apps in the near future.

@seratch
Copy link
Member

seratch commented Apr 3, 2020

What should I do if I create an application of a new type (because the old type can no longer be created) and I want the bot to write to my messages?

If you need to use RTM API for new apps, create a Slack app from https://api.slack.com/apps?new_classic_app=1

The original question here has been clearly answered at #326. Allow me to close this issue now.

@seratch seratch closed this as completed Apr 3, 2020
@seratch seratch mentioned this issue Apr 29, 2020
6 tasks
@bkievitkylar
Copy link

We are unable to use event subscription and unable to create new classic app with RTM access.

We want to run our Slack bot on a cloud server which gives us two very large reasons that the event subscription model is not practical for us. 1) You need to have both a static IP as well as a domain name to use this model. While possible, these do not facilitate dynamically generating slack bots. 2) This will require us to open a port to the outside world on machines that we would like to keep closed. If we had a guarenteed ip range that we could go-list for slack servers, that would help us be a little bit more comfortable but we're not willing to open a port globally. RTM also allowed for much more flexibility in that a single program being able to manage multiple apps which does not seem possible with the event subscription model. We would really appreciate the return of the ability to use RTM or a much lighter weight replacement than event subscription.

We have an old app that still works for RTM but we recently have had a need for a second app. I attempted to create a classic app that would retain RTM access as described above (https://api.slack.com/apps?new_classic_app=1) but in order to install the app, you need to add at least one scope and if you add a scope, you can no longer use RTM. So this path is also not available to us (or I'm missing something in the setup). Any advice for moving forward would be greatly appreciated.

@seratch
Copy link
Member

seratch commented Jun 5, 2020

@bkievitkylar
Here is the up-to-date way to create a new RTM app. I know it may be a bit confusing. I hope this comment will help you and other folks.

  • Go to https://api.slack.com/apps?new_classic_app=1 and create a classic app
  • Go to OAuth & Permissions in the left pane
  • Add bot scope in the Scopes section
    • You'll see a warning saying "This scope is deprecated. Please update scopes to use granular permissions." but don't upgrade to the newer permission model
  • Go to App Home in the left pane
  • Click Add Legacy Bot User and set its name
  • Go to Install App in the left pane
  • Run the OAuth flow with your development workspace
  • Use Bot User OAuth Access Token for your RTM app

Screen Shot 2020-06-06 at 08 04 53

@bkievitkylar
Copy link

Thank you,

That appears to have worked in creating a legacy bot.

@seratch
Copy link
Member

seratch commented Jun 8, 2020

@bkievitkylar Glad to know that!

@olarapio
Copy link

olarapio commented Jun 9, 2020

@seratch Thank you very much! It worked for me!!

@gbs278
Copy link

gbs278 commented Jun 10, 2020

Hello @seratch,

I followed your instructions in the above solution but for some reason, the RTM fails to connect. Here is a screenshot of my code and a screenshot of the error that arises when I test it. You can see that at the line that says "test_slack_bot.py::test_slackConnect False", it should instead output "True".
Any help?
Thanks!

Screen Shot 2020-06-10 at 11 20 07 AM

@seratch
Copy link
Member

seratch commented Jun 11, 2020

@gbs278 I've verified with slackclient==1.3.2 just in case but I was not able to see the same situation. Can you verify if you're using the right token for it?

Also, the second screenshot publicly exposed your bot token. I've removed the file from your comment and deleted the history but I recommend revoking the token as soon as possible.

@pattrickrice
Copy link

Add bot scope in the Scopes section
You'll see a warning saying "This scope is deprecated. Please update scopes to use granular permissions." but don't upgrade to the newer permission model

This scope is no longer accessible @seratch. Any idea how to proceed?

@seratch
Copy link
Member

seratch commented Jul 13, 2020

@pattrickrice

You can add bot permission in the select menu this way:

And then,

  • Add a bot user in App Home section
  • Install the app from Install App section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info rtm-client Version: 1x Version: 2x
Projects
None yet
Development

No branches or pull requests

9 participants