Skip to main content
Module

x/grammy_emoji/deps.deno.ts>lazySession

Use emoji names instead of Unicode strings. Copy-pasting emoji sucks.
Go to Latest
function lazySession
import { lazySession } from "https://deno.land/x/grammy_emoji@v1.1.2/deps.deno.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