当我尝试提供年龄信息时,它会先要求我的性别,然后是身高。如果我输入了身高,则会再次要求我的性别两次以及一次年龄。如何让它按照下列方式工作:它应该问一个问题。如果我回答不好,它应该再次询问此问题;如果回答正确,则应使用相同的算法问新问题。
let weight, height, age, dailyNorm, A, proteine, fat, glucide, gen;
let low=1.2, small=1.4, middle=1.6, big=1.7;
const TelegramBot = require('node-telegram-bot-api');
const token = '734206894:... ';
const bot = new TelegramBot(token, {polling: true,
onlyFirstMatch:true, });
bot.onText(/\/start/, (msg) => {
bot.sendMessage(msg.chat.id,"Bot activated" , { "reply_markup": {
"keyboard":[["Calculate" ], ["Report"]]
}});
console.log (msg.text);
});
function dataGen(a){
bot.sendMessage(a.chat.id,"Your gen(-m,-f)?"); console.log (1)
bot.on("message", (msg) => {
if (msg.text=="m"){ gen="m"; dataAge(msg);}
else if (msg.text=="f"){ gen="f"; dataAge(msg);}
else { dataGen(msg);}
console.log (2)
});
}
function dataAge(b){
bot.sendMessage(b.chat.id,"Your age?");