我会在带有“取消”按钮的 WizardScene 中的消息之后放置一个按钮。但我检索到一些错误:
这是我的巫师场景:
const superWizard = new WizardScene('super-wizard',
async ctx => {
ctx.wizard.state.data = {};
ctx.telegram.sendMessage(ctx.from.id, "Insert name", {
parse_mode: 'MarkdownV2',
reply_markup: cancelOrder()
})
return ctx.wizard.next();
},
ctx => {
ctx.wizard.state.data.name = ctx.message.text;
ctx.reply("here is your name: "+ctx.wizard.state.data.name);
return ctx.scene.leave();
}
);
const stage = new Stage([superWizard]);
bot.use(session());
bot.use(stage.middleware());
这是我的取消订单功能:
function cancelOrder() {
const annullaBtn = Markup.inlineKeyboard([
Markup.callbackButton('CANCEL', `cancelOrder_btn`),
])
return annullaBtn;
}
和按钮动作:
bot.action("cancelOrder_btn", (ctx) => {
ctx.replyWithMarkdown(`Ordine *ANNULLATO* correttamente`)
return ctx.scene.leave('super-wizard');
});
该程序正确写入文本,并放置按钮。但是,如果我按“取消”,则会在以下位置出现错误:
ctx.wizard.state.data.name = ctx.message.text;
因为“文本未定义”,因为我按下取消并且我没有写任何东西。
那么我怎样才能离开场景而不前进,但是如果我写了一个文本,它会在wizardScene中前进?
谢谢