1.2.0 • Published 5 years ago

telegraf-session-mongodb-fork v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

MongoDB session middleware for Telegraf

MongoDB powered simple session middleware for Telegraf.

Installation

$ npm install telegraf-session-mongodb

Example (Simple)

const { TelegrafMongoSession } = require('telegraf-session-mongodb');
const Telegraf = require('telegraf');
const bot = new Telegraf(process.env.TOKEN);

TelegrafMongoSession.setup(bot, process.ENV.MONGODB_URI);

bot.startPolling();

Example (Advanced)

const { TelegrafMongoSession } = require('telegraf-session-mongodb');
const { MongoClient } = require('mongodb');
const Telegraf = require('telegraf');
const bot = new Telegraf(process.env.TOKEN);

let session;
bot.use((...args) => session.middleware(...args));

MongoClient.connect(process.env.MONGODB_URI, { useNewUrlParser: true }).then((client) => {
    const db = client.db();
    session = new TelegrafMongoSession(db, {
      collectionName: 'sessions',
      sessionName: 'session'
    });
    bot.startPolling();
});

API

Simple Setup

  • TelegrafMongoSession.setup(bot, mongodb_url, options)

Options

  • collectionName: name for MongoDB collection (default: sessions)
  • sessionName: context property name (default: session)