无法访问对象方法 - Node.JS,Twilio,Heroku

时间:2014-03-12 08:47:38

标签: node.js heroku twilio

我正在Heroku上运行Twilio应用程序,我正在尝试设置一个简单的POST请求来接收传入的短信。出于某种原因,我收到一条错误消息:

"TypeError: Object #<RestClient> has no method 'validateExpressRequest'"

我已经检查了几个示例和API文档,但不确定为什么我无法访问方法'validateExpressRequest'。

有人可以帮忙吗?谢谢。

这是我的代码:

var http = require('http');
var express = require('express');
var accountSid = 'xxx';
var authToken = "xxx";
var client = require('twilio')(accountSid, authToken);
var app = express();

app.configure(function () {
    app.use(express.urlencoded());
});

//Create a route to resp
app.post('/respondToSms', function(req,res) {
    //Validate that this request came from TW
    if(client.validateExpressRequest(req, authToken)) {
        var twiml = new client.TwimlResponse();

        twiml.Sms('Hi, thanks for sending!');

        res.type('text/xml');
        res.send(twiml.toString());
    }
    else {
        res.send('you are not twilio.');
    }
});

var port = Number(process.env.PORT || 5000);
app.listen(port, function() {
    console.log("Listening on " + port);
});

1 个答案:

答案 0 :(得分:0)

实际上,看看here,似乎validateExpressRequesttwilio而不是RestClient的函数。

试试这个:

var twilio = require('twilio');
...
if(twilio.validateExpressRequest(req, authToken)) {
...