Module

x/grammy/mod.ts

The Telegram Bot Framework.
Go to Latest
interface SessionOptions
import { type SessionOptions } from "https://deno.land/x/grammy@v1.10.1/mod.ts";

Options for session middleware.

Properties

optional
type: "single"
optional
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.

optional
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 ctx.chat?.id.

optional
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.