Hubot ReferenceError:调用API时未定义主体

时间:2019-01-03 18:13:00

标签: coffeescript slack hubot

我正在尝试遵循本教程https://poanchen.github.io/blog/2016/10/18/how-to-build-a-simple-chat-bot-using-hubot-that-determine-gender-based-on-name

这是我的代码:

module.exports = (robot) ->
  robot.hear /check gender for (.*)/i, (res) ->
      personName = escape(res.match[1])
      res.http("https://api.genderize.io/?name=" + personName)
        .header('Accept', 'application/json')
        .get() (error, response, body) ->
        try
          json = JSON.parse(body)
          res.send "Probability of " + "#{json.probability}" + " that " + personName + " is a " + "#{json.gender}.\n"
        catch error
          res.send "something went wrong... #{error}"

例如,当我键入“检查鲍勃性别”时,我总是收到一条错误消息,提示“ ReferenceError”。有人知道如何解决这个问题吗?

0 个答案:

没有答案