我正在使用带有Telegraf模块的电报机器人

时间:2019-03-22 15:40:40

标签: node.js telegraf

我想在我的机器人中添加几个向导。 我如何进入另一个场景 我有以下内容(草图) 我得到这个错误无法读取未定义的属性“输入” 我的意思是我喜欢 任何帮助,将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

这是一个较晚的响应,但可能会对某人有所帮助。 您需要在之后 const stage = new Stage ...之前 bot.hears...

阶段注册中间件
bot.use(stage.middleware())

也可以使用其ID(而不是变量名称)进入场景。因此,不用Stage.enter('wiz2')来使用Stage.enter('task2')来输入Wizard2。