import { lazySession } from "https://deno.land/x/grammy@v1.32.0/convenience/session.ts";
This is an advanced function of grammY.
Generally speaking, lazy sessions work just like normal sessions—just they
are loaded on demand. Except for a few async
s and await
s here and there,
their usage looks 100 % identical.
Instead of directly querying the storage every time an update arrives, lazy
sessions quickly do this once you access ctx.session
. This can
significantly reduce the database traffic (especially when your bot is added
to group chats), because it skips a read and a wrote operation for all
updates that the bot does not react to.
// The options are identical
bot.use(lazySession({ storage: ... }))
bot.on('message', async ctx => {
// The session object is persisted across updates!
const session = await ctx.session
// ^
// |
// This plain property access (no function call) will trigger the database query!
})
Check out the documentation on the website to know more about how lazy sessions work in grammY.
Type Parameters
C extends Context
Parameters
optional
options: SessionOptions<S, C> = [UNSUPPORTED]Optional configuration to pass to the session middleware