In this Speed Run episode, we'll show you how to build a Slack Slash command with a Pipedream workflow in less than 10 minutes.
What is a slash command?
Slash commands are pre-defined actions on Slack to trigger a query or an action. A great example is the
/remind slash command on Slack.
You can use this command to schedule a reminder for yourself right in Slack:
`/remind me in 2 hours to swap out the laundry`
A Slack bot will interpret the command, and display some feedback:
What are the benefits of using slash commands?
Slack Slash commands are great small shortcuts to perform actions or queries quickly.
They're portable too, so if you're away from your computer, just open Slack on your mobile device and still be able to trigger a slash command.
First you'll need to start a new Slack App if you haven't already. Head on over to https://api.slack.com and create a new app.
Then, on the left hand side you'll see a Slash Commands navigation link.
Open this link to start to define a new Slash Command, give it a name and some expected parameters.
Connecting the Slack Command to a Pipedream workflow
This part is actually simple. On Pipedream create a new HTTP triggered workflow, and then just copy and paste the unique URL into the Slack Slash Command definition.
That's it! Nothing else required. Slack will automatically send an HTTP request every time your slash command is triggered.
Developing the workflow
Once you have the Slash command definition saved and have installed your app in your workspace, now we can develop the workflow to actually perform actions or queries.
Configuring the HTTP response
By default, the response to Slack's Slash Command webhook request will render as the reply in Slack.
However, it needs to be fast and synchronous with that method.
Instead, if you send an 200 level response with no content, Slack will interpret this as a signal to wait on the reply.
This gives us up to 5 minutes to reply to the Slash Command query, plenty of time to perform actions like querying a database or another API.
To configure your Pipedream HTTP webhook's initial response, just click the Configure button on the trigger and select 204 No Content default response.
Your webhook will respond instantly with an empty body, giving you time to send a reply later.
Sending a reply asynchronously with
You'll notice in the body of the payload from Slack, there's a special
This URL is unique to this message, it allows an asynchronous reply to the slash command.
So after you add steps to your workflow to perform a database query, or send some API calls to another service, you'll want to send feedback to Slack with a message.
To send a message back, configure a POST request to this unique URL and define a
text property to send a simple text response back to the user that initiated this command on Slack.
Alternatively you can use
blocks to initiate a rich formatted message.