SessionOptions
Options for session middleware.
Properties
type
type?: "single";
initial
initial?: () => S;
Recommended to use.
A function that produces an initial value for ctx
. 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.
prefix
prefix?: string;
An optional prefix to prepend to the session key after it was generated.
This makes it easier to store session data under a namespace. You can technically achieve the same functionality by returning an already prefixed key from get
. This option is merely more convenient, as it does not require you to think about session key generation.
getSessionKey
getSessionKey?: (ctx: Omit<C, "session">) => 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 ctx
.
storage
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.