GramIO API Reference / @gramio/session/dist
@gramio/session/dist
Interfaces
| Interface | Description |
|---|---|
| SessionOptions | Options types from session plugin |
Type Aliases
| Type Alias | Description |
|---|---|
| Events | Telegram events that support session |
| SessionData | Helper 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 Parameter | Default type |
|---|---|
Data | unknown |
Key extends string | "session" |
Lazy extends boolean | false |
Parameters
| Parameter | Type |
|---|---|
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++;
});