Work with Slash Commands

The following are Apex classes for working with slash commands.

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.

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.

For example, you can post a message that contains a view when a user enters a slash command. See ChatPostMessageRequest

The following are methods for SlashCommandDispatcher.

Invokes the action handler.

Signature

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.


Contains information about the slash command.

SlashCommandParameters has the following constructor.

Creates an instance of the Slack.SlashCommandParameters class with the command name and text.

Signature

Parameters

command

Type: String

The command after the slash.

text

Type: String

The string after the command.

SlashCommandParameters has the following methods.

Gets the command that was typed in to trigger the request.

Signature

Return Value

Type: String

Gets the string after the command, which can contain anything that the user types. This text provides extra context for the command.

Signature

Return Value

Type: String