错误TypeError:对象#<incomingmessage>没有方法'send'</incomingmessage>

时间:2015-04-15 16:53:11

标签: javascript node.js hubot slack-api

我有一个机器人,可以听取来自Slack的聊天记录,如果匹配,它会根据定义的身体做出反应。

在下面的示例中,当我键入e2e时,它会执行功能robot.hear(/ e2e / i)。我还可以看到它调用http并在控制台中打印值,但res.send命令失败。它返回错误ERROR TypeError:对象#没有方法&#39;发送&#39;

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&amp;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)

0 个答案:

没有答案