javascript - Telegraf:等待用户回复并立即使用
问题描述
我希望我的机器人在输入特定命令后等待用户的消息,然后像这样使用它:
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}");
});
解决方案
您需要像下面的代码一样使用 callback_query。
app.on('callback_query', async (ctx) => {
ctx.reply(`Your answer was: ${ctx.update.callback_query.data}`);
})
推荐阅读
- php - 为什么我在 Angular 中收到 HttpErrorResponse 错误?
- java - 发生键盘事件时 VideoView 重新启动
- azure - Notary init 不适用于 Microsoft azure 容器注册表
- signalr - 一个文件被分成几部分并从信号器核心的集线器发送到客户端
- android - 发布具有 SMS 权限的应用时出现问题
- java - 如何将 .jar 的“-XX:+UseG1GC -Xmx1g -Xms512m”参数放入服务包装器中?
- ios - 滑动时选择 CollectionView 单元格
- angular - 如何在 Angular + .Net 核心控制器设置中知道客户端机器的 IP 地址?
- php - 在不替换php中的索引元素的情况下对数组进行排序
- python - 全息图散点图的回归线?