telegraf-ignore-old-messages
v1.0.3
Published
The crash-preventing middleware for Telegram bots
Downloads
4
Maintainers
Readme
telegraf-ignore-old-messages
Ignores old messages in Telegram chats.
Why? POV:
Your bot was off for an hour • Each of 1000 users sent 2 messages in that time • Bot wakes up and gets all the updates • Tries to reply to 2000 messages simultaneously • most probably crashes the server
Quick start
First, run npm i telegraf-ignore-old-messages
. Then, in your Telegraf app:
const { Telegraf } = require('telegraf')
const ignoreOldMessages = require('telegraf-ignore-old-messages')
const bot = new Telegraf(process.env.BOT_TOKEN)
const skipAfter = 5
// the message skipping interval in minutes. Defaults to 1.
bot.use(
ignoreOldMessages(skipAfter)
)
// ...
bot.launch()
ignoreOldMessages should be connected first, before all the other message-related middlewares
Caught a Bug?
- Fork this repository to your own GitHub account and then clone it to your local device
- Link the package to the global module directory:
npm link
- Within the Telegraf app you want to test your local development instance of telegraf-ignore-old-messages, just link it to the dependencies:
npm link telegraf-ignore-old-messages
. Instead of the default one from npm, Node.js will now use your clone of the middleware!