Kik Bot 键盘项目没有改变

Kik Bot keyboard items not changing

所以我有一个 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 发出网络请求,因此虽然只需要几分之一秒来下载数据,但它的时间足以让 return 在完成之前为 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)
                   });