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:

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.

Shortcuts 

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.

Shortcuts enable users to invoke actions

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.

Shortcuts with callback IDs

If you’ve already defined your shortcuts, you can also find the callback_id in the app manifest.

Tip

Global Shortcuts 

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 Shortcuts 

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.

Slash Commands 

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.

Slash commands trigger an action like viewing a record

Slack comes prebuilt with a list of slash commands. See What are Slash Commands? and Getting Started with Slash Commands.

Tip

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.

Use Slash Commands and Shortcuts with Flows 

Users can use slash commands, global shortcuts, and message shortcuts to trigger flows. Add your action to the app’s metadata.

1description: App configuration for running flows in slack
2commands:
3  /SlashCommandName:
4    action:
5      definition: flow__requestHandler
6      properties:
7        flowApiName: slashCommandFlow
8    title: Launch flow command
9    description: Launches a flow in a modal from slack`
10globalShortcuts:
11  flow-gs:
12    action:
13      definition: flow__requestHandler
14      properties:
15        flowApiName: ScreenFlowOnSlackGS
16    title: Launches flow with API Name ScreenFlowOnSlackGS
17    description: Launches a flow from slack global shortcut.
18messageShortcuts:
19  flow-ms:
20    action:
21      definition: flow__requestHandler
22      properties:
23        flowApiName: ScreenFlowOnSlackMS
24    title: Launches flow with API Name ScreenFlowOnSlackMS
25    description: Launches a flow from slack message shortcut.

Slash commands are global and can’t contain namespaces.

Important

This table outlines the keys required in the app manifest to bind flows to actions.

Keys

KeyTypeRequiredDescription
action.definitionStringYesA reference to the expected return type of the flow API.
action.properties.flowApiNameStringYesThe name of the flow API.
titleStringNoReserved for future use.
descriptionStringNoThe purpose for this slash command. Not used in code.

Use Slack Buttons with Flows 

Trigger flows with Slack buttons by using an on-click event.

1description: "Launches a flow from a button"
2components:
3  definition: message
4  components:
5    definition: "actions"
6    components:
7      definition: "button"
8      properties:
9        name: "flowButton"
10        label: "Launch Flow"
11        events:
12          onclick:
13           definition: "flow__requestHandler"
14            properties:
15              flowApiName: "MyFlow"

Keys

KeyTypeRequiredDescription
properties.nameStringYesButton Name
properties.labelStringYesButton Label
properties.events.onclick.definitionStringNoThe purpose for this slash command. Not used in code.
properties.events.onclick.definition.properties.flowAPINameStringThe name of the flow API.

See Also 

Entry points for app interactions

Beta Feature

This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.