Skip to main content

Slash Command Handling

Slash commands let users invoke your bot’s functionality by typing /command in the message composer. The SDK provides a unified API for handling slash commands across platforms.

Registering Commands

Handle specific commands:
Handle multiple commands with one handler:
Catch-all handler for any command:

Slash Command Event

Handlers receive a SlashCommandEvent with full context:

Command Arguments

Access arguments via event.text:
Parse complex arguments:

Posting Responses

Public Response

Visible to everyone in the channel:

Ephemeral Response

Visible only to the command invoker:

Rich Card Response

Opening Modals

Trigger a form dialog from a slash command:

User Information

Access information about the command invoker:

Channel Context

The event.channel provides access to the channel where the command was invoked:

Complete Example

Task management commands:

Platform Setup

You need to register slash commands in each platform:

Slack

  1. Go to your Slack App settings
  2. Navigate to “Slash Commands”
  3. Click “Create New Command”
  4. Set Request URL to your webhook endpoint
  5. Add the command (e.g., /help)

Microsoft Teams

  1. Add to your app manifest:

Google Chat

Slash commands work as regular messages starting with /.

Best Practices

Error messages, help text, and user-specific data should be sent as ephemeral messages to avoid cluttering the channel.
Check for required arguments and provide clear usage instructions when they’re missing.
Slash commands should respond within 3 seconds. For long operations, acknowledge immediately and update later.
When you need multiple fields or structured data, open a modal instead of parsing complex command arguments.

Next Steps

Modals

Create forms triggered by slash commands

Actions

Add buttons to command responses