Python-slack-sdk: Find the channel ID if it is already created

Created on 2 May 2019  路  6Comments  路  Source: slackapi/python-slack-sdk

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
  • [x] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] 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

Most helpful comment

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.

All 6 comments

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!

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 ?

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.

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marshallino16 picture marshallino16  路  3Comments

Terrance picture Terrance  路  3Comments

Dwyte picture Dwyte  路  3Comments

tinoargentino picture tinoargentino  路  3Comments

schlegelp picture schlegelp  路  3Comments