Skip to main content

Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score100%
Publisheda year ago (0.1.6)

@gramio/session

npm npm downloads JSR JSR Score

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

More info

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

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gramio/session

Import symbol

import * as session from "@gramio/session";
or

Import directly with a jsr specifier

import * as session from "jsr:@gramio/session";