Kik Bot键盘项目没有变化

时间:2016-07-12 04:33:03

标签: javascript node.js kik

所以我有一个我正在研究的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;
                  }

1 个答案:

答案 0 :(得分:1)

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)
                   });