Skip to content

Instantly share code, notes, and snippets.

@illvart
Last active March 2, 2022 06:13
Show Gist options
  • Save illvart/9152147c40bf05b90008475d6ec00db0 to your computer and use it in GitHub Desktop.
Save illvart/9152147c40bf05b90008475d6ec00db0 to your computer and use it in GitHub Desktop.
Ignoring Telegraf old messages from users
module.exports = (ctx, next) => {
switch (ctx.updateType) {
case 'message':
if (new Date().getTime() / 1000 - ctx.message.date < 5 * 60) {
next();
} else {
console.log(`Ignoring messages updateType: 'message' from ${ctx.chat.id}`);
}
break;
case 'callback_query':
if (ctx.callbackQuery.message && new Date().getTime() / 1000 - ctx.callbackQuery.message.date < 5 * 60) {
next();
} else {
console.log(`Ignoring messages updateType: 'callback_query' from ${ctx.chat.id}`);
}
break;
case 'inline_query':
return next();
default:
next();
break;
}
};
const Telegraf = require('telegraf');
const checkTime = require('./checkTime');
const bot = new Telegraf(BOT_TOKEN);
bot.use(checkTime);
bot.on('message', async (ctx, next) => {
await ctx.reply('Hello');
});
bot.startPolling();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment