Mike Paszkiewicz
Mike Paszkiewicz

Reputation: 65

Twilio TWIML POST request: Document Parse Error

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:

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

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

Upvotes: 3

Views: 1466

Answers (1)

Megan Speir
Megan Speir

Reputation: 3811

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.

Upvotes: 3

Related Questions