---
schema_version: "1"
id: c5eea665d135101afbe145f5f25a8630e96c03df4020f3fabff6ec95c31f9025
title: Shortcuts and Slash Commands
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-slack-sdk/apex-slack-sdk/guides/build/actions_interact.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/actions_interact.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 2e8bbbce7f17d2d22fea485289c3105bbe78983bc499bca9bc1aa096983e0a65
products:
  - Apex SDK for Slack (Beta)
---
# 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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_dispatchers.md)
- Register the class in the [app's metadata](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/app-definition.md).

A class that extends the dispatcher based on the action or event you’re handling provides dispatching logic that returns a [`Slack.ActionHandler`](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_dispatchers.md#actionhandler-class).
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](https://developer.salesforce.com/media/shortcuts.png)

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?](https://api.slack.com/interactivity/shortcuts/using#shortcut_types)

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](https://api.slack.com/apps/).

![Shortcuts with callback IDs](https://developer.salesforce.com/media/callbackID.png)

**tip:** If you've already defined your shortcuts, you can also find the `callback_id` in the app manifest.

### 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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/surface.md#modal).

### 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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/components/surface.md#modal).

## 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](https://developer.salesforce.com/media/slash_command.png)

**tip:** Slack comes prebuilt with a list of slash commands. See [What are Slash Commands?](https://api.slack.com/interactivity/slash-commands#enabling-interactivity-with-slash-commands__what-are-slash-commands) and [Getting Started with Slash Commands](https://api.slack.com/interactivity/slash-commands#getting_started).

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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_dispatchers.md#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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/actions_register.md).

Slash commands receive these properties from [`Slack.RequestContext`](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/apex_ref/apex_ref_requestcontext.md), 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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/app-definition.md).

```yaml
description: App configuration for running flows in slack
commands:
  /SlashCommandName:
    action:
      definition: flow__requestHandler
      properties:
        flowApiName: slashCommandFlow
    title: Launch flow command
    description: Launches a flow in a modal from slack`
globalShortcuts:
  flow-gs:
    action:
      definition: flow__requestHandler
      properties:
        flowApiName: ScreenFlowOnSlackGS
    title: Launches flow with API Name ScreenFlowOnSlackGS
    description: Launches a flow from slack global shortcut.
messageShortcuts:
  flow-ms:
    action:
      definition: flow__requestHandler
      properties:
        flowApiName: ScreenFlowOnSlackMS
    title: Launches flow with API Name ScreenFlowOnSlackMS
    description: Launches a flow from slack message shortcut.
```

**important:** 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.    |

## Use Slack Buttons with Flows

Trigger flows with Slack buttons by using an on-click event.

```yaml
description: "Launches a flow from a button"
components:
  definition: message
  components:
    definition: "actions"
    components:
      definition: "button"
      properties:
        name: "flowButton"
        label: "Launch Flow"
        events:
          onclick:
           definition: "flow__requestHandler"
            properties:
              flowApiName: "MyFlow"
```

**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.                             |

## See Also

[Entry points for app interactions](https://api.slack.com/interactivity/entry-points)
