2

When utilizing and TwiML, how can I setup a repeating loop?

My use case is calling a support line, Twilio waiting through on hold music until a tech answers call and dials 1. I can't figure how to wait for human to pickup so I figure repeat forever until pickup. If I can figure out repeat.

1 Answers1

2

You can use the loop attribute with a value of 0.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Say loop="0">Hello World</Say>
</Response>

The 'loop' attribute specifies how many times you'd like the text repeated. The default is 1. Specifying '0' will cause the verb to loop until the call is hung up.

https://www.twilio.com/docs/api/twiml/say#attributes-voice

.

or if you are playing an audio file

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play loop="0">https://api.twilio.com/cowbell.mp3</Play>
</Response>

The 'loop' attribute specifies how many times the audio file is played. The default behavior is to play the audio once. Specifying '0' will cause the verb to loop until the call is hung up.

https://www.twilio.com/docs/api/twiml/play#attributes

Alex Baban
  • 11,312
  • 4
  • 30
  • 44
  • Is there a way to just loop it couple of times? Trying this was returning an error (503). – ZZzzZZzz Feb 16 '21 at 22:48
  • 1
    @ZZzzZZzz `loop="2"` should loop two times. I don't think the error comes from the number of loops. Maybe ask a question and post your code. You're probably not returning valid XML. – Alex Baban Feb 17 '21 at 01:16