3

Building a dead simple Twilio app using Meteor, getting the call but XML is not being parsed (getting the usual 'Sorry, an application error has occured')

Pointed to xxxxx.meteor.com/api/twiml/voice or xxxxx.meteor.com/voice.xml:

  • Twilio responds with Error 11200 - HTTP retrieval failure (404)
  • Response body is the 'No site is deployed at this address'

Pointed to xxxxx.onmodulus.net/api/twiml/voice or voice.xml

  • This is exactly the same app, just configured to the corresponding urls
  • Twilio responds with Error 12100 - Document parse failure
  • Response body is modulus' equivalent of 'No site deployed', even though I was requesting a server side route.

Curl request from terminal produces the same results on both sites. This is the relevant code (the rest is boilerplate 'click the button' example). In my case, clicking the button fires the method below...

//lib.js
Router.route('/');

if (Meteor.isServer) {
  Router.route('/SERVER_SIDE_URL', {
     where: 'server',
     action: function() {
       console.log(this.request);
       var xmlData = "<?xml version=1.0 encoding=UTF-8?>";
       xmlData += '<Response><Say voice="man">Please, please work!</Say></Response>';

       this.response.writeHead(200, {'Content-Type': 'text/xml'});
       this.response.end(xmlData);
    }
  });

  Meteor.methods({
    makeCall: function(){
      twilio = Twilio("PUB_KEY", "PRIV_KEY");
      twilio.calls.create({
        to:'MY_PHONE_NUMBER',
        from: 'MY_TWILIO_NUMBER',
        url: 'SERVER_SIDE_URL'
      }, function(err, responseData) {
        if(!err && !responseData.error_message){
          console.log(responseData); 
          return responseData;
        } else{
          console.log(responseData);
          return responseData;
        }
      });
    }
  });
}

1 Answers1

3

Megan from Twilio here. Try putting the version and encoding in var xmlData in quotes.

var xmlData = "<?xml version='1.0' encoding='UTF-8'?>";

Hope that does the trick.

Also, I'm testing this locally running ngrok which allows you to tunnel your localhost to a publicly accessible URL. This makes it easy to make sure code works before heading into deployment.

If you're curious to see more about how ngrok works you can check out this post.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25