我需要传递一些从数据库中检索的数据。
当我点击一个按钮时,我会向已经点击的用户发送一条私人消息。我需要从该按钮向发送的消息传递一些数据。因为,在这条消息中,我还有一个启动WizardScene的按钮。那么我该如何传递数据呢?谢谢。
这是我的代码。
这是一个函数,用于发布带有描述和callbackup按钮的照片。
my function() {
...
let productId = //obtain from a db;
await bot.telegram.sendPhoto(
channel_id,
{ source: filepath },
{
caption: description.join("\n"),
parse_mode: 'MarkdownV2',
reply_markup: productButtons.reply_markup
}
)
return productId;
...}按钮是:
const productButtons = Extra.markup((m) =>
m.inlineKeyboard([
[m.callbackButton('TEST', 'test_btn')],
])
)当有人点击它时,它会向私人用户发送一条消息,其中包含以下内容:
bot.action('testa_btn', (ctx) => {
console.log('testa')
let text = `My text about ${productId}`
ctx.telegram.sendMessage(ctx.from.id, o_functions.escapeReplace(text), {
parse_mode: 'MarkdownV2',
reply_markup: startBtn.reply_markup
})
});这将发送一个需要写入productid的文本,以及一个启动向导场景的按钮:
const startBtn = Extra.markup((m) =>
m.inlineKeyboard([
[m.callbackButton('START', 'start_btn_wizard')],
])
);
bot.action('start_btn_wizard', (ctx) => {
return ctx.scene.enter('super-wizard');
})那么,如何将productId变量首先传递给按钮测试,然后传递给向导场景呢?我需要在用户对话的向导中使用它。
谢谢
发布于 2021-03-30 01:07:10
要将数据从回调按钮传递到处理程序,然后再传递到向导场景,您需要做几件事。
const startBtn = Extra.markup((m) => m.inlineKeyboard([ m.callbackButton('START',start\_btn\_wizard\_${product\_id}),]) );
bot.action(/start_btn_wizard_+/,(ctx) => { let product_id = ctx.match.input.substring(17);//在此处添加所有必需的向导验证product_id return ctx.scene.enter(‘超级向导’);});
ctx.scene.state从场景内部再次提取它。bot.action(/start_btn_wizard_+/,(ctx) => { let product_id = ctx.match.input.substring(17);//在此处添加所有必需的向导验证返回ctx.scene.enter(‘超级向导’,{ product_id : product_id});});
在向导内部,您可以使用ctx.scene.state.product_id访问product_id。
我希望这能帮助到一些人,尽管现在可能太晚了
https://stackoverflow.com/questions/63991174
复制相似问题