我需要传递从数据库中检索到的一些数据。
当我点击一个按钮时,我会向已点击的用户发送一条私人消息。我需要将该按钮中的一些数据传递给发送的消息。因为,在那条消息中,我有一个启动 WizardScene 的按钮。那么我该怎么做才能传递数据?谢谢你。
这是我的代码。
这是一个发布带有描述和回调按钮的照片的函数。
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 变量传递给按钮 TEST,然后传递给向导场景?我需要在用户对话框上的向导上使用它。
谢谢你