How can I create a Slack command with a file attachment

1.1k views Asked by At

I would like to create a Slack command /command do-something-with-that-file with at the same time, the user uploading the file.

So far, my command is received but there is no files in the payload. Is this possible?

I have also added files:read in the scope but no luck so far.

1

There are 1 answers

0
Jai Pandya On BEST ANSWER

A Slack command can only accept text as input. If you upload a file at the same time, it wouldn't be a part of the payload and will be ignored (although uploaded, and accessible through file browser).

Some alternatives you could try though:

  1. Use files.list method - Look for files uploaded within a few seconds of the moment when you receive the command. The method accepts ts_from and ts_to parameters for this purpose.
  2. Use file_shared event - Subscribe to this event in your app configuration. This event fires every time a file is uploaded in a channel visible to your bot. You could ask the app user to use a certain format to provide with a file upload, and look for a pattern in the event submission.
  3. Use message shortcut - Once a user uploads a file, you can ask them to use the context menu to fire a message shortcut associated with your app. This message shortcut contains a reference to the message ID, which can be used to fetch the uploaded file.