I do not see a way to combine it with a Slash command in the exact way as you described, since you can either execute a slash command or upload a code snippet, but not do both actions together.
Note that code snippets are plain text filed uploaded to Slack.
However, if you are open to a changing the order of the actions a bit, here is how it would work:
- Let the user upload his code snippet (or multiple) by clicking on
+
- User issues slash command
/mycommand
- Your app starts and shows the user a drop down list with all his
code snippets
- User chooses his code snippet
- Your app does with the code snippet whatever you want to do
Here is how you get the drop down list:
- Use files.list with parameter
user
= user ID and types
=
snippets
to get list of files.
- Use the file list to create the dropdown list for an interactive
menu, type simple.
One caveat: Your app will only see files that are shared in channels that the app (the user that has installed the app) has access too. So it will e.g. not work in direct messaging channel.
Another important mention: To download a file from Slack with your app you can use the url_private
property in the file list. But you need to provide your access token in the header to get access. See this answer for details.
If that approach does not work for you, the only alternative I see is to redirect the user to an external web page for the snippet upload.