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 Parameter | Default type |
|---|---|
Data | unknown |
Key extends string | undefined | "session" |
Lazy extends boolean | false |
Properties
| Property | Type | Description | Defined 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? | Key | The key that will be added to the context Default "session" | session/index.d.ts:48 |
lazy? | Lazy | Enable 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? | Storage | The Storage in which to store the session Documentation | session/index.d.ts:54 |