Middlewares

import { IContext, nextMiddleware } from 'degreet-telegram/src/types'

bot.use((ctx: IContext, next: nextMiddleware): void => {
  console.log('global middleware worked')
  next()
})

bot.command(
  'start',
  (ctx: IContext, next: nextMiddleware): void => {
    console.log('middleware worked')
    next()
  }
  async (ctx: IContext): Promise<void> => {
    try {
      await ctx.answer.send('Hello!')
    } catch (e: any) {
      console.error(e)
    }
  }
)

Last updated