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

files_upload_v2 Doesn't work with user ID's or channel names #1326

Closed
nils-soderman opened this issue Feb 9, 2023 · 10 comments
Closed

files_upload_v2 Doesn't work with user ID's or channel names #1326

nils-soderman opened this issue Feb 9, 2023 · 10 comments
Labels
auto-triage-stale discussion M-T: An issue where more input is needed to reach a decision web-client

Comments

@nils-soderman
Copy link

nils-soderman commented Feb 9, 2023

With the older function files_upload you used to be able to use channel names such as "#my_channel" for the channels argument.
Or use user ID's as the channels argument to send the file to a user as a direct message.

The new files_upload_v2 doesn't work with either channel names or user ID's. And seems to only accept channel ID's for the channel argument now.
So unless I'm missing something there's currently no way to use files_upload_v2 to send a direct message to a user? it must be posted to a channel.

I'd also argue that using channel names in the code is easier to read than channel ID's. Since if I skim through some code I can quickly & easily see what channel a script is logging to. If all I see is an ID I'll have no way of knowing which channel that ID belongs to.

The Slack SDK version

3.19.5

Python runtime version

3.9.7

Steps to reproduce:

import slack_sdk
Client = slack_sdk.WebClient(TOKEN)
Client.files_upload(content = "Hello World", channels = "#my_channel", filename="test.txt")  # Works!
Client.files_upload_v2(content = "Hello World v2", channel = "#my_channel", filename="test.txt")  # Fails!

Expected result:

Two files would be shared with the channel "my_channel".

Actual result:

files_upload will send the content as a file, however files_upload_v2 will respond with:

The server responded with: {'ok': False, 'error': 'invalid_channel', 'channel': '#my_channel'}
@WilliamBergamin
Copy link
Contributor

Hi @nils-soderman thanks for writing in!

This is correct, I was able to reproduce this behavior on my local 🥇

Under the hood files_upload_v2 uses the files.completUploadExternal endpoint, this endpoint only accepts the channel_id not the channel_name this is where the error comes from.

Ill label this issue as a feature request, this would apply to all implementations of this feature (js, java, python).

@seratch I tried using conversations.info to fetch the channel_id from the channel name but this also did not work, not sure if there is work around we can implement

@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented discussion M-T: An issue where more input is needed to reach a decision web-client and removed untriaged labels Feb 9, 2023
@WilliamBergamin
Copy link
Contributor

From an old thread I found, it is possible to use conversation.list to go though all the channels and find the channel_id corresponding to the channel_name but this is very slow.

It is also possible to use chat.postMessage in order to send a message to the channel using the channel_name and receive the channel_id in the response, if the request fails the channel does not exist.

Both these solutions feel like hacky work arounds

@srajiang
Copy link
Member

srajiang commented Feb 9, 2023

@nils-soderman @WilliamBergamin channel name was evaluated to be supported at the API endpoint level in the improvements that our teams released to the functions.completeUploadExternal endpoint and channel name support was intentionally omitted. My best understanding for why is because channel names can easily be renamed (with the underlying ID staying the same), channel ID is the more robust way to identify the channel from an app development perspective. Developers relying on channel names as stable leads to more "breaky" apps, and we don't want to set devs up to have unpleasant surprises.

I'd also argue that using channel names in the code is easier to read than channel ID's. Since if I skim through some code I can quickly & easily see what channel a script is logging to. If all I see is an ID I'll have no way of knowing which channel that ID belongs to.

Fair point to bring up about quality of life from a dev perspective, and valuable feedback at that, @nils-soderman. Given that it's highly unlikely channel name support will be added to the api endpoint, and we can certainly take that feedback to see if it makes sense to add support for it at the SDK level, but as @WilliamBergamin, there may not be a robust way to do this. Would love to hear from others using the v2 upload functionality to see if this is a common desire and pain point.

Maybe for this, you can have a mapping in your code between channel IDs and names in your project, to get the advantage in readability and code maintenance quality of life when developing, but also use IDs instead. Channel Ids are ultimately the most reliable and stable indicator of a channel that exists, and allow you to get information on that channel (via this endpoint https://api.slack.com/methods/conversations.info).

In terms of DM'ing users and supplying user ID in the channel parameter, if that was a feature it was an unintentional one - I'm really sorry that the improvement in v2 has led to what seems like an unpleasant surprise for you in terms of loss of functionality. My workaround recommendation would be to start a DM with the user in question, and supply the channel ID you get from the successful response (should look like D047T8J9PJM) in the channels param.

@srajiang srajiang removed the bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented label Feb 9, 2023
@srajiang
Copy link
Member

srajiang commented Feb 9, 2023

I'm removing the bug label for now, since the behavior that has been confirmed as intended as part of the design of the function upload versison 2 API endpoints.

@nils-soderman
Copy link
Author

Thank you both for the quick responses!

Creating a mapping between channel names & ID's makes sense and would indeed solve the issue of not knowing which ID's belong to which channel + as you @srajiang mentioned it'd avoid potential errors in the future due to a channel being renamed. I wasn't aware of the conversations_open function, but makes sense I'd have to use that one in order to send a DM.

I'll buy the argument for not wanting to support channel names, so unless you would like to keep this issue open to see if anyone else has any opinions, I'd be down close the issue.

If anything, since channel names/user ID's was supported with the previous files_upload function, it might be worth checking if the user has provided a channel name or User ID and raise a more descriptive error, so future users knows this is intentional.
For example:

if channel_to_share.startswith(("#", "U")):
    raise ValueError("Channel names/user ID's are no longer supported for the `channel` argument, please provide the channel ID instead!")

Cheers,
Nils

@calumah
Copy link

calumah commented Feb 13, 2023

I don't totally agree, I think it's best to leave the choice.

If I want robustness I use a mapping and channel ids, but if I want to do a quick test or stay clear I use channel names.

The best option in my opinion is to let the developer choose and also it allows to stay consistent with the rest of the functions.

@github-actions
Copy link

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

@github-actions github-actions bot closed this as completed Apr 3, 2023
@crypdick
Copy link

crypdick commented May 4, 2023

+1. Having to figure out the channel IDs is user unfriendly!

@Kunalroy241
Copy link

Slack API files upload
def slackResponse = slackSend channel: '$userId', message: 'Hey', sendAsText: true
slackUploadFile filePath: "wsu.zip", channel: slackResponse.channelId
the above code is still not working can anyone help me with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale discussion M-T: An issue where more input is needed to reach a decision web-client
Projects
None yet
Development

No branches or pull requests

6 participants