Skip to main content
The Thread interface represents a conversation thread where users exchange messages. It provides methods for posting messages, managing subscriptions, and storing per-thread state.

Properties

id

Unique thread ID. Format: {adapter}:{channel}:{thread} Examples:
  • Slack: slack:C123ABC:1234567890.123456
  • Teams: teams:{base64(conversationId)}:{base64(serviceUrl)}
  • Google Chat: gchat:spaces/ABC123:{base64(threadName)}

channelId

Channel/conversation ID containing this thread.

adapter

The adapter this thread belongs to.

isDM

Whether this is a direct message conversation.

channel

Get the Channel containing this thread. Lazy-created and cached.

state

Get the current thread state. Returns null if no state has been set.

recentMessages

Recently fetched messages (cached). Updated by refresh().

messages

Iterate messages newest first (backward from most recent). Auto-paginates lazily.

allMessages

Iterate ALL messages in chronological order (oldest first). Automatically handles pagination.

Methods

post()

Post a message to this thread. Supports text, markdown, cards, and streaming from async iterables.
string | PostableMessage | CardJSXElement
required
Message content to post
SentMessage
A SentMessage with methods to edit, delete, or add reactions
Streaming Behavior: When posting a stream (e.g., from AI SDK), uses platform-native streaming APIs when available (Slack), or falls back to post + edit with throttling.

postEphemeral()

Post an ephemeral message visible only to a specific user.
string | Author
required
User ID string or Author object (from message.author or event.user)
AdapterPostableMessage | CardJSXElement
required
Message content (string, markdown, card, etc.). Streaming is NOT supported.
PostEphemeralOptions
required
EphemeralMessage | null
EphemeralMessage with usedFallback: true if DM was used, or null if native ephemeral not supported and fallbackToDM is false
Platform Behavior:
  • Slack: Native ephemeral (session-dependent, disappears on reload)
  • Google Chat: Native private message (persists, only target user sees it)
  • Discord: No native support - requires fallbackToDM: true
  • Teams: No native support - requires fallbackToDM: true

setState()

Set the thread state. Merges with existing state by default.
Partial<TState>
required
State object to set (will be merged with existing state unless replace: true)
object

subscribe()

Subscribe to future messages in this thread. Once subscribed, all messages in this thread will trigger onSubscribedMessage handlers.
The initial message that triggered subscription will NOT fire the handler. Only subsequent messages will.

unsubscribe()

Unsubscribe from this thread. Future messages will no longer trigger onSubscribedMessage handlers.

isSubscribed()

Check if this thread is currently subscribed.
In subscribed message handlers, this is optimized to return true immediately without a state lookup, since we already know we’re in a subscribed context.

startTyping()

Show typing indicator in the thread.
string
Optional status text (e.g., “Typing…”, “Searching documents…”) shown where supported
Some platforms support persistent typing indicators, others just send once. The optional status parameter is shown where supported.

refresh()

Refresh recentMessages from the API. Fetches the latest 50 messages and updates the cache.

mentionUser()

Get a platform-specific mention string for a user. Use this to @-mention a user in a message.
string
required
Platform-specific user ID
string
Formatted mention string (e.g., <@U123>)

createSentMessageFromMessage()

Wrap a Message object as a SentMessage with edit/delete capabilities. Used internally for reconstructing messages from serialized data.
Message
required
Message object to wrap
SentMessage
SentMessage with edit/delete/reaction methods

Type Parameters

object
default:"Record<string, unknown>"
Custom state type stored per-thread
unknown
default:"unknown"
Platform-specific raw message type

Usage Examples

Basic Message Posting

Streaming from AI

Thread State Management

Message Iteration

See Also