Run a workflow from a Slack slash command
Start a Stylo Workflow when someone types a slash command in Slack, and post the result back to them.
This guide shows you how to start a Workflow from a Slack slash command, such as /blocked-items store 42, and reply to the person who ran it. Do this when your team should be able to run a Workflow from Slack without opening Stylo.
Prerequisites: You're a Stylo admin, and you can create and install apps in your Slack workspace.
How it works
When someone runs the command, Slack sends it to Stylo. Stylo checks that the request came from your Slack app, starts the Workflow, and answers Slack straight away with a short acknowledgement. The Workflow runs in the background. A Reply to Slack Command step then posts the result back to the person who ran the command.
Slack gives each command a reply link that accepts at most 5 replies within 30 minutes. A Workflow that takes longer than 30 minutes can't reply to the command.
Set up the command
Create a Slack app
Go to api.slack.com/apps, click Create New App, choose From scratch, name it, and pick your workspace. On the app's Basic Information page, find App Credentials and copy the Signing Secret.
Expected result: You have the Signing Secret copied.
Add the Signing Secret to Stylo
In Stylo, go to Settings → Integrations and open the Slack card. Click Connect (or reconnect an existing Slack connection) and paste the Signing Secret. The Bot Token is only needed if the same connection also sends messages with the Send Slack Message block.
Expected result: Slack shows as connected.
Build and publish the Workflow
Create a Workflow in the Workflow Builder and choose the Slack Slash Command trigger. Select the Slack connection that holds your Signing Secret. Save the Workflow, then copy the Request URL from the trigger's settings.
Add the steps the command should run. Use <Slack Slash Command.text> to read what the person typed after the command. End with a Reply to Slack Command step, then publish the Workflow.
Expected result: The Workflow is published and you have its Request URL.
Add the slash command in Slack
Back in your Slack app settings, open Slash Commands and click Create New Command. Enter the command name, paste the Stylo Request URL, and add a short description and usage hint. Turn on Escape channels, users, and links sent to your app if your Workflow needs the IDs of users or channels mentioned in the command.
Expected result: The command is listed on the Slash Commands page.
Install the app
Open Install App in your Slack app settings and click Install to Workspace, or Reinstall if Slack prompts you after adding the command.
Expected result: The app is installed and the command appears when you type / in Slack.
Run the command
Type the command in any channel and press Enter.
Expected result: You see the Workflow's acknowledgement, then its reply. The run appears in the Workflow's execution history.
Choose who sees the reply
The trigger's Acknowledgement and the default reply are visible only to the person who ran the command. To post the reply for everyone in the channel, set the Reply to Slack Command step's Visibility to Everyone in the channel. Leave Acknowledgement blank to skip the acknowledgement.
Troubleshooting
Slack shows an error when you run the command. Stylo rejects commands it can't verify. Check that the Workflow is published, that its trigger uses the Slack connection holding this app's Signing Secret, and that the command's Request URL matches the one in the trigger. If you regenerated the Signing Secret in Slack, paste the new one into Stylo.
The command is acknowledged but no reply arrives. Open the Workflow's execution history and check the Reply to Slack Command step. A reply fails if the Workflow ran longer than 30 minutes or replied more than 5 times.
Slack never reaches Stylo. Turn off Socket Mode in your Slack app settings. With Socket Mode on, Slack stops sending commands to the Request URL.
Slash commands can't be run inside message threads. This is a Slack limitation.