Saturday, 20 April 2019

Stage.enter doesn't start the wizard

I created an application which display a survey wizard to the user. When the user launch the /start command, I call the AddProject:

const Telegraf = require('telegraf');
const bot = new Telegraf(process.env.BOT_TOKEN);
const session = require('telegraf/session');
bot.use(session());

    const main = new TelegrafInlineMenu("Welcome.");
    main.setCommand('start');
    main.simpleButton('Start Survey', 'START_SURVEY', {
    doFunc: async ctx => surveyController.AddProject(ctx, bot)
});

essentially the code above create a menu that display the label Welcome and a button to start the survey. When the user click on the button, the method AddProject is called from the surveyController:

const Composer = require('telegraf/composer')
const stepHandler = new Composer();
const Stage = require('telegraf/stage')
const WizardScene = require('telegraf/scenes/wizard')
const userController = require('../controllers/user.controller');

module.exports = {

    AddProject: async function (ctx, bot) {

    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()
        },
        (ctx) => {
            ctx.reply('Step 2')
            return ctx.wizard.next()
        },
        (ctx) => {
            ctx.reply('Done')
            return ctx.wizard.leave()
        }
    )

    const stage = new Stage([superWizard])
    bot.use(stage.middleware())
    Stage.enter('super-wizard');
    }
}

the method AddProject is firing correctly, but the wizard is not displayed, what I did wrong?



from Stage.enter doesn't start the wizard

No comments:

Post a Comment