I am having a hard time create my TWIML files with nodejs. I am creating outbound calls and they work with a static XML file or twiml bin but not my endpoint.
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
response.type('text/xml');
response.send(twiml.toString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.