Skip to main content

Basic Usage

This guide covers the core concepts and common usage patterns for Chat SDK.

Core Concepts

Chat Instance

The Chat class is the main entry point. It coordinates adapters, handles webhooks, and dispatches events to your handlers.
Configuration options:
  • 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

A Thread represents a conversation. It’s the primary interface for posting messages, managing subscriptions, and accessing thread state.
Key properties:
  • id - Unique thread ID (format: adapter:channel:thread)
  • channelId - Channel/conversation ID
  • isDM - Whether this is a direct message
  • adapter - The adapter instance for this thread
  • state - Custom thread state (typed if you provide a type parameter)

Message

Messages contain text, formatting, metadata, and attachments:
Message properties:
  • text - Plain text content
  • formatted - mdast AST representation
  • raw - Platform-specific raw message
  • author - Author information (userId, userName, fullName, isBot, isMe)
  • metadata - Timestamp, edited status
  • attachments - File/image attachments
  • isMention - Whether the bot was @mentioned

Event Handlers

Mentions

Handle @mentions of your bot in unsubscribed threads:
onNewMention only fires for mentions in unsubscribed threads. After calling thread.subscribe(), all subsequent messages (including mentions) go to onSubscribedMessage handlers.

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:
Emoji usage:

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:
State TTL: Thread state persists for 30 days by default.

Iterating Messages

Recent Messages (Newest First)

All Messages (Oldest First)

Manual Pagination

Ephemeral Messages

Send messages visible only to a specific user:
Ephemeral messages on Slack are session-dependent and disappear on reload. On Google Chat they persist. Discord and Teams require fallbackToDM: true.

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