gpt4 book ai didi

javascript - Kik Bot 键盘项目没有改变

转载 作者:行者123 更新时间:2023-12-03 06:33:54 25 4
gpt4 key购买 nike

因此,我目前正在开发一个 Kik 机器人,它使用键盘来建议用户可能想对机器人说的话,就像大多数 Kik 机器人所做的那样。对于不同的用户,我希望弹出不同的选项。我创建了一个函数来检查当前用户是否是这些特殊用户中的一个,如果是,则为他们显示另一个选项。我从许多测试中证实该函数返回 true,但键盘选项拒绝改变普通用户所看到的内容。这是我的代码

message.stopTyping();
if (userIsAdmin(message.from)) //This function returns the boolean true
{
message.reply(Bot.Message.text("I don't understand what you are trying to ask me. Please reply with something I can work with.").addResponseKeyboard(["Homework", "Admin Options"]))
}
else
{
message.reply(Bot.Message.text("I don't understand what you are trying to ask me. Please reply with something I can work with.").addResponseKeyboard(["Homework"])) //The bot always displays this as the keyboard, no matter if the user is an admin or not
}
break;
}

最佳答案

Node Js 喜欢在函数开始运行时继续执行程序,以便可以处理更多请求。函数 userIsAdmin() 向 Firebase 发出 Web 请求,因此虽然只需要几分之一秒的时间来下载数据,但其时间足以让它在完成之前返回 false。我要做的就是编辑函数 userIsAdmin() ,以便它将回调作为参数,然后调用它。这是我的新代码:

let sendingMessage = Bot.Message.text("I don't understand what you are trying to ask me. Please reply with something I can work with.")

adminCheck(user, function(isAdmin)
{
if (isAdmin)
{
bot.send(sendingMessage.addResponseKeyboard(adminSuggestedResponces), user)
}
else
{
bot.send(sendingMessage.addResponseKeyboard(userSuggestedResponces), user)
}
});

这是我的 adminCheck 函数:

var isAdmin = false
adminsRef.on("child_added", function(snapshot)
{
if(user == snapshot.key && snapshot.val() == true)
{
isAdmin = true
}
});

adminsRef.once("value", function(snapshot)
{
callback(isAdmin)
});

关于javascript - Kik Bot 键盘项目没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38320076/

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