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)
const { DegreetTelegram, Session } = require('degreet-telegram')
const bot = new DegreetTelegram(token)
bot.use(new Session().middleware())
bot.use(async (ctx, next) => {
try {
ctx.session.example = 5 // saves until the project is reloaded or manually deleted
ctx.props.prop = 1 // saves once
ctx.prop = 1 // how ctx.props.prop
} catch (e) {
console.error(e)
}
})
bot.command('start', console.log)
Last updated