Skip to content

Find the channel ID if it is already created #405

Closed

Description

@gothraven

Description

This is more like a question than an issue.
Sometimes there is no way for a bot to create a new channel by NAME because it is already created, and no way to get the Channel without fetching all channels list and iterating through most of them to get the channel you want.

What type of issue is this?

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

Requirements

  • 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

It is not really a bug

Reproducible in:

slackclient version: 1.2.1
python version: 3.7.3
OS version(s): Any

Steps to reproduce:

api_key = 'key...'
client = SlackClient(api_key)
result = client.api_call("channels.create", name='test')
if not result['ok'] and result['error'] == 'name_taken': 
 ... some way to find the channel ID

Expected result:

the behavior seems fine, though it would've been better if it would like something like this

{'ok': False, 'error': 'name_taken', channel: {...}, 'headers': {...}}

Actual result:

{'ok': False, 'error': 'name_taken', 'headers': {...}}

Attachments:

None

Activity

  1. self-assigned this
    on May 3, 2019
  2. lavabyrd commented on May 3, 2019

    @lavabyrd

    Hey @gothraven ,

    Thanks for this. Completely get where you're coming from. However this is more to do with the information our API returns for the *.create endpoints. You may be able to do similar yourself by calling the create api call and if you get that error, you run *.list and iterate over the results until you find a matching channel name. It would depend on pagination too however.

    The one thing to be aware of, the channels.* and groups.* endpoints are being retired in place of conversations.*. This endpoint allows you to check both private and public channels provided you have access to them.

    I will mention to our product managers that you'd like this to happen but I'm afraid at the moment, I think this would be out of scope for the SDK itself.

    Thanks for your feedback and information however!

  3. gothraven commented on May 3, 2019

    @gothraven
    Author

    It makes no sense to iterate over more than 7K channels to get the right one, fetching all channels, I think there can be a better way to filter the channels.list based on name or something ?

  4. amilbourne commented on Nov 6, 2019

    @amilbourne

    I have hit this issue as well - the API is definitely deficient in this respect. As @gothraven points out there should be a way to search for channel(s) by name.

  5. acurt1 commented on Apr 29, 2020

    @acurt1

    Same issue here. Is there any update or still need to iterate?

  6. JohnPaton commented on Jun 25, 2020

    @JohnPaton

    Also just ran into this. Making loads of api calls and iterating over thousands of channels just to find the ID that matches the name I have seems... inefficient.

  7. zachsirotto commented on Sep 23, 2020

    @zachsirotto
  8. kalrish commented on Oct 8, 2021

    @kalrish

    This limitation is unfortunate and unfortunately still there.

    use https://api.slack.com/methods/search.messages

    search.messages is not just a workaround, but also won't work with a bot token — it requires a user token. You could create a dummy user for this purpose, but there's a dark corner in hell reserved for whomever dares.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions