Skip to main content
The Chat SDK provides a comprehensive event system for responding to messages, reactions, button clicks, slash commands, and more.

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
onNewMention is ONLY called for mentions in unsubscribed threads. Once subscribed, all messages (including @-mentions) go to onSubscribedMessage handlers.

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

Use emoji constants for cross-platform emoji support. They work consistently across Slack, Google Chat, Teams, and Discord.

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.
Handle modal form submissions and closures:

Event Flow and Deduplication

The SDK handles common concerns automatically:

Deduplication

Messages can arrive via multiple paths (e.g., Slack sends both message 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

Use waitUntil for fast webhook responses:
Without waitUntil, webhook processing blocks the response. Platforms may retry if the response takes too long.

Error Handling

Handlers are wrapped with automatic error catching:
Errors in handlers are logged but don’t crash the application. Use structured logging for debugging.