Skip to content

Explanation of composer.drop() #1673

Answered by MKRhere
Ludenser asked this question in Q&A
Discussion options

You must be logged in to vote

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.

bot.drop(ctx => ctx.chat?.id === blackListedChatId)

For example, this middleware will drop all updates from a blacklisted chat.

dynamically adding and dropping handlers

Composer.drop does not seem the right tool for this. You probably just want to conditionally process updates.

const filter = (ctx, next) => mustReadText && next();

composer.on("text", filter, ctx => {
  // do stuff only when mustReadText is true
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Ludenser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants