telegraf-session-postgresql

1.0.3 • Public • Published

PostgreSQL session middleware for Telegraf

User session stored in PostgreSQL for the framework Telegraf.

Installation

$ npm install telegraf-session-postgresql

Setup

you should create a table named sessions in your database.

CREATE TABLE telegraf_session(id varchar, session varchar);

Example

const Telegraf              = require('telegraf')
    , PostgreSQLSession     = require('telegraf-session-postgresql')
    , bot = new Telegraf(process.env.BOT_TOKEN)
 
const session = new PostgreSQLSession({
    user: 'postgres',
    host: 'localhost',
    database: 'name',
    password: '1234',
    port: 5432,
})
 
bot.use(session)
 
bot.on('message', ctx => {
    ctx.session.counter = ctx.session.counter ? ctx.session.counter : 0
    ctx.session.counter++
    ctx.reply(ctx.session.counter)
})
 
bot.startPolling()

API

The database connection configuration is described in The PostgreSQL API -- PostgreSQL.

Contacts

my telegram: @JSusDev, channel https://t.me/Jsusdevs

if you have any questions and suggestions please email me in telegram if you find bugs I will be very grateful if you also let me know

telegraf-session-postgresql by JSus

Package Sidebar

Install

npm i telegraf-session-postgresql

Weekly Downloads

3

Version

1.0.3

License

ISC

Unpacked Size

4.46 kB

Total Files

4

Last publish

Collaborators

  • jsusdev