gpt4 book ai didi

javascript - 使用 node-telegram-bot-api 顺序执行功能

转载 作者:行者123 更新时间:2023-11-30 06:18:14 26 4
gpt4 key购买 nike

当我尝试发送有关我的年龄的信息时,它会先询问我的年龄,然后再询问我的高度。如果我写的是我的高度,那就是问我的世代 2 倍和 1 倍我的年龄。如何让它像这样工作:它应该问一些事情。然后如果我回答了一些问题但答案不好,它应该再次问这个问题,如果答案很好它应该使用相同的算法提出新问题。

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👶?");

最佳答案

用于发送顺序问题:

var answerCallbacks = {};

bot.on('message', function (message) {
var callback = answerCallbacks[message.chat.id];
if (callback) {
delete answerCallbacks[message.chat.id];
return callback(message);
}
});

bot.onText(/questions/, function (message,match) {
bot.sendMessage(message.chat.id, "Enter your name").then(function () {
answerCallbacks[message.chat.id] = function (answer) {
var name = answer.text;
bot.sendMessage(message.chat.id, "Enter your address").then(function () {
answerCallbacks[message.chat.id] = function (answer) {
var address = answer.text;
bot.sendMessage(message.chat.id, "Enter your phone ").then(function () {
answerCallbacks[message.chat.id] = function (answer) {
var phone = answer.text;
bot.sendMessage(message.chat.id, name + address + phone + " saved!");
}
});
}
});
}
});
});

关于javascript - 使用 node-telegram-bot-api 顺序执行功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54842331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com