Event Handler Types
The SDK distinguishes between different types of events based on subscription state and message patterns:Message Events
onNewMention
Triggered when the bot is @-mentioned in an unsubscribed thread
onSubscribedMessage
Triggered for all messages in subscribed threads
onNewMessage
Triggered when a message matches a regex pattern
Interactive Events
onReaction
Triggered when a user adds/removes a reaction emoji
onAction
Triggered when a user clicks a button in a card
onSlashCommand
Triggered when a user invokes a slash command
onModalSubmit
Triggered when a user submits a modal form
Mention Handlers
Basic Mention Handling
Subscribing to Threads
The typical pattern is to subscribe when first mentioned:The initial message that triggered subscription does NOT fire
onSubscribedMessage. Only subsequent messages trigger subscribed handlers.Pattern-Based Message Handlers
Match messages using regular expressions:Reaction Handlers
React to emoji reactions on messages:Reaction Event Structure
Action Handlers (Button Clicks)
Handle button clicks from interactive cards:Action Event Structure
Slash Command Handlers
Handle slash commands like/help or /status:
Slash Command Event Structure
Slash commands are invoked at the channel level, so you get a
Channel object instead of a Thread.Modal Handlers
Handle modal form submissions and closures:Modal Response Types
Event Flow and Deduplication
The SDK handles common concerns automatically:Deduplication
Messages can arrive via multiple paths (e.g., Slack sends bothmessage and app_mention events):
Default deduplication TTL is 5 minutes. Adjust with
dedupeTtlMs in ChatConfig.Bot Message Filtering
Messages from the bot itself are automatically skipped:Thread Locking
Only one instance processes a thread at a time:Background Processing
UsewaitUntil for fast webhook responses: