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)
}
}
)
bot.use((ctx, next) => {
console.log('global middleware worked')
next()
})
bot.command(
'start',
(ctx, next) => {
console.log('middleware worked')
return next()
}
async (ctx) => {
try {
await ctx.answer.send('Hello!')
} catch (e) {
console.error(e)
}
}
)
Last updated