【问题标题】:Telegraf: wait for a user reply and use it right afterTelegraf:等待用户回复并立即使用
【发布时间】:2021-02-21 05:57:14
【问题描述】:

我希望我的机器人在输入特定命令后等待用户的消息,然后像这样使用它:


const { Telegraf } = require('telegraf')
const app = new Telegraf(process.env.BOT_TOKEN);

app.command('request', async(ctx) => {
   ctx.reply("Hi user, what is your request?");
   //Wait for the user response and use it
   ctx.reply("Your answer was: ${user_answer}");
});

【问题讨论】:

标签: javascript node.js async-await telegram telegraf


【解决方案1】:

您需要使用如下代码所示的回调查询。

   app.on('callback_query', async (ctx) => {
    ctx.reply(`Your answer was: ${ctx.update.callback_query.data}`);
   })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-22
    • 2013-05-01
    • 1970-01-01
    • 2021-12-19
    • 2020-08-28
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多