branch method
Bot<CTX>
branch(
- MiddlewarePredicate<
CTX> predicate, - Middleware<
CTX> trueMiddleware, - Middleware<
CTX> falseMiddleware
override
Adds middleware that handles a specific branch of execution.
The branch middleware allows you to conditionally execute different middleware based on a predicate.
Parameters:
predicate: Function that determines which branch to taketrueMiddleware: Middleware to run if predicate is truefalseMiddleware: Middleware to run if predicate is false
Returns this composer for method chaining.
Example:
composer.branch(
(ctx) => ctx.isPrivateChat,
(ctx, next) => ctx.reply('Private message handler'),
(ctx, next) => ctx.reply('Group message handler'),
);
Implementation
@override
Bot<CTX> branch(
MiddlewarePredicate<CTX> predicate,
Middleware<CTX> trueMiddleware,
Middleware<CTX> falseMiddleware,
) {
super.branch(predicate, trueMiddleware, falseMiddleware);
return this;
}