Session, Props, Custom Context

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

interface ISession {
  example?: number
}

interface ICustomContext extends IContext {
  session: ISession
  prop?: number
}

const bot: DegreetTelegram<ICustomContext> = new DegreetTelegram<ICustomContext>(token)
bot.use(new Session<ISession>().middleware())

bot.use(async (ctx: ICustomContext, next: nextMiddleware) => {
  try {
    ctx.session.example = 5 // saves until the project is reloaded or manually deleted
    ctx.props.prop = 1 // saves once
  } catch (e: any) {
    console.error(e)
  }
})

bot.command('start', console.log)

Last updated