Middlewares and Params

Middlewares

How middleware works?

How middleware works

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

You can move middleware to different position

You can read more about Answer class here

Global middlewares

You can apply middleware for all controller, if you are uncomfortable to set it for every handler

Last updated