When the bot gets update, it completes all middlewares, and only then completes a handler. For example, using middlewares, you can auth user and pass some params to the handler
Creating middleware
Let's create logger.middleware.ts file. It will be the middleware that will log received update. We will then apply this middleware
export function LoggerMiddleware(
update: IUpdate, // received update
answer: Answer, // Answer (you can send a message)
params: any, // Params (you can pass params to the handler)
next: NextFunction, // next function (it can be next middleware or handler)
fail: NextFunction, // fail function (you need to call it if you don't want to call handler)
) {
params.someParam = 1; // set some param that we want to get in handler
console.log(update); // log received update
next(); // call handler
}