Thomas Anderson7286790
Posts: 0
Joined: Sat Dec 20, 2014 3:46 pm

Output XML to Twilio

Hey there, Appery is amazing. I am a newbie and searching for the best way to output XML to interact with a URL request from Twilio. I'm assuming that I will need to create custom server code to do this. Here is an example of the output required:

(< replaced with - so you can see the code)

-?xml version="1.0" encoding="UTF-8"?-

-Response-
-Say voice="woman" Please leave a message after the tone.-/Say-

Code: Select all

 -Record maxLength="20" /- 

-/Response-

Can you guys point me in the right direction to get started?

Regards!

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Output XML to Twilio

Hi Thomas,

Please let us know it this link will be helpful: http://devcenter.appery.io/documentat...

Regards.

Thomas Anderson7286790
Posts: 0
Joined: Sat Dec 20, 2014 3:46 pm

Output XML to Twilio

I am familiar with this tutorial. However, it does not address my needs. I need to write a server script that outputs TWIML - twilios markup language.

https://www.twilio.com/docs/api/twiml

I've since found a JavaScript library for doing just that at :

https://github.com/stevegraham/twilio-js

However, after installing it as a library and creating a server script using it as a dependency , I get errors when testing. I think I am not referencing the library properly in my server script. Could you play around with it and give me a working example? Then I can take it and run with it.

Thanks.!

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Output XML to Twilio

Hi Thomas,

Unfortunatly this library developed for node.js and could not be used in Appery.io server code from box.

But this is not hard to work with XML. Please take a look at following document. There you can find simple ways to work with XML:
https://developer.mozilla.org/en-US/d...

Regards.

Thomas Anderson7286790
Posts: 0
Joined: Sat Dec 20, 2014 3:46 pm

Output XML to Twilio

Thanks. Making some progress. Below is my code that produces the desired XML output when run on a javascript tester. However, when I test it using the Run function in the server code section on Appery.io I don't get the desired output.

The results are MIME Type: /
Status: 200

Twilio = Object.create({})
Twilio.TwiML = {
build: function(fn) {
var prolog = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&quot
var Buffer = function(level) {
var buffer = "&quot
var indent = function(i) { return new Array((i * 2) + 1).join(" ") }
var level = level || 1;
var append = function(str) {
buffer += indent(++level) + str + "\n&quot
level--;
}

Code: Select all

   var toAttributes = function(obj) { 
     var string = "&quot 
     for (key in obj) { string += " " + key + "=" + "\"" + obj[key] + "\"" } 
     return string; 
   } 

   var commonElement = function(verb) { 
     return function(str, attributes) { 
       append("<" + verb + toAttributes(attributes) + ">" + str + "</" + verb + ">") 
     } 
   } 

   var emptyElement = function(verb) { 
     return function(attributes) { append("<" + verb + toAttributes(attributes) + " />") } 
   } 

   var containerElement = function(verb) { 
     return function(fn, attributes) { 
       var buffer = new Buffer(level + 2); 
       append('<'+ verb + toAttributes(attributes) + '>'); 
       fn(buffer); 
       level -= 2; 
       append(buffer.emit().replace(/\n$/, '')); 
       level += 2; 
       append('</' + verb + '>'); 
     } 
   } 

   this.dial = function(arg, attributes) { 
     switch(typeof arg) { 
       case 'function': 
         return containerElement('Dial')(arg, attributes); 
         break; 
       case 'string': 
         return commonElement('Dial')(arg, attributes); 
         break; 
     } 
   } 

   this.say        = commonElement('Say'); 
   this.play       = commonElement('Play'); 
   this.redirect   = commonElement('Redirect'); 
   this.number     = commonElement('Number'); 
   this.client     = commonElement('Client'); 
   this.conference = commonElement('Conference'); 

   this.hangup     = emptyElement('Hangup'); 
   this.reject     = emptyElement('Reject'); 
   this.record     = emptyElement('Record'); 
   this.pause      = emptyElement('Pause'); 

   this.gather     = containerElement('Gather'); 

   this.emit       = function() { return buffer } 
 } 

 var buffer = new Buffer; 

 fn(buffer); 

 return prolog + "<Response>\n" + buffer.emit() + "</Response>&quot 

}
}

Twilio.TwiML.build(function(res) {

res.say("Holy shit, batman!");

Code: Select all

 res.hangup(); 

})

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Output XML to Twilio

attributes) { append(""<"" + verb + toAttributes(attributes) + """" + str + ""</"" + verb + """") } } var emptyElement = function(verb) { return function(attributes) { append(""<"" + verb + toAttributes(attributes) + "" "") } } var containerElement = function(verb) { return function(fn

Williamskido
Posts: 3
Joined: Thu Dec 17, 2020 3:42 am
Location: Italy
Contact: Website Skype

-

The jod has a WISD input and WISD outptu stages right now so In format does the data come from WISD output?

Now the output should be in XML format?

can anyone suggest which stage is used for that? and where is that stage used?
I quess XML output stage is used for it but where should the XML output stage be?

Is it before WISD output?

thanks,
Rahul

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Output XML to Twilio

Hello Rahul,

Could you please provide us with more details, screenshots or exact steps to reproduce this problem?

Return to “Issues”