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

telegraf-userbased-ratelimit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegraf-userbased-ratelimit

Rate-limiting middleware for Telegraf based on number of users

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Build Status NPM Version js-standard-style

Telegraf Rate Limit

Rate-limiting middleware for Telegraf (Telegram bot framework).

This repository is forked from telegraf/telegraf-ratelimit in order to add limitation based on number of users who are using bot.

Installation

$ npm install telegraf-userbased-ratelimit

Example

const Telegraf = require('telegraf')
const rateLimit = require('telegraf-userbased-ratelimit')

// Set limit to 1 message per 3 seconds
const limitConfig = {
  window: 3000,
  limit: 1,
  onLimitExceeded: (ctx, next) => ctx.reply('Rate limit exceeded')
}
const telegraf = new Telegraf(process.env.BOT_TOKEN)
telegraf.use(rateLimit(limitConfig))
telegraf.on('text', (ctx) => ctx.reply('Hello!'))
telegraf.startPolling()

API

Options

  • window: how long to keep records of requests in memory in ms (default: 1 second)
  • limit: max number of messages during window (default: 1)
  • keyGenerator: key generator function (context -> any)
  • onLimitExceeded: rate-limit middleware

Default implementation of keyGenerator:

function keyGenerator(ctx) {
  return ctx.from.id
}

Keywords

FAQs

Package last updated on 19 Jan 2018

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