Search code examples
slackslack-api

How to access file shared with slack bot


I am writing a slack app having a bot user also. I am currently working on a workflow where if a user is sharing a file with the bot or uploading to a channel and then sharing a file with the bot I want to download that file. Till now what I have done is if a user is sharing a file then I am listening to file_share event and whenever I got the event then I am getting the file object with the event also having a field named "url_private" which helps me to download the file. But now the issue is to download the file I have request that URL along with user token or api token(Token that starts with xoxp-) but for a team that token is the token of the member who has installed the app in the workspace but for all other members I don't have the token so I am not able to download the file. So I want to know if I can get the token for all other members to download the file or my understanding is incorrect and I am not obliged to download the file that belongs to the user. Please help.


Solution

  • No, you do not need to gather access tokens from all you users.

    Once a file has been shared in a channel with your bot you can download it using the bot's token as follows:

    • Make a GET call to the URL from the url_private property
    • Provide the bot's access token as authorization in the header. The syntax is:

    Authorization: Bearer A_VALID_TOKEN

    See here for reference and additional infos.