I discovered a weird bug on the wizard middleware, let's take as example the wizard in the doc:
const Telegraf = require('telegraf')
const Composer = require('telegraf/composer')
const session = require('telegraf/session')
const Stage = require('telegraf/stage')
const Markup = require('telegraf/markup')
const WizardScene = require('telegraf/scenes/wizard')
const stepHandler = new Composer()
stepHandler.action('next', (ctx) => {
ctx.reply('Step 2. Via inline button')
return ctx.wizard.next()
})
stepHandler.command('next', (ctx) => {
ctx.reply('Step 2. Via command')
return ctx.wizard.next()
})
stepHandler.use((ctx) => ctx.replyWithMarkdown('Press `Next` button or type /next'))
const superWizard = new WizardScene('super-wizard',
(ctx) => {
ctx.reply('Step 1', Markup.inlineKeyboard([
Markup.urlButton('鉂わ笍', 'http://telegraf.js.org'),
Markup.callbackButton('鉃★笍 Next', 'next')
]).extra())
return ctx.wizard.next()
},
stepHandler,
(ctx) => {
ctx.reply('Step 3')
return ctx.wizard.next()
},
(ctx) => {
ctx.reply('Step 4')
return ctx.wizard.next()
},
(ctx) => {
ctx.reply('Done')
return ctx.scene.leave()
}
)
const bot = new Telegraf(process.env.BOT_TOKEN)
const stage = new Stage([superWizard], { default: 'super-wizard' })
bot.use(session())
bot.use(stage.middleware())
bot.launch()
then the wizard start and reach the stepHandler, so the ctx.reply('Step 2. Via command'), the wizard doesn't go automatically on the next step but wait for an input. This behavior is wrong imho 'cause seems that the wizard is stucked.
When the wizard reach the stepHandler of Composer should show automatically the Step 3 reply, otherwise I don't see any point to call ctx.wizard.next() and wait for an user input to enable it.
Could you please fix this?
This is intended behavior cause wizard is a simple Finite State Machine and must wait for input before any state change. I recommend don't use WizardScene at all and implement all logic on basic scenes.
@dotcypress so what's the purpose of return ctx.wizard.next() inside the stepHandler if the wizard always wait for an input? This problem happen only in the stepHandler not in the wizard steps, when I call ctx.wizard.next() this must be called: ctx.reply('Step 3'), I don't need to type some input to display Step3 'cause the stepHandler has already managed my input
UPDATE:
Seems that in the stepHandler I need to use:
ctx.wizard.next();
return ctx.wizard.steps[ctx.wizard.cursor](ctx);
really don't understand why ctx.wizard.next() alone not works
I have also observed this only in the stepHandler. The behaviour should not deviate between a "wizard" step and a stepHandler IMHO.
Most helpful comment
@dotcypress so what's the purpose of
return ctx.wizard.next()inside thestepHandlerif the wizard always wait for an input? This problem happen only in thestepHandlernot in the wizard steps, when I callctx.wizard.next()this must be called:ctx.reply('Step 3'), I don't need to type some input to displayStep3'cause thestepHandlerhas already managed my inputUPDATE:
Seems that in the stepHandler I need to use:
really don't understand why
ctx.wizard.next()alone not works