Skip to main content


The Telegram Bot Framework.
Very Popular
Go to Latest
interface SessionOptions
import { type SessionOptions } from "";

Options for session middleware.


type: "single"
initial: () => S

Recommended to use.

A function that produces an initial value for ctx.session. This function will be called every time the storage solution returns undefined for a given session key. Make sure to create a new value every time, such that different context objects do that accidentally share the same session data.

getSessionKey: (ctx: Context) => MaybePromise<string | undefined>

This option lets you generate your own session keys per context object. The session key determines how to map the different session objects to your chats and users. Check out the documentation on the website about how to use session middleware to know how session keys are used.

The default implementation will store sessions per chat, as determined by

storage: StorageAdapter<S>

A storage adapter to your storage solution. Provides read, write, and delete access to the session middleware.

Consider using a known storage adapter instead of rolling your own implementation of this.

The default implementation will store session in memory. The data will be lost whenever your bot restarts.