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:Slash Command Event
Handlers receive aSlashCommandEvent with full context:
Command Arguments
Access arguments viaevent.text:
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
Theevent.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
- Go to your Slack App settings
- Navigate to “Slash Commands”
- Click “Create New Command”
- Set Request URL to your webhook endpoint
- Add the command (e.g.,
/help)
Microsoft Teams
- Add to your app manifest:
Google Chat
Slash commands work as regular messages starting with/.
Best Practices
Use ephemeral messages for private responses
Use ephemeral messages for private responses
Error messages, help text, and user-specific data should be sent as ephemeral messages to avoid cluttering the channel.
Validate arguments early
Validate arguments early
Check for required arguments and provide clear usage instructions when they’re missing.
Provide feedback quickly
Provide feedback quickly
Slash commands should respond within 3 seconds. For long operations, acknowledge immediately and update later.
Use modals for complex inputs
Use modals for complex inputs
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