History
The History API reads and persists message history in three scopes, keyed by user, thread, or channel. The user scope is stored in your state adapter. Thread history comes from platform APIs, with an optional cache in the state adapter. Channel history reads from the platform through adapter methods.
| Scope | Access | Keyed by | Typical use |
|---|---|---|---|
| User | bot.history.user | Cross-platform user key | LLM context, audit trail, GDPR |
| Thread | bot.history.thread | Thread ID | Backfill for adapters without server-side history |
| Channel | bot.history.channel | Channel ID | Channel-level summaries, moderation |
bot.history is the unified successor to bot.transcripts. The user scope is a drop-in replacement. See Migrating from bot.transcripts below.
Setup
All three scopes are available once you configure a state adapter. The user scope also needs an identity resolver:
history.user requires an identity resolver. Set history.user.identity, or keep the deprecated top-level identity field during migration. Omitting both when history.user (or legacy transcripts) is set throws at construction.
Set history.user.maxPerUser: false to disable count-based eviction. Omit retention as well to keep entries without a TTL. The state adapter must use durable storage to retain history across restarts. The legacy transcripts.maxPerUser field also accepts false.
Thread and channel scopes are always available on bot.history. Use history.thread to tune the thread cache, which is used by adapters with persistThreadHistory: true such as WhatsApp, and Telegram unless you turn the option off:
User history
bot.history.user stores a per-user transcript keyed by a stable cross-platform identifier. The same user can talk to your bot on Slack and Discord and see the same accumulated history.
Building LLM context
The most common pattern is to append the user's message, build a prompt from recent history, post the reply, and then append the reply.
A few details about this pattern:
- The SDK sets
msg.userKeyfrom youridentityresolver before your handler runs. If the resolver returnednull,msg.userKeystaysundefinedandappenddoes nothing. - Bot replies are stored only when you append them. The SDK does not capture
thread.post()output, so you decide what gets persisted. That matters for retries and intermediate streaming chunks. listreturns entries oldest first, the order a model expects. Uselimitto keep prompts bounded.
Filtering entries
Deleting a user's history
For GDPR data-subject requests or "forget me" flows:
This deletes every entry stored under the key. Single-entry and time-range deletes are not supported, because the underlying appendToList primitive can't do them safely under concurrent writes.
Thread history
bot.history.thread reads thread messages through adapter.fetchMessages and keeps a per-thread cache for adapters that lack server-side message history APIs and set persistThreadHistory: true, such as Telegram and WhatsApp. For those adapters, list() falls back to the cache when the adapter returns an empty first page. For every other adapter, the platform response is authoritative.
Telegram sets persistThreadHistory: true by default. If you pass persistThreadHistory: false to createTelegramAdapter, the SDK doesn't write to the cache or fall back to it, so list() returns only the messages the current process has seen. On serverless platforms, that list is empty after a cold start.
Thread history is populated automatically when adapter.persistThreadHistory is true. You don't need to append manually. For adapters with server-side history (Slack, Teams, Discord), prefer thread.messages or adapter.fetchMessages.
Channel history
bot.history.channel reads top-level channel messages and lists threads. It delegates to the adapter, and its methods throw when the adapter doesn't implement the underlying capability, such as listThreads on WhatsApp.
Identity resolution
The identity resolver can live on history.user.identity (preferred) or the deprecated top-level ChatConfig.identity field. It runs once per inbound message:
Return null when you can't resolve a key. The SDK won't fall back to a platform-specific ID, because that would split a user's history across platforms without any warning.
If the resolver throws, the SDK logs a warning and dispatches the message without a userKey. Handlers still run; only the persistence is skipped.
Migrating from bot.transcripts
bot.transcripts is deprecated in favor of bot.history.user. The API is identical, so you rename the config key and the call sites:
bot.transcripts continues to work and will not be removed in the current major version.
You can migrate one field at a time: when both history.user and the legacy transcripts block are set, they merge, with history.user winning field by field. Settings like retention and maxPerUser left on transcripts keep applying until you move them.
Storage
The user scope and the thread cache use StateAdapter.appendToList and getList. Channel scope reads from platform APIs and is not persisted in state by default.
| Scope | Storage / source | Key or API |
|---|---|---|
| User | State adapter | transcripts:user:{userKey} |
| Thread cache | State adapter (when persistThreadHistory: true) | msg-history:{threadId} |
| Thread / channel reads | Platform adapter | adapter.fetchMessages, fetchChannelMessages, listThreads |
On channel-scoped platforms such as WhatsApp and Telegram, inbound messages may also be appended under msg-history:{channelId}. bot.history.channel.listMessages reads from that cache only when the adapter doesn't implement fetchChannelMessages.
Appends to user and thread cache keys are atomic, so concurrent inbound messages on the same key don't race.
Reference
See History API reference for full type signatures, configuration options, and entry shapes.
Read more
Handling Events
Register handlers for mentions, messages, reactions, member joins, and platform-specific events.
History
API reference for bot.history, covering the user, thread, and channel scopes.
State Adapters
State adapters store thread subscriptions, distributed locks, and cached data for your bot.
Message Subject
Fetch the parent resource that a message is about.