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

telegraf-postgres-session

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegraf-postgres-session

A middleware session for telegraf

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

PostgreSQL session middleware for Telegraf

Installation

npm i telegraf-postgres-session

Setup

Create table in your database

CREATE TABLE postgress_sessions(id varchar PRIMARY KEY, session varchar);

Example

import { Telegraf } from 'telegraf';
import PostgresSession from 'telegraf-postgres-session';

const bot = new Telegraf(process.env.BOT_TOKEN) // Your Bot token here

bot.use((new PostgresSession({
	connectionString: process.env.DATABASE_URL,
		ssl: {
			rejectUnauthorized: false
		}
})).middleware());

bot.on('message', ctx => {
    ctx.session.counter = ctx.session.counter ? ctx.session.counter : 0
    ctx.session.counter++
    ctx.reply(ctx.session.counter)
});

bot.launch();

Example with Typescript

import { Context, Telegraf } from 'telegraf';
import PostgresSession from 'telegraf-postgres-session';

interface SessionContext extends Context {
 session: any;
};

const bot: Telegraf<SessionContext> = new Telegraf(process.env.BOT_TOKEN as string);// Your Bot token here

bot.use((new PostgresSession({
	connectionString: process.env.DATABASE_URL,
		ssl: {
			rejectUnauthorized: false
		}
})).middleware());

bot.on('message', ctx => {
    ctx.session.counter = ctx.session.counter ? ctx.session.counter : 0
    ctx.session.counter++
    ctx.reply(ctx.session.counter)
});

bot.launch();

The database connection configuration is described in The PostgreSQL API.

Keywords

FAQs

Package last updated on 15 May 2022

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