I've recently run into an issue with the TwiML <Hangup>
verb. I have a simple setup that works as follows:
I have a Twilio number setup to receive incoming calls, and configured to use a TwiML bin that is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Record timeout="5" transcribe="false" trim="trim-silence" maxLength="10"/>
<Hangup/>
</Response>
The goal was to have the number pickup an incoming call, record at most 10s of audio from it, trim the silence, and then hangup. It does all of this correctly, except hangup.
At this moment, instead of hanging up, after a recording ends by reaching the maxLength
of 10s a new recording is started. This continues until the end of the call, and typically leads to 2-5 recordings per call. Its as if the <Hangup>
verb is entirely ignored. Here is an example of what I mean:
Twilio Call Details Screen
I'd like to know if anyone has encountered this before (and what you did to get around it), or what I can do to have my call hangup properly after recording. My current solution is this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<!-- This is a hacky solution. I found by accident that passing an invalid action argument causes the call to forcibly hangup (after the recording is completed) - hence the action "breakcall" below. = -->
<Record timeout="5" transcribe="false" trim="trim-silence"
action="breakcall" maxLength="10"/>
</Response>
However this is hacky, and I'd rather figure out the right way to do it.
Thank you!
You encounter this problem because
Any TwiML verbs occurring after a
<Record>
are unreachable.
This is documented here: (https://www.twilio.com/docs/voice/twiml/record).
Regarding your first code snippet, the one without action
If no 'action' is provided, will default to requesting the current document's URL.
As a consequence, you're entering a loop, and this explains why you end up with multiple recordings.
How to fix:
Create another bin which responds with <Hangup/>
and point the action
of the first bin to it.
first bin
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Record
action="[hangup_bin_url]"
timeout="5"
transcribe="false"
trim="trim-silence"
maxLength="10"
/>
</Response>
second bin
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Hangup />
</Response>
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With