Skip to content

GramIO API Reference / @gramio/session/dist / SessionOptions

Interface: SessionOptions<Data, Key, Lazy>

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

Options types from session plugin

Type Parameters

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

Properties

PropertyTypeDescriptionDefined in
getSessionKey?(context) => MaybePromise<string>A function that allows you to specify which key will be used to identify the session in the storage Default (context) => ${context.senderId}session/index.d.ts:59
initial?(context) => MaybePromise<Data>Specify which data will exist while there has not been an record in the repository yet To type a session data, you need to specify the type as the ReturnType of the initial function. interface MySessionData { apple: number; some?: "maybe-empty"; } bot.extend( session({ key: "sessionKey", initial: (): MySessionData => ({ apple: 1 }), }) );session/index.d.ts:78
key?KeyThe key that will be added to the context Default "session"session/index.d.ts:48
lazy?LazyEnable lazy session loading. When true, session is only loaded from storage when accessed, reducing database reads for handlers that don't use sessions. Default false Example // Lazy session - only loads if accessed bot.extend(session({ lazy: true, initial: () => ({ count: 0 }) })); bot.on("message", async (ctx) => { const session = await ctx.session; // Loads here session.count++; });session/index.d.ts:96
storage?StorageThe Storage in which to store the session Documentationsession/index.d.ts:54