我有一个机器人可以监听来自 Slack 的聊天,如果匹配,它会根据定义的主体做出反应。
在下面的示例中,当我键入 e2e 时,它会执行函数 robot.hear(/e2e/i)。我还可以看到它进行了 http 调用并在控制台中打印了值,但是 res.send 命令失败了。它返回错误 ERROR TypeError: Object # has no method 'send'
hubot_example.js
module.exports = function(robot) {
robot.hear(/badger/i, function(res) {
res.send("Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS");
});
robot.hear(/e2e/i, function(res) {
robot.http("https://api.mycompany.com/v1/users?offset=50&limit=50").get()(function(err, res, body) {
var rateLimitRemaining;
if (res.statusCode !== 200) {
res.send("Request didn't come back HTTP 200 :(");
return;
}
console.log(body);
return res.send("Got back " + body);
});
});
};
错误:
2015-04-15T12:49:01.11-0400 [App/0] OUT [Wed Apr 15 2015 16:49:01 GMT+0000 (UTC)] ERROR TypeError: Object #<IncomingMessage> has no method 'send'
2015-04-15T12:49:01.11-0400 [App/0] OUT at /home/vcap/app/scripts/example.js:14:24
2015-04-15T12:49:01.11-0400 [App/0] OUT at IncomingMessage.<anonymous> (/home/vcap/app/node_modules/hubot/node_modules/scoped-http-client/src/index.js:83:20)
2015-04-15T12:49:01.11-0400 [App/0] OUT at IncomingMessage.emit (events.js:117:20)
2015-04-15T12:49:01.11-0400 [App/0] OUT at _stream_readable.js:944:16
2015-04-15T12:49:01.11-0400 [App/0] OUT at process._tickCallback (node.js:448:13)