twilio-python icon indicating copy to clipboard operation
twilio-python copied to clipboard

Invalid nested TwiML

Open remik opened this issue 9 years ago • 2 comments

Nested TwiML is wrong nested.

Version: 6.0.0

Code Snippet


In [2]: from twilio.twiml.voice_response import VoiceResponse

In [3]: r = VoiceResponse()

In [5]: g = r.gather(method='POST', action="http://example.com", timeout=30, num_digits=1)

In [7]: g.say("hello")
Out[7]: <twilio.twiml.voice_response.VoiceResponse at 0x110f987d0>

In [8]: print(str(r))
<?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://example.com" method="POST" numDigits="1" timeout="30" /><Say>hello</Say></Response>

It should be

<?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://example.com" method="POST" numDigits="1" timeout="30"><Say>hello</Say></Gather></Response>

remik avatar Apr 05 '17 13:04 remik

hey @remik!

We updated the TwiML generator in this version of the library to return the parent element. You can achieve this effect by using:

from twilio.twiml.voice_response import VoiceResponse
from twilio.twiml.voice_response import Gather

g = Gather(method='POST', action="http://example.com", timeout=30, num_digits=1)
g.say("hello")

r = VoiceResponse()
r.append(g)
print(str(r))
# <?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://example.com" method="POST" numDigits="1" timeout="30"><Say>hello</Say></Gather></Response>

jingming avatar Apr 05 '17 14:04 jingming

Thanks! You should write some migrations docs, a lot changes.

remik avatar Apr 05 '17 16:04 remik