简体   繁体   English

如何为 Twiml Nodejs 提供服务

[英]how to serve Twiml Nodejs

I am having a hard time create my TWIML files with nodejs.我很难用 nodejs 创建我的 TWIML 文件。 I am creating outbound calls and they work with a static XML file or twiml bin but not my endpoint.我正在创建出站调用,它们使用静态 XML 文件或 twiml bin 但不适用于我的端点。

do you know what is wrong?你知道有什么问题吗?

app.post('/twiml-generator', function(req, res){
    var name = "billy";
    //Create TwiML response
    var twiml = new twilio.TwimlResponse();

    twiml.say("Hello from your pals at Twilio! Have fun. Love " + name);

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

});

then when i go to initiate the call然后当我去发起呼叫时

  client.calls.create({ 
    url: 'http://myHOSTEDsite.com/twiml-generator',//ISSUE HERE but if i use a twiml bin or static xml, it works// so my endpoint must be the issue 
    to: targetNumber, 
    from: "+14444444444", // my trail number 
    timeout: 12

  }, function(err, call) { 
    console.log("call made"); 
    //console.log(call)

  }); 

Instead of代替

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

try尝试

res.set('Content-Type', 'text/xml');
res.send(twiml.toString());

This is what Twilio doc says这就是 Twilio 文档所说的

response.type('text/xml');
response.send(twiml.toString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM