2017-02-19 11 views
0

Мне сложно создавать файлы TWIML с узлами. Я создаю исходящие вызовы, и они работают со статическим XML-файлом или твим-бином, но не с моей конечной точкой.Как обслуживать Twiml Nodejs

Знаете ли вы, что не так?

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()); 

}); 

тогда, когда я иду, чтобы инициировать вызов

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) 

    }); 

ответ

1

Вместо

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

попробовать

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