slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
568 stars 210 forks source link

FileUploadV2 is breaking two useful features available in pervious version #1309

Closed mmarsous closed 2 months ago

mmarsous commented 2 months ago

FileUploadV2 is breaking V1 in two ways:

These two V1 features are extremely useful and their removal from V2 is stopping us from upgrading so it would be appreciated if they are addressed/fixed in V2.

Java: slack-api-client version: 1.39.0

seratch commented 2 months ago

Hi @mmarsous, thank you so much for taking the time to share this feedback.

We understand that these differences in the v2 method might not be favorable for your use case. Nonetheless, these changes were deliberately made by the server-side team due to various factors. Therefore, we don't foresee the possibility of making the amendments you are hoping for your smoothest transition. We acknowledge that this could be frustrating, and we would deeply appreciate your understanding on this matter.

Let me suggest some workarounds for your situation:

For sharing a file across multiple channels, you may want to include the file's permalink in your channel messages. Although this may slightly differ from previous notification messages, it should work mostly in the same way for your end-users. To do this, you can have additional chat.postMessage API calls after the v2 file upload method call.

As for sharing files in a DM, you can call the conversations.open API to obtain a channel ID for the DM, which begins with a "D" prefix. This "D" prefix ID can then be used in place of a user ID. If your app is not allowed to have the scope to access this endpoint, the only remaining option is to manually learn the "D" prefix ID for the DM on the Slack product UI (i.e., check message permalink or click the name header of DM UI and then copy the "D" prefix ID on the modal dialog).

While I understand this may not be the ideal solution for you, I hope it was helpful to you.

mmarsous commented 2 months ago

Thank you for your reply and providing a workaround. Regarding sharing files in a DM, I tried uploading exact same file along with a title and comments using exact same code (custom app) that successfully uploads to private and public channels with V2, and the result was as follows:

Is this the expected behavior?

My understanding from you reply was that the member DM channel id should be used instead of member id, but it seems like the channel id of the custom app that the member added is the one that actually works.

seratch commented 2 months ago

Your app's bot user can access only the DMs where your bot user is a member of. Thus, any DMs you don't have the bot user can result in "channel_not_found" as you observed. I haven't checked the first result with user_id but the error could be improved (e.g., validate the passed channel_id and if it is a user_id, throw an exception with a clear instruction). Overall, these are expected. If everything is clear now, would you mind closing this issue?

mmarsous commented 2 months ago

I apologize if I was not very clear in my earlier post. The bot user is in fact a member of the DM that I am using for testing, unless "adding the app to DM" is not the same as "bot user being a member of DM". When using V1 the bot app has no access issue for the same DM, only V2 results in "channel_not_found" error. Just to make it a bit more clear, using channel id of the bot app that is a member of DM works fine, but using channel id of the DM itself results in "channel_not_found" error.

slack-dm-issue-blured

I really appreciate it if you point me to any Slack Java SDK document that will help me with this issue in case I am not doing it correctly before I close this issue.

seratch commented 2 months ago

using channel id of the DM itself

I don't understand what you mean by this. A DM always has a single ID. In other words, a DM between user A and your app's bot user always has a single DM ID.

seratch commented 2 months ago

v1 works even when you pass user_id, thus indeed behavior with v2 could be different. but there is no specific difference on the DM requirement in v2.

mmarsous commented 2 months ago

using channel id of the DM itself

I don't understand what you mean by this. A DM always has a single ID. In other words, a DM between user A and your app's bot user always has a single DM ID.

Please see the screenshots of the channel id of the user "A" and its bot user in my earlier post. User bot has a different channel id than the user "A" that it is a member of:

slack-my-dm-id-blured

slack-bot-user-id-blured

I have to use bot user channel id ending with "59S" to be able to upload a file to user "A" with channel id ending with "R1P".

So, are you saying that with V2, I should always use the channel id of the added bot app not the user "A" channel id? If that is the case then how would I be able to get that channel id using the API calls?

seratch commented 2 months ago

Thanks you for sharing this. Indeed, the UI could be a bit puzzling, but if your app's bot user is represented by the blue icon, this is an expected behavior. Regarding proper coding here, you can simply call conversations.open API to create/retrieve a DM ID interacting with other user(s), utilizing your app's bot token. With this way, the "D" ID serves as the channel ID which your app should use for sending messages to the specified recipient(s).

mmarsous commented 2 months ago

Thank you so much. I will try that API call.