ddgd ddgd - 1 year ago 105
Ruby Question

Receive files from slack with slack bot

I need a slack bot that's able to receive and save files send from slack chatrooms.

The problem is: slack doesn't send file contents, but an array of links pointing to the file. Most of them, including download link are private and cannot be accessed via bot. It does send one public link, but that link points at the file preview, which does not have the file itself (here's an example).

So the question is: how can I access uploaded files via bot?

Answer Source

You can access private URLs from your bot by providing an access token in the http header when you are doing you CURL request. This can be an access token received with OAuth or a global "test token".

The format is:

Authorization: Bearer A_VALID_TOKEN

Replace A_VALID_TOKEN with your slack access token.

I just tested it with a simple PHP script to retrieve a file by its "url_private" and it works nicely.

Source: Slack API documententation / file object / Authentication

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download