slackapi / bolt-python

A framework to build Slack apps using Python
https://slack.dev/bolt-python/
MIT License
1.02k stars 236 forks source link

Get Channel_id through channel_name besides using conversations.list #1093

Open Tang20031010 opened 3 weeks ago

Tang20031010 commented 3 weeks ago

(Describe your issue and goal here)

Reproducible in:

The slack_bolt version

slack-bolt==1.18.1 slack_sdk==3.27.2

Python runtime version

Python 3.12.3

OS info

ProductName: macOS ProductVersion: 14.4.1

Steps to reproduce:

I am trying to get channel id by channel name. I would like to let the user input a channel's name and use that to get the channel's id since I need the channel id to do conversations.join. I have found one thread in https://github.com/slackapi/bolt-js/issues/1725 and tried the suggestion by using conversations.list to filter and then use the conversations.info. However, there are too many channels in the organization. I have tried pagination but still failed to retrieve all channels through conversations.list. I think there are more than 50000 channels and the return from conversations.list is not stable. Since that post is in 2023, I am wondering if we have additional solutions to this situation. The worst case I am thinking is letting user input the channel id.

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

filmaj commented 3 weeks ago

I would like to let the user input a channel's name and use that to get the channel's id since I need the channel id to do conversations.join.

Could you use the Block Kit Conversation Select Menu? It will render a drop down menu of conversations (channels, public or private, even DMs and MPDMs) that is contextual to the user (meaning: the user has access to them). Then, you can listen to block_actions payloads on this element to get channel / conversation ID.

Tang20031010 commented 3 weeks ago

Thank you for your quick response! I looked into it; however, this does not seem quite fit to my situation as what I want is to let the user only interact with the UI I implemented instead of going to slack to do the operation.

filmaj commented 3 weeks ago

I see. Yes, it's a common request and unfortunately we have no good answer. If you have access to an admin token, you could use the admin.conversations.search API as it accepts a query parameter for the channel name. The other is to paginate through conversations.list, as you pointed out.

Tang20031010 commented 3 weeks ago

Thank you! I probably need to go with letting the user input channel_id.