Shortcuts and Slash Commands
Users can interact with your app through shortcuts and slash commands. To respond when a shortcut or slash command is triggered, or when an event is dispatched:
- Write a class that extends from one of the dispatcher classes
- Register the class in the app's metadata.
A class that extends the dispatcher based on the action or event you’re handling provides dispatching logic that returns a Slack.ActionHandler
.
The Slack.ActionHandler
invoke()
method performs processing logic when the handler is invoked.
Users access shortcuts in Slack by clicking the lightning bolt or typing a slash. They’re ideal for common and repeatable actions within an app. An app can have up to 5 shortcuts, and only up to 10 actions (shortcuts and slash commands) are visible within the menu, and fewer are visible on mobile.
There are two types of shortcuts.
- Global shortcuts: Available to users from the shortcuts button in the composer or when using search.
- Message shortcuts: Available to users in the context menu of a message.
For more information, see What's the difference between message and global shortcuts?
To implement a shortcut handler for a global or message shortcut, extend the Slack.ShortcutDispatcher
class.
Write code that performs actions and generates a response when the shortcut is triggered.
To map this class as the handler for the corresponding shortcut in the app's metadata, use its callback_id
. This value must match the value that you define when you create the shortcut in your Slack app. You can find the callback ID in the Interactivity & Shortcuts page at api.slack.com/apps.
If you've already defined your shortcuts, you can also find the callback_id
in the app manifest.
Global shortcut handlers receive these properties from Slack.RequestContext
, a class that's passed into the invoke()
method.
appId
—The application's unique ID.enterpriseId
—The organization ID for Enterprise Grid. null values are accepted.userId
—The Slack user’s user_id associated with this request.teamId
—The Slack workspace ID.triggerId
—A temporary ID generated for the interaction in your app. This value can be used to open modals.
Message shortcut handlers receive these properties from Slack.RequestContext
, a class that's passed into the invoke()
method.
appId
—The application's unique ID.channelId
—The channel where the source message was located.enterpriseId
—The organization ID for Enterprise Grid. null values are accepted.Message
—The message that the user initiated the shortcut from.text
—The text of the message.ts
—The timestamp of the message.user
—The user who initiated the shortcut.userId
—The Slack user’s user_id associated with this request.teamId
—The Slack workspace ID.triggerId
—A temporary ID generated for the interaction in your app. This value can be used to open modals.
Generally, we recommend creating shortcuts instead of slash commands for key navigation and discoverability.
When a user submits a slash command, Slack sends a payload of data to your app via an HTTP POST request. The slash command can be an entry point to a simple message response or a complex workflow.
Slack comes prebuilt with a list of slash commands. See What are Slash Commands? and Getting Started with Slash Commands.
To perform actions and generate a response when a slash command is sent from the message composer box in Slack, extend the Slack.SlashCommandDispatcher
class.
Map this class as the handler for the corresponding slash command in the app's metadata. The command must specify the same value used to create the slash command in your Slack app. See Register an Action.
Slash commands receive these properties from Slack.RequestContext
, a class that's passed into the invoke()
method.
appId
—The application's unique ID.channelId
—The channel where the source message was located.enterpriseId
—The organization ID for Enterprise Grid. null values are accepted.userId
—The Slack user’s user_id associated with this request.teamId
—The Slack workspace ID.triggerId
—A temporary ID generated for the interaction in your app. This value can be used to open windows.
Users can use slash commands, global shortcuts, and message shortcuts to trigger flows. Add your action to the app's metadata.
Slash commands are global and can’t contain namespaces.
This table outlines the keys required in the app manifest to bind flows to actions.
Keys
Key | Type | Required | Description |
---|---|---|---|
action.definition | String | Yes | A reference to the expected return type of the flow API. |
action.properties.flowApiName | String | Yes | The name of the flow API. |
title | String | No | Reserved for future use. |
description | String | No | The purpose for this slash command. Not used in code. |
Trigger flows with Slack buttons by using an on-click event.
Keys
Key | Type | Required | Description |
---|---|---|---|
properties.name | String | Yes | Button Name |
properties.label | String | Yes | Button Label |
properties.events.onclick.definition | String | No | The purpose for this slash command. Not used in code. |
properties.events.onclick.definition.properties.flowAPIName | String | The name of the flow API. |
Entry points for app interactions