branch method

  1. @override
Bot<CTX> branch(
  1. MiddlewarePredicate<CTX> predicate,
  2. Middleware<CTX> trueMiddleware,
  3. 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 take
  • trueMiddleware: Middleware to run if predicate is true
  • falseMiddleware: 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;
}