Looking for the chatbot template? It's now here.

Overview

Pluggable state adapters for thread subscriptions, distributed locking, and caching.

State adapters handle persistent storage for thread subscriptions, distributed locks (to prevent duplicate processing), and caching. You must provide a state adapter when creating a Chat instance.

Comparison

AdapterPackagePersistenceMulti-instanceUse case
Redis@chat-adapter/state-redisYesYesProduction (recommended)
ioredis@chat-adapter/state-ioredisYesYesProduction (Cluster/Sentinel)
Memory@chat-adapter/state-memoryNoNoDevelopment and testing

What state adapters manage

Thread subscriptions

When your bot calls thread.subscribe(), the state adapter persists that subscription. On subsequent webhooks, the SDK checks subscriptions to route messages to onSubscribedMessage handlers. With Redis, subscriptions survive restarts and work across multiple instances.

Distributed locking

When a webhook arrives, the SDK acquires a lock on the thread to prevent duplicate processing. This is critical for serverless deployments where multiple instances may receive the same event.

Caching

State adapters provide key-value storage with TTL for thread state (thread.setState()), message deduplication, and other internal caching.

On this page

GitHubEdit this page on GitHub