@waptik/grammy-supabase-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Depreciation notice

This project is not maintained anymore. Please consider using the official plugin: @grammyjs/storage-supabase

New Section

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 @waptik/grammy-supabase-adapter --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 string, cannot be null either
    • session as string, cannot be null as well

How to use

Here is a simple example on how it's done:

import { Bot, Context, session, SessionFlavor } from 'grammy';
import { supabaseAdapter } from '@waptik/grammy-supabase-adapter';
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>('');
bot.use(
  session({
    initial: () => ({ counter: 0 }),
    storage,
  }),
);

// Register your usual middleware, and start the bot
bot.command('stats', (ctx) => ctx.reply(`Already got ${ctx.session.counter} photos!`));
bot.on(':photo', (ctx) => ctx.session.counter++);

bot.start();

Package Sidebar

Install

npm i @waptik/grammy-supabase-adapter

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

5.38 kB

Total Files

4

Last publish

Collaborators

  • waptik