Xml response like below:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<!--my error message-->
<Reject/>
</Response>
enter code here:
currently i am using ruby to build response
xml.Response do |r|
r.Reject
end.text
I need a comment before reject verb..Any one help?
Twilio Evangelist here.
Twilio's Ruby helper library is built on Builder (see here). Therefore, you can use the standard Builder approach:
xml.Response do |r|
r.comment! "This is a comment!"
r.Reject
end.text
This will generate:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<!--This is a comment!-->
<Reject/>
</Response>
Hope this helps!
Related
Other than one being slightly more verbose than the other, functionally is there any difference between these two TwiML blocks, assuming there is no additional configuration? I was unable to find anything in the docs.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>111-111-1111</Dial>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>111-111-1111</Number>
</Dial>
</Response>
You are right, both TwiML files are equivalent.
I am sorry. I am a new to this so forgive me in advance. I'm searching for an answer and I was not able to understand when searching previous inquiries.
I am starting a TwiML Bin and so far my code is
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This call is being recorded for quality assurance purposes</Say> .
<Dial record="true">+1 858-220-8650</Dial>
</Response>
When I receive the forwarded phone call, and I answer it, I want a message to say "phone call from website xyz" and then connect the call.
Is this possible from just within the TwiML Bin? Or do I have to utilize some external code?
You can do it with TwiML Bins, you will need to use the URL attribute on the Number noun to "chain" them together.
First create your whisper bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>phone call from website xyz</Say>
</Response>
Then use this with the URL attribute on your existing bin, like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This call is being recorded for quality assurance purposes</Say>
<Dial record="true">
<Number url="https://handler.twilio.com/twiml/xxxxxxxxxxxxxxxxxxxxxxx">
18582208650
</Number>
</Dial>
</Response>
When the call is answered it will say the message from the whisper bin immediately before connecting the calls. Hope this helps! :)
My server is returning the following twiml
<?xml version="1.0" encoding="UTF-8"?>
<Response><Dial callerId="+16122610242"><Number>+16128687242</Number></Dial>
<Record recordingStatusCallback="https://myserver.com/twilio/recording" transcribe="true" transcribeCallback="https://myserver.com/twilio/transcribe" trim="trim-silence"/>
</Response>
Why is the call not being recorded and transcribed?
I am pretty sure the record needed to be set on the Dial in order for it to record
I'm trying to do something pretty simple that is straight from the Twilio blog at https://www.twilio.com/blog/2009/05/dialing-multiple-numbers-simultaneously-with-twilio.html
Namely, this:
<?xml version=“1.0” encoding=“UTF-8”?>
<Response>
<Dial action=“/handleDialStatus.php” method=“GET”>
<Number>877-555-1212</Number>
<Number>877-999-1234</Number>
<Number>877-123-4567</Number>
</Dial>
</Response>
But it's returning 'Invalid TwiML'.
Any ideas?
Twilio developer evangelist here.
As Devin suggested in the comments, it looks like the blog post had smart quotes in the XML. The XML you need instead is:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial action="/handleDialStatus.php" method="GET">
<Number>877-555-1212</Number>
<Number>877-999-1234</Number>
<Number>877-123-4567</Number>
</Dial>
</Response>
I've updated the original blog post to fix this issue there too.
Let me know if this helps at all.
Alright, so the ultimate goal here is to parse the data inside of an xml response. The response comes in the format of a ruby string. The problem is that I'm getting an error when creating the xml file from that string (I know for a fact that response.body.to_s is a valid string of xml:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<CardTxn>
<authcode>123</authcode>
<card_scheme>Mastercard</card_scheme>
<country>United Kingdom</country>
</CardTxn>
<datacash_reference>XXXX</datacash_reference>
<merchantreference>XX0001</merchantreference>
<mode>TEST</mode>
<reason>ACCEPTED</reason>
<status>1</status>
<time>1286477267</time>
</Response>
Inside the ruby method I try to generate an xml file:
doc = Nokogiri::XML(response.body.to_s)
the output of doc.to_s after the above code executes is:
<?xml version="1.0"?>
Any ideas why the file is not getting generated correctly?
This works for me on 1.9.2. Notice it's Nokogiri::XML.parse().
require 'nokogiri'
asdf = %q{<?xml version="1.0" encoding="UTF-8"?>
<Response>
<CardTxn>
<authcode>123</authcode>
<card_scheme>Mastercard</card_scheme>
<country>United Kingdom</country>
</CardTxn>
<datacash_reference>XXXX</datacash_reference>
<merchantreference>XX0001</merchantreference>
<mode>TEST</mode>
<reason>ACCEPTED</reason>
<status>1</status>
<time>1286477267</time>
</Response>
}
doc = Nokogiri::XML.parse(asdf)
print doc.to_s
This parses the XML into a Nokogiri XML document, but doesn't create a file. doc.to_s only shows you what it would be like if you printed it.
To create a file replace "print doc.to_s" with
File.open('xml.out', 'w') do |fo|
fo.print doc.to_s
end