我会在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');
});程序正确地写入文本,并将按钮放入。但如果我按"CANCEL“,它会在以下位置给出错误:
ctx.wizard.state.data.name = ctx.message.text;“文本未定义”,因为我按了“取消”,而我没有写任何东西。
那么,我如何才能离开场景而不前进,但如果我写了一个文本,它将在wizardScene中前进?
谢谢
发布于 2021-05-28 04:33:34
替换
ctx.message.text;
使用
ctx.update.callback_query.data;
因为回调按钮没有返回消息
https://stackoverflow.com/questions/64091380
复制相似问题