Step Scene
Scenes are an environment isolated from other updates/handlers
// info.scene.ts
import { StepScene } from 'degreet-telegram'
import { IContext } from 'degreet-telegram/src/types'
const scene: StepScene = new StepScene(
'info',
async (ctx: IContext): Promise<any> => {
try {
await ctx.answer.send('Enter your name')
return ctx.scene.next()
} catch (e: any) {
console.error(e)
}
},
async (ctx: IContext): Promise<any> => {
try {
await ctx.answer.send('Enter your age')
return ctx.scene.next()
} catch (e: any) {
console.error(e)
}
},
async (ctx: IContext): Promise<any> => {
try {
const data: string[] = ctx.scene.data
console.log(data)
console.log(ctx.scene.params) // params that you can pass on enter
await ctx.answer.send('Success')
return ctx.scene.leave()
} catch (e: any) {
console.error(e)
}
},
)
export default scene
// index.ts
bot.use(scene)
// call scene
ctx.scene.enter('info', { param1: 1 })
// info.scene.js
const { StepScene } = require('degreet-telegram')
const scene = new StepScene(
'info',
async (ctx) => {
try {
await ctx.answer.send('Enter your name')
return ctx.scene.next()
} catch (e) {
console.error(e)
}
},
async (ctx) => {
try {
await ctx.answer.send('Enter your age')
return ctx.scene.next()
} catch (e) {
console.error(e)
}
},
async (ctx) => {
try {
const data = ctx.scene.data
console.log(data)
console.log(ctx.scene.params) // params that you can pass on enter
await ctx.answer.send('Success')
return ctx.scene.leave()
} catch (e) {
console.error(e)
}
},
)
module.exports = scene
// index.js
bot.use(scene)
// call scene
ctx.scene.enter('info', { param1: 1 })
Last updated