npm.io
1.0.2 • Published 4 years ago

telegraf-session-sequelize

Licence
ISC
Version
1.0.2
Deps
1
Size
11 kB
Vulns
0
Weekly
0

Sequelize session middleware for Telegraf

Sequelize powered simple session middleware for Telegraf 4.0 with TypeScript support.

Installation

$ npm install telegraf-session-sequelize
$ yarn add telegraf-session-sequelize

Example

import { Telegraf } from 'telegraf'
import { Sequelize } from 'sequelize'
import { session } from 'telegraf-session-sequelize'

const bot = new Telegraf(process.env.BOT_TOKEN)

const init = async () => {
    const sequelize = await new Sequelize('dbName', 'username', 'pass', {
	    host: 'host',
	    dialect: 'postgres'
    })
	
    bot.use(session(sequelize, { collectionName: 'Sessions' }))
    bot.launch()
}

init()

API

Options
  • collectionName: name for MongoDB collection (default: Sessions)
  • sessionName: context property name (default: session)
  • sessionKeyFn: function that generates the session key from the context (default implementation, legacy deprecated function)

Keywords