-
Hi, can you explain to me how this method works? What is the Predicate in argument ? In my bot in scene i would like dynamically adding and dropping handlers for the same action. composer.on('text') for example. Is it real when scene already registered? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
A predicate is a condition function that returns a boolean. For example, the function passed to bot.drop(ctx => ctx.chat?.id === blackListedChatId) For example, this middleware will drop all updates from a blacklisted chat.
const filter = (ctx, next) => mustReadText && next();
composer.on("text", filter, ctx => {
// do stuff only when mustReadText is true
} |
Beta Was this translation helpful? Give feedback.
A predicate is a condition function that returns a boolean. For example, the function passed to
Array#filter
is a predicate.Composer.drop()
takes a predicate which tells Telegraf to drop the matching updates and not process them.For example, this middleware will drop all updates from a blacklisted chat.
Composer.drop
does not seem the right tool for this. You probably just want to conditionally process updates.