@grammyjs/storage-supabase
TypeScript icon, indicating that this package has built-in type declarations

2.4.2 • Public • Published

Supabase database storage adapter for grammY

Database storage adapter that can be used to store your session data in Supabase database when using sessions.

Installation

npm install @grammyjs/storage-supabase --save

Instructions

To get started, you first need to

  • Have both @supabase/supabase-js and grammy installed

  • Have a defined table for sessions in supabase will the following informations:

    • id as a primary key of type varchar, cannot be null
    • session as text. Make it nullable.

    You could also add created_at and updated_at to keep track of changes.

How to use

You can check examples folder for full blown usage, or see a simple use case below:

import { Bot, Context, session, SessionFlavor } from 'grammy';
import { supabaseAdapter } from '@grammyjs/storage-supabase';
import { createClient } from '@supabase/supabase-js';

interface SessionData {
  counter: number;
}
type MyContext = Context & SessionFlavor<SessionData>;

const URL = 'http://localhost:3000';
const KEY = 'some.fake.key';

// supabase instance
const supabase = createClient(URL, KEY);

//create storage
const storage = supabaseAdapter({
  supabase,
  table: 'session', // the defined table name you want to use to store your session
});

// Create bot and register session middleware
const bot = new Bot<MyContext>(''); // <-- put your bot token here
bot.use(
  session({
    initial: () => ({ counter: 0 }),
    storage,
  }),
);

// Display total stats of images uploaded so far
bot.command('stats', (ctx) => ctx.reply
(`Already got ${ctx.session.counter} images!`));

// Collect statistics of photos uploaded
bot.on(':photo', (ctx) => ctx.session.counter++);

bot.start();

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.4.297latest

Version History

VersionDownloads (Last 7 Days)Published
2.4.297
2.4.10
2.4.03
2.3.20
2.3.10
2.3.00
2.2.00
2.1.40
2.1.30
2.1.10
2.1.00
2.0.20
2.0.00
1.0.20
1.0.11
1.0.00
0.1.00

Package Sidebar

Install

npm i @grammyjs/storage-supabase

Weekly Downloads

101

Version

2.4.2

License

MIT

Unpacked Size

11 kB

Total Files

13

Last publish

Collaborators

  • knorpelsenf
  • waptik
  • satont