Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
gramiojs/sessionWorks with
•JSR Score100%•This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers




Publisheda year ago (0.1.6)
@gramio/session
Session plugin for GramIO.
!!!Currently not optimized and WIP!!!
Usage
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();
You can use this plugin with any storage (Read more)
Redis example
import { Bot } from "gramio"; import { session } from "@gramio/session"; import { redisStorage } from "@gramio/storage-redis"; const bot = new Bot(process.env.token!) .extend( session({ key: "sessionKey", initial: () => ({ apple: 1 }), storage: redisStorage(), }) ) .on("message", (context) => { context.send(`🍏 apple count is ${++context.sessionKey.apple}`); }) .onStart(console.log); bot.start();
TypeScript
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 }), }) );
Built and signed on
GitHub Actions
Add Package
deno add jsr:@gramio/session
Import symbol
import * as session from "@gramio/session";
Import directly with a jsr specifier
import * as session from "jsr:@gramio/session";