Last active
March 2, 2022 06:13
-
-
Save illvart/9152147c40bf05b90008475d6ec00db0 to your computer and use it in GitHub Desktop.
Ignoring Telegraf old messages from users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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