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 })

Last updated