Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@grammyjs/storage-deta

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grammyjs/storage-deta

deta.sh storage adapter for grammY

  • 2.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Deta.sh Base storage adapter for grammY

Storage adapter that can be used to store your session data on Deta.sh Base when using sessions.

Installation

Node

npm install @grammyjs/storage-deta --save

Deno

import { DetaAdapter } from "https://deno.land/x/grammy_storages/deta/src/mod.ts";

Introduction

Set up your Deta Base by creating a Deta project. Copy the Project Key to here.

You should now have:

  1. A project key for your Deta.sh project.
  2. A Telegram bot token.

Put those values into the following example code:

Usage

You can check examples folder.

Example of a message counter bot running on Deno:

import {
  Bot,
  Context,
  session,
  SessionFlavor,
} from "https://lib.deno.dev/x/grammy@1.x/mod.ts";
import { DetaAdapter } from "https://deno.land/x/grammy_storages/deta/src/mod.ts";

// Define session structure
interface SessionData {
  count: number;
}
type MyContext = Context & SessionFlavor<SessionData>;

// Create the bot and register the session middleware
const bot = new Bot<MyContext>(""); // <-- Put your Bot token here.

bot.use(session({
  initial: () => ({ count: 0 }),
  storage: new DetaAdapter<SessionData>({
    baseName: "session", // <-- Base name - your choice.
    projectKey: "", // <-- Project Key here.
  }),
}));

// Use persistant session data in update handlers
bot.on("message", async (ctx) => {
  ctx.session.count++;
  await ctx.reply(`Message count: ${ctx.session.count}`);
});

bot.catch((err) => console.error(err));
bot.start();

Keywords

FAQs

Package last updated on 29 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc