等待用户响应。例如,机器人问用户的年龄,他进入它,机器人必须抓住他的答案,并发送下一个问题。我该怎么做?
发布于 2022-08-09 16:12:20
您只需看一看Telegraf.js文档,就可以知道如何使用。
要等待一条短信和回复,您可以这样做:
const { Telegraf } = require("telegraf");
const bot = new Telegraf(process.env.BOT_TOKEN); // Your bot api token
// waiting for messages and replying
bot.on("text", (ctx) => {
ctx.reply("Hello World");
});
bot.start();要回答一个特定的问题(例如:你叫什么名字),你可以这样做:
const { Telegraf } = require("telegraf");
const bot = new Telegraf(process.env.BOT_TOKEN); // Your bot api token
let ask = false;
let name;
bot.on("text", (ctx) => {
if(ask) {
name = ctx.message.text;
} else {
ask = true;
ctx.reply("What is your name?");
}
});
bot.start();https://stackoverflow.com/questions/73145201
复制相似问题