Basic Usage
This guide covers the core concepts and common usage patterns for Chat SDK.Core Concepts
Chat Instance
TheChat class is the main entry point. It coordinates adapters, handles webhooks, and dispatches events to your handlers.
userName- Bot username (required)adapters- Map of adapter instances (required)state- State adapter for persistence (required)logger- Logger instance or log level ("info","debug","silent")streamingUpdateIntervalMs- Update interval for fallback streaming (default: 500ms)fallbackStreamingPlaceholderText- Initial placeholder for streaming (default:"...")dedupeTtlMs- Message deduplication TTL (default: 300000ms / 5 minutes)
Thread
AThread represents a conversation. It’s the primary interface for posting messages, managing subscriptions, and accessing thread state.
id- Unique thread ID (format:adapter:channel:thread)channelId- Channel/conversation IDisDM- Whether this is a direct messageadapter- The adapter instance for this threadstate- Custom thread state (typed if you provide a type parameter)
Message
Messages contain text, formatting, metadata, and attachments:text- Plain text contentformatted- mdast AST representationraw- Platform-specific raw messageauthor- Author information (userId, userName, fullName, isBot, isMe)metadata- Timestamp, edited statusattachments- File/image attachmentsisMention- Whether the bot was @mentioned
Event Handlers
Mentions
Handle @mentions of your bot in unsubscribed threads:Subscribed Messages
Handle all messages in threads you’ve subscribed to:The initial message that triggered
thread.subscribe() does not fire onSubscribedMessage. Only subsequent messages do.Pattern Matching
Match messages against regex patterns:Reactions
Handle emoji reactions:Button Clicks (Actions)
Handle button clicks in interactive cards:Slash Commands
Handle slash commands:Posting Messages
Simple Text
Markdown
With Emoji
With Attachments
Interactive Cards (JSX)
Streaming AI Responses
Streaming uses native Slack streaming APIs when available. On other platforms, it falls back to post + periodic edits.
Editing and Deleting Messages
Thread State
Store custom data per thread:Iterating Messages
Recent Messages (Newest First)
All Messages (Oldest First)
Manual Pagination
Ephemeral Messages
Send messages visible only to a specific user:Typing Indicators
Some platforms show persistent typing indicators, others send a single ping. The optional status parameter is only supported on select platforms.
Direct Messages
Open a DM conversation:Custom Thread State Types
Define custom state for type safety:Error Handling
Logging
Configure logging level:Next Steps
Event Handlers
Deep dive into all event types
AI Streaming
Stream LLM responses
Interactive Cards
Build rich UI with JSX
Adapters
Platform-specific configuration