Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/grammy/mod.ts>lazySession

The Telegram Bot Framework.
Very Popular
Go to Latest
function lazySession
import { lazySession } from "https://deno.land/x/grammy@v1.10.1/mod.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 asyncs and awaits 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.

Parameters

optional
options: SessionOptions<S> = [UNSUPPORTED]

Optional configuration to pass to the session middleware