解决Node JS中的引用错误

时间:2015-05-27 11:22:37

标签: javascript node.js heroku get

我工作在一个节点js后端,它通过telerivet webhook api接收用户短信,代码应该发送一个获取请求,以便将一个网页转换为纯文本并将其发送回原始文本。 device..below是我的代码

var express = require('express');
var request = require("request");
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function (request, response) {
    response.send('Hello World!');
});
var bodyParser = require('body-parser');
var WEBHOOK_SECRET = "62DZWMCCFFHTTQ44CG3WUQ94CTT7GAAN";
app.post('/telerivet/webhook',
    bodyParser.urlencoded({
        extended: true
    }),
    function (req, res) {
        var secret = req.body.secret;
        if (secret !== WEBHOOK_SECRET) {
            res.status(403).end();
            return;
        }
        if (req.body.event == 'incoming_message') {
            var content = req.body.content;
            var from_number = req.body.from_number;
            var phone_id = req.body.phone_id;
            request("http://boilerpipe-web.appspot.com/extract?url=http%3A%2F %2Fwww.caclub.in&extractor=ArticleExtractor&output=text&extractImages=", function (error, response, body) {
                console.log(body);
            });
            //do something with the message, e.g. send an autoreply
            res.json({
                messages: [{
                    content: " " + body
                }]
            });
        }
        res.status(200).end();
    }
);
app.listen(app.get('port'), function () {
    console.log('Node app is running on port', app.get('port'));
});

我已经托管了我的应用程序@ heroku,每次应用程序运行它都会给我一个错误,告诉我"未定义对body的引用"尽管我在日志中获得了预期的输出(www.caclub.in的纯文本) )使用命令heroku日志...请帮忙,我哪里出错

0 个答案:

没有答案