Pa Bebek
Pa Bebek

Reputation: 21

Twilio / TwiML on iOS - Using Enqueue and Dial

Basically, I am creating an iOS app that will Dial a phone number in my office when certain button is tapped. This is working fine, but now I want to have a music file played while waiting for the phone to be picked up.

Knowing that Dial cannot use a music file to replace the default wait tone, I was guided to use Enqueue's waitURL. However, I am lost on how to Dequeue so to start the Dial. This is how the whole TwiML looks right now, and it plays the whole song without dialing in:

<Response>
    <Enqueue waitUrl="waitMusic.xml">office</Enqueue>
    <Dial callerId="+12345678910">
        <Number >999-999-9999</Number>
    </Dial>
</Response>

waitMusic.xml is simply:

<Response>
  <play>slowrock.mp3</play>
</Response>

Is it not possible to use this TwiML?

Upvotes: 2

Views: 310

Answers (1)

philnash
philnash

Reputation: 73100

Twilio developer evangelist here.

You can't use <Dial> and <Enqueue> like that together. Here's what you need to do.

When the user taps the button have them make the call and return just the <Enqueue> in the TwiML response.

<Response>
    <Enqueue waitUrl="waitMusic.xml">office</Enqueue>
</Response>

And in that response also kick off a call to the number you want to dial using the REST API. When that call is answered, Twilio will request some TwiML, you should return a <Dial> with a nested <Queue> which will pop the top caller off of the queue and connect them to the person on the phone.

<Response>
    <Dial>
        <Queue>office</Queue>
    </Dial>
</Response>

You may need to do a bit more work to ensure you don't end up with anyone stuck in the queue, but that should get you started.

Upvotes: 2

Related Questions