I am creating a telegram bot using telegraf using wizards. I would like to have several wizards in my bot. How can I enter to another scene? I am using the below code and I am getting error Cannot read property 'enter' of undefined
.
const Stage = require("telegraf/stage");
const WizardScene = require("telegraf/scenes/wizard");
const wiz1 = new WizardScene('task1',
ctx => {...},
ctx => {...}
);
const wiz2 = new WizardScene('task2',
ctx => {...},
ctx => {...}
);
const wiz3 = new WizardScene('task3',
ctx => {...},
ctx => {...}
);
const stage =new Stage([wiz1,wiz2,wiz3],{default: 'task1'})
bot.hears('anAction', (ctx) => {Stage.enter('wiz2')}); // this does not work
2
Answers
This is a late response, but it may help someone.
You need to register the middleware of the stages after
const stage = new Stage ...
and beforebot.hears...
And also you can enter the scene with their ids not the name of the variable. So instead of
Stage.enter('wiz2')
useStage.enter('task2')
to enter wizard2.And also make sure that
bot.use(stage.middleware())
should be registred afterbot.use(session());
. Like that: