twilio-python
twilio-python copied to clipboard
Invalid nested TwiML
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>
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>
Thanks! You should write some migrations docs, a lot changes.