Node.js Twilio TwimlResponse不是构造函数

Node.js Twilio TwimlResponse不是构造函数,node.js,twilio,Node.js,Twilio,我遵循了其他答案,并将我的要求简化为: var http = require('http'); var twilio = require('twilio'); http.createServer(function (req, res) { var resp = new twilio.TwimlResponse(); resp.say({voice:'woman'}, 'ahoy hoy! Testing Twilio and node.js'); res.writeHead(

我遵循了其他答案,并将我的要求简化为:

var http = require('http');
var twilio = require('twilio');
http.createServer(function (req, res) {
var resp = new twilio.TwimlResponse();
     resp.say({voice:'woman'}, 'ahoy hoy! Testing Twilio and node.js');
     res.writeHead(200, {
      'Content-Type':'text/xml'
     });
     res.end(resp.toString());
}).listen(1337);
这将返回:

TypeError: twilio.TwimlResponse is not a constructor
at Server.<anonymous> (C:\Users\jmmann\Projects\node-sms\server.js:9:14)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:548:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
TypeError:twilio.TwimlResponse不是构造函数
在服务器上。(C:\Users\jmmann\Projects\node sms\server.js:9:14)
两点钟(events.js:106:13)
在Server.emit上(events.js:191:7)
在HTTPParser.parserOnIncoming[作为onIncoming](_http_server.js:548:12)
在HTTPParser.parserOnHeadersComplete(_http_common.js:99:23)

有什么想法/建议吗?

我认为您正在尝试在当前版本3.X SDK中使用旧的不推荐版本2.X代码。 下面是Twilio网站上使用当前3.X版SDK实现此目的的一些示例:

const http = require('http');
const VoiceResponse = require('twilio').twiml.VoiceResponse;

http.createServer((req, res) => {
    // Create TwiML response
    const twiml = new VoiceResponse();

    twiml.say('Hello from your pals at Twilio! Have fun.');

    res.writeHead(200, {'Content-Type': 'text/xml'});
    res.end(twiml.toString());
})
.listen(1337, '127.0.0.1');

console.log('TwiML server running at http://127.0.0.1:1337/');

如果您使用的是旧的2.X版本的SDK,您可以使用页面右上角附近的选择器切换示例。

您使用的是什么版本的SDK,因为TwimlResponse在当前的3.X版本中不推荐使用。非常感谢您提供的2.X/3.X信息,这正是问题所在<代码>常量MessagingResponse=require('twilio').twiml.MessagingResponse