Skip to content

GramIO API Reference / @gramio/session/dist

@gramio/session/dist

Interfaces

InterfaceDescription
SessionOptionsOptions types from session plugin

Type Aliases

Type AliasDescription
EventsTelegram events that support session
SessionDataHelper type: If Lazy is true, wraps Data in Promise, otherwise returns Data as-is

Functions

session()

session<Data, Key, Lazy>(options?): Plugin<{ }, DeriveDefinitions & object>

Defined in: session/index.d.ts:137

Session plugin

Type Parameters

Type ParameterDefault type
Dataunknown
Key extends string"session"
Lazy extends booleanfalse

Parameters

ParameterType
options?SessionOptions<Data, Key, Lazy>

Returns

Plugin<{ }, DeriveDefinitions & object>

Examples

ts
import { Bot } from "gramio";
import { session } from "@gramio/session";

const bot = new Bot(process.env.token!)
    .extend(
        session({
            key: "sessionKey",
            initial: () => ({ apple: 1 }),
        })
    )
    .on("message", (context) => {
        context.send(`🍏 apple count is ${++context.sessionKey.apple}`);
    })
    .onStart(console.log);

bot.start();
ts
// Lazy sessions - only load when accessed
const bot = new Bot(process.env.token!)
    .extend(
        session({
            lazy: true,
            initial: () => ({ count: 0 }),
        })
    )
    .on("message", async (context) => {
        const session = await context.session;
        session.count++;
    });