Context Middleware
This middleware is designed to be used with
node-telegram-bot-api-middleware
.
For each incoming message this middleware adds a custom context object this.ctx
that is shared between all handlers.
Useful for designing complex request processing logic involving custom handler interoperation.
Context can be used to create generic handler that:
- displays help information if there is no any specific handler for the request
- processes arbitrary user text input that is not meant for any specific handler to process. In this case it is best to also use state machines to fully control the bot's logic.
Intallation
npm i node-telegram-bot-api-middleware-context
Usage
const TelegramBot = const use = useconst createContextMiddleware = const bot = 'YOUR_TELEGRAM_BOT_TOKEN' polling: true let response = /* .use(otherMiddleware) */ /* * Handlers are called in the order of their creation: * 1. /start (specific handler) * 2. .+ (generic handler) */ bot bot