---
schema_version: "1"
id: 23fc8b06c118643ef86a3ed1031245c9525f1a570fcaa0ba03af03ca056794e0
title: Work with 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/apex_ref/apex_ref_slashcommand.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/apex_ref_slashcommand.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: b23749817838a6a203a1e5f8302bacf5e9e922d5b2a85f9a396952437ca1fc35
products:
  - Apex SDK for Slack (Beta)
---
# Work with Slash Commands

The following are Apex classes for working with slash commands.

## SlashCommandDispatcher Class

Defines the dispatcher for the slash command you are handling.

**Usage**

When a user interacts with your slash command, your app receives an interaction payload. Your handler processes that payload and then sends a response. See [Handle Slack Actions](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/build/actions.md).

To respond to an interaction payload, always send an acknowledgement response, follow up with a modal to confirm any action that occurs next. See [Slack API: Responding to shortcuts](https://api.slack.com/interactivity/shortcuts/using#shortcut_response).

For example, you can post a message that contains a view when a user enters a slash command. See [ChatPostMessageRequest](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/apex_ref_chat.md#chatpostmessagerequest-class)

### SlashCommandDispatcher Methods

The following are methods for `SlashCommandDispatcher`.

#### invoke(parameters, context)

Invokes the action handler.

**Signature**

```java
public Slack.ActionHandler invoke(
  Slack.SlashCommandParameters parameters,
  Slack.RequestContext context
);
```

**Parameters**

_parameters_

Type: Slack.SlashCommandParameters

The action parameters for the shortcut handler. The format is a `Map<String, Object>`.

_context_

Type: Slack.RequestContext

Describes the context in which a Slack action is invoked.

**Return Value**

Type: Slack.ActionHandler

**Usage**

To access the Slack context, use the `invoke()` method. This method is passed in by an instance of `RequestContext`. It exposes information about the source of the action in Slack, performs custom logic, and obtains the correct Slack client to respond to Slack based on the request.
Each action type receives different information in its `RequestContext`.

---

## SlashCommandParameters Class

Contains information about the slash command.

### SlashCommandParameters Constructor

`SlashCommandParameters` has the following constructor.

#### SlashCommandParameters(command, text)

Creates an instance of the `Slack.SlashCommandParameters` class with the command name and text.

**Signature**

```java
public SlashCommandParameters(String command, String text)
```

**Parameters**

_command_

Type: String

The command after the slash.

_text_

Type: String

The string after the command.

### SlashCommandParameters Methods

`SlashCommandParameters` has the following methods.

#### getCommand()

Gets the command that was typed in to trigger the request.

**Signature**

```java
public String getCommand()
```

**Return Value**

Type: String

#### getText()

Gets the string after the command, which can contain anything that the user types. This text provides extra context for the command.

**Signature**

```java
public String getText()
```

**Return Value**

Type: String
