1

I have a slash slack command which sends the request to AWS API gateway. The command works but now i have a requirement to post code snippet from slack to this API gateway using slack slash command. e.g.:

/mycommand and then After clicking on '+' -->Code Snippet --> Enter script contents( echo "Hello") --> Create snippet

What i want in my server code is to get the code snippet contents like echo "Hello"

I cannot find a way to achieve this in documentation.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
SCoder
  • 919
  • 2
  • 11
  • 26

1 Answers1

1

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:

  1. Let the user upload his code snippet (or multiple) by clicking on +
  2. User issues slash command /mycommand
  3. Your app starts and shows the user a drop down list with all his code snippets
  4. User chooses his code snippet
  5. Your app does with the code snippet whatever you want to do

Here is how you get the drop down list:

  1. Use files.list with parameter user = user ID and types = snippets to get list of files.
  2. 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.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114