Skip to main content
Deno 2 is finally here 🎉️
Learn more
Very Popular
Latest
interface SessionFlavor
import { type SessionFlavor } from "https://deno.land/x/grammy@v1.30.1/convenience/session.ts";

A session flavor is a context flavor that holds session data under ctx.session.

Session middleware will load the session data of a specific chat from your storage solution, and make it available to you on the context object. Check out the documentation on session middleware to know more, and read the section about sessions on the website.

Methods

getter
session(): S

Session data on the context object.

WARNING: You have to make sure that your session data is not undefined by providing an initial value to the session middleware, or by making sure that ctx.session is assigned if it is empty! The type system does not include | undefined because this is really annoying to work with.

Accessing ctx.session by reading or writing will throw if getSessionKey(ctx) === undefined for the respective context object ctx.

setter
session(session: S | null | undefined)