We've got a basic twiml set up that sends a call to multiple destinations, it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play loop="10">https://xxx.xxx.xxx/assets/MoH.wav</Play>
<Dial>
<Number>+1800XXXXXXX</Number>
<Number>+1912XXXXXXX</Number>
</Dial>
</Response>
The problem with this is that the <Dial> doesn't happen until the <Play> finishes. We want to play music to the caller while waiting for the call to be answered by one of the destination parties.
We've tried <Enqueue> to play the music but it still doesn't dial simultaneously.
Twilio developer evangelist here.
You are right that TwiML expects to finish one verb before it starts the next, so in your example code it will play the <Play> all the way through before starting to dial the numbers.
If you want to play music to the caller while the dial happens, then you will need to use <Enqueue> to put them into a holding pattern while you dial the other numbers. However, you will not be able to use TwiML to dial the numbers, instead you will need to make the outbound calls using the REST API.
Once one of the outbound calls connects, you can then connect it with the original call by <Dial>ling in to the <Queue> that you placed the caller in. You will also want to end the other calls using the REST API.
Related
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?
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.
I'm trying to create an customized Music for Call forwarding.
When someone calling the it's redirecting to Enqueue named by "support".
<Response>
<Enqueue waitUrl="waitMusic.xml"></Enqueue>
</Response>
waitMusic.xml (Playing the audio)
<Response>
<Play>http://audio_file.mp3</Play>
</Response>
I don't know how to continue, I tried all out of things, and nothing works.
Please help!
You have 2 legs, the user leg and the agent leg.
When the user calls to Twilio's number, Twilio will do a request to your server which should return (same TwiML as you are using, but with a queue name):
<Response>
<Enqueue waitUrl="waitMusic.xml">support</Enqueue>
</Response>
This puts the user in hold playing the music from waitMusic.xml if there are no agents available.
But you also need the logic for the agent. The agent will call to a Twilio phone, and in this case you'll return a different TwiML:
<Response>
<Dial>
<Queue url="agentWaitMusic.xml">support</Queue>
</Dial>
</Response>
This is a "dial queue" (docs) that automatically dequeues any user that is on the the queue "support" and connects them together. If there are no users in the queue, the agent will be put on hold, playing the music from "agentWaitMusic.xml".
It's important to use the same queue name (in this case "support") for both, the "enqueue" and the "dial queue" actions.
Do Play verb with loop 0 value cause the music to play till the call is connected?
https://www.twilio.com/docs/api/twiml/play
Twilio developer evangelist here.
Effectively in this situation you are looking to put your user in a queue while you dial your agents. This is how you'd do it:
First up, when you receive the incoming call you can respond with <Enqueue> that directs a user into a queue. You can set a waitUrl attribute that allows you to define either a music file or TwiML that will play while the user waits for the call to be answered.
<Response>
<Enqueue waitUrl='/wait-music'>incoming</Enqueue>
</Response>
While your incoming caller is waiting, you can then start making calls to your agents using the REST API. Once an agent connects and accepts the whisper you would then join the calls by dialling the <Queue>.
<Response>
<Dial><Queue>incoming</Queue></Dial>
</Response>
With this method you'd need to maintain whether your user has been answered yet and manually handle whether to redirect their call from the queue to more TwiML to <Record> a voicemail.
There is a more robust way to set all this up. It still requires enqueueing in the first place, but you should take a look at TaskRouter. It's an automated call distribution service with configurable workflows. There's a bit more setup involved on the Twilio side, but TaskRouter will handle directing calls to your agents and allow you to define rules for how to handle a user who's been waiting too long. I recommend you check out the TaskRouter documentation and then take a look at the quickstart guide as an example.
Let me know if that helps at all.
I am building an Interactive Voice Assistant using Twilio. My goal is to record parts of the conversation, process the recorded audio and
This is the answer to the /voice webhook (the one will receive Twilio's call)
<Response>
<Play>./welcome</Play>
<Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording"></Record>
</Response>
Processing the audio and providing an answer may take a long time, so I added a Pause at the end of /processing:
<Response>
<Play>./ok</Play>
<Pause length="10"></Pause>
</Response>
This is the answer when finished with /getRecording
<Response>
<Play>./answer</Play>
<Record maxLength="10" action="/processing" recordingStatusCallback="/getRecording "></Record>
</Response>
/welcome, /ok and /answer lead to corresponding audio files.
So I was able to execute all steps, I can check in my logs that /getRecording is actually executed to the end and the twiml sent back again, but the /answer after /getRecording is never executed by Twilio (and the call just ends).
Do you have any guidance for it? Does Twilio accept multiple recordings on the same call?
Note: For some reason, if instead of using the 'recordingStatusCallback' I use /getrecording as 'action' it does work... but then we wouldn't be sure the recording we are using is really generated, right?
Thank you for your help!
Twilio developer evangelist here.
Your /getRecording endpoint is called, however that is an asynchronous webhook in the context of the call. Returning TwiML to the recordingStatusCallback will not affect the current call.
Instead, you should use the REST API to modify the call by redirecting it to the next TwiML you want to execute based on the response to the recording file.
Hopefully the recording does take less than the 10 second pause that you are using, but you may want to add a loop into your /processing endpoint so that the call won't hang up on your caller. You can do this by redirecting the caller back to the start again:
<Response>
<Play>./ok</Play>
<Pause length="10"></Pause>
<Redirect>./processing</Redirect>
</Response>
Then, when you get the recording callback you redirect your caller out of this loop.
Let me know if that helps at all.
When a Twilio number receives an incoming voice call, what TwiML can I use so that the phone continues ringing indefinitely?
In certain circumstances, I want to pretend that the phone is ringing but there's nobody around to answer it and there's no voicemail configured. I thought the Reject verb could help. It appears to support only a busy signal or a "number disconnected" message.
One can use the Pause verb to have Twilio delay pickup. By specifying a sufficiently long delay, the call effectively rings "forever". For example,
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Pause length="600"/>
<Hangup />
</Response>
Probably the easiest way to do this is going to be to get an mp3 recording of a ringing phone, one that is very long (you can find them by googling) and setup twilio to <Play> the mp3 when someone calls it - I've done it and its very convincing.
Doing this will give you the extra benefit of letting you track who calls that number and how long they let it ring (of course you get billed for this).