Skip to main content
Thread interface with support for custom state. Extends Postable for shared message posting capabilities.

Constructor

Parameters

ThreadImplConfig
required

Returns

ThreadImpl

Properties

required
The adapter this entity belongs to
AsyncIterable<Message<unknown>>
required
Type: MessageAsync iterator for all messages in the thread. Messages are yielded in chronological order (oldest first). Automatically handles pagination.
Channel<TState>
required
Type: ChannelGet the Channel containing this thread
string
required
Channel/conversation ID
The visibility scope of this channel
string
required
Unique ID
boolean
required
Whether this is a direct message conversation
AsyncIterable<Message<unknown>>
required
Type: MessageIterate messages newest first (backward from most recent). Auto-paginates lazily — only fetches pages as consumed.
Message<unknown>[]
required
Type: MessageRecently fetched messages (cached)
AbortSignal
required
Aborted when the platform or application stops the active turn.Pass this to AI/model APIs so cancellation stops upstream generation, not only message delivery.
Promise<TState | null>
required
Get the current state. Returns null if no state has been set.

Methods

WORKFLOW_DESERIALIZE

Deserialize a ThreadImpl from @workflow/serde. Uses lazy adapter resolution from Chat.getSingleton(). Requires chat.registerSingleton() to have been called.

Parameters

Returns

ThreadImpl

WORKFLOW_SERIALIZE

Serialize a ThreadImpl instance for @workflow/serde. This static method is automatically called by workflow serialization.

Parameters

required

Returns

SerializedThread

createSentMessageFromMessage()

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

Parameters

required

Returns

SentMessage

fromJSON()

Reconstruct a Thread from serialized JSON data. Reconstructs a ThreadImpl from serialized data. Uses lazy resolution from Chat.getSingleton() for adapter and state.

Parameters

Serialized thread data
Adapter<unknown, unknown>
Type: Adapter
ChatSingleton

Returns

ThreadImpl

getParticipants()

Get the unique human participants in this thread. Scans all messages in the thread and returns deduplicated authors, excluding the bot itself. Useful for deciding whether to subscribe based on how many humans are participating — subscribe when it’s a 1:1 conversation, unsubscribe when others join so humans can talk without the bot replying to every message.

Returns

Author Array of unique non-bot authors

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.

Returns

Promise<boolean> Promise resolving to true if subscribed, false otherwise

markAsRead()

Send a read receipt for an inbound message. Defaults to the message being handled, so it takes no argument inside a message handler. Pass a Message or a message ID to target one explicitly; a Message must belong to this thread. Platforms may treat the receipt as a watermark and mark earlier messages read along with the target.

Parameters

string | Message<unknown>
Type: MessageMessage or message ID to acknowledge; defaults to the current message

Returns

Promise<void>

mentionUser()

Get a platform-specific mention string for a user. Use this to @-mention a user in a message.

Parameters

string
required

Returns

string

post()

Post a message to this thread. Supports text, markdown, cards, and streaming from async iterables. When posting a stream (e.g., from AI SDK), uses adapter-native streaming when available, or falls back to post + edit with throttling.

Parameters

T
required
String, PostableMessage, JSX Card, or AsyncIterable

Returns

Promise<T> A SentMessage with methods to edit, delete, or add reactions
Post a message.

Parameters

Returns

SentMessage

postEphemeral()

Post an ephemeral message visible only to a specific user. Platform Behavior:
  • Slack: Native ephemeral (session-dependent, disappears on reload)
  • Google Chat: Native private message (persists, only target user sees it)
  • Teams: Native targeted message (public preview)
  • Discord: No native support - requires fallbackToDM: true

Parameters

string | Author
required
Type: AuthorUser ID string or Author object (from message.author or event.user)

Returns

EphemeralMessage EphemeralMessage with usedFallback: true if DM was used, or null if native ephemeral not supported and fallbackToDM is false

refresh()

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

Returns

Promise<void>

reply()

Reply to a specific message in this thread, using the platform’s native reply (quote, threaded reply) rather than posting a loose message. Throws NotImplementedError on adapters without native reply support.

Parameters

string | Message<unknown>
required
Type: MessageThe message to reply to, or its id. Prefer passing the Message: it is checked against this thread, and it is carried through to SentMessage.replyTo and cached thread history. A raw id is resolved only if it matches a message this thread already holds (recentMessages or the message being handled); otherwise the reply is still sent, but replyTo is left undefined and no cross-thread check happens.

Returns

SentMessage

schedule()

Schedule a message for future delivery. Currently only supported by the Slack adapter. Other adapters will throw NotImplementedError.

Parameters

{ postAt: Date }
required
Scheduling options including the target delivery time

Returns

ScheduledMessage A ScheduledMessage with cancel() capability

setState()

Set the thread state. Merges with existing state by default. State is persisted for 30 days.

Parameters

Partial<TState>
required
{ replace: boolean }

Returns

Promise<void>

startTyping()

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

Parameters

string

Returns

Promise<void>

subscribe()

Subscribe to future messages in this thread. Once subscribed, messages in non-DM threads trigger onSubscribedMessage handlers. DM threads route to onDirectMessage first when a direct message handler is registered. The initial message that triggered subscription will NOT fire the handler.

Returns

Promise<void>

toJSON()

Serialize the thread to a plain JSON object. Use this to pass thread data to external systems like workflow engines.

Returns

SerializedThread

unsubscribe()

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

Returns

Promise<void>