Gather after caller hangs up - twilio

Is it possible to play a recording and then gather digits from the receiver of a call after a call ends (the caller hangs up)?
Similar to: https://www.twilio.com/docs/api/twiml/gather just that it's the receiver and not the caller who ask and that it happens when the call ends.
Thanks!
Morten

Twilio Evangelist here. Thanks for the clarification.
You can do this, but you need to use a conference call. Imagine Alice is calling Jack. Normally, you would use TwiML like this:
<Response>
<Dial>
+15551234567
</Dial>
</Response>
What you need to do is dial Alice into a conference call:
<Response>
<Dial>
<Conference>Alice and Jack</Conference>
</Dial>
</Response>
Then you need to make an outbound API call to dial Jack into the conference. In Ruby this would be something like this:
require 'twilio-ruby'
client = Twilio::REST::Client.new "account-sid", "account-token"
cient.account.calls.create to: "+15551234567", from: "some-twilio-number", url: "Your app URL"
This will use the same TwiML as above to join Jack into the conference. You'll need to look at the details for a <Conference> to avoid/select holding music, and to prevent the conference ending when Alice hangs up. Something like this:
<Response>
<Dial>
<Conference endConferenceOnExit="false" beep="false" waitUrl="http://some-twilml-no-hold-music">
Alice and Jack
</Conference>
</Dial>
</Response>
Now, you will also need to use the callbacks for when the call ends (you should also set this on your Twilio Number in the Dashboard, or through the API.
Now, you can take the Call SID of whoever remains in the conference call (you'll get this when you receive the initial request for the TwiML), and use the REST API to modify that call, redirecting them to new TwiML:
require 'twilio-ruby'
client = Twilio::REST::Client.new "account-sid", "account-token"
call = client.account.calls.get "my-call-sid"
call.redirect_to url: "http://new-url-of-twiml", method: "POST"
This allows you to redirect the call to TwiML such as:
<Response>
<Gather action="http://some-url-to-send-digits-to">
<Play>http://some-mp3-or-wav-file</Play>
</Gather>
</Response>
Twilio will play the MP3/WAV file, while listening for any key (DTMF) tones the user enters. You'll need to configure your <Gather> depending on how many keys you want to listen for etc. But that's very straight forward.
Hope this helps!

Related

simulring and collect digits from dialed number to accept call

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>
<Dial>
<Number>+1800XXXXXXX</Number>
<Number>+1912XXXXXXX</Number>
</Dial>
</Response>
The problem is I want to have one of the destination parties press a digit ( like "1" for example ) before twilio actually bridges the call to them.
I've looked at but that only seems to get digits from the caller, not the callee.
Twilio developer evangelist here.
To have the recipient of a call started by a <Number> perform an action, you need to provide a URL as the url attribute of the <Number>. When the call connects, Twilio will make a webhook request to that URL and you can return TwiML from the URL. Within that TwiML you can include a <Gather> to have the recipient enter a digit before you connect the call. See the documentation for the url attribute for <Number> for more detail.

Twilio call forwarding one after another - how to disconnect if person picks up the call

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say> Connecting call to Pinto </Say>
<Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
<Number>XXXXXXXX</Number>
</Dial>
<Say> Pinto is not picking up the call, now connecting call to Management </Say>
<Dial record ="record-from-answer" timeout="10" hangupOnStar ="true">
<Number>XXXXXXXX</Number>
</Dial>
<Say> No one is picking up right now. Please text us at +12022171828 </Say>
</Response>
Above is the call forwarding flow for one after another.
What I'm looking here is,
If 1st user attended the call, then it should not initiate the call to 2nd number and also it should not say text message which is at last line
If 1st user disconnected, then redirect call to 2nd number - if 2nd number not picking up the call then it should say text message which is at last line
if 1st user disconnected, then redirect call to 2nd number - if 2nd number picked up the call then it should not say text message which is at last line
Also I want to Implement Transcribe & Transcribe call back by using TwiML.
So, please help me like how we need to do with that?
To carry out this flow, you cannot perform the entire thing in one TwiML response. Instead, you will need to provide the <Dial> element with URL in the action attribute so that once the first call completes, Twilio makes a webhook to find out what to do next.
So, your first TwiML response should look like:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say> Connecting call to Pinto </Say>
<Dial record="record-from-answer" timeout="10" hangupOnStar="true" action="/complete">
<Number>XXXXXXXX</Number>
</Dial>
</Response>
Above I've added action="/complete" to the <Dial> and this means we need an application to be able to respond to HTTP requests to /complete as well. We also need this to be an application and not a static response as we need to work out whether the call was answered or not and decide on what to do next and what TwiML to respond with.
We can do this because one of the parameters that Twilio sends to the action URL is DialCallStatus. This parameter can be "completed", "busy", "no-answer", "failed" or "canceled" and this tells you what happened in that first call.
So, in your case, you will want to check the DialCallStatus and if it is "completed" then you do not need to return the next <Say> and <Dial>. If, however, the DialCallStatus is one of the other statuses, you do want to return the next <Say> and <Dial>. That <Dial> should include another action URL that makes the same choice at the end of the second <Dial>.
I'm not sure what language you are building with, but a pseudo-code idea of this would look like this:
post '/complete' do
if params["DialCallStatus"] != "completed"
return "<Response><Hangup/></Response>"
else
return "<Response><Say>Pinto is not picking up the call, now connecting call to Management</Say><Dial ....></Response>"
end
end

Twilio, How to transfer a in-progress call to another number

How to transfer a in-progress call to another number.The concept that I m using is to use the update method when the call is in in-progress and dial the number that I wanted To connect and It is working but the connection with the first caller is breaking/
Code for the process of transferring call-
1.process for dialing call-
<Response>
<Dial callerId="callerid">
<Number statusCallbackEvent="initiated ringing answered completed" statusCallback="urltohadlestatus">user_number</Number>
</Dial>
</Response>
2. process to process to transfer the call-
I have used the update method to transfer the call.
function update_call1($CallSid, $admin_no) {
$rr = array(
"url" => "trurl?admin_no=".$admin_no,
"method" => "POST"
);
$call = $this->client->calls($CallSid)->update($rr);
return $call->to;
}
and used this TwiML
<Response>
<Dial>admin_number_call_to_be_transfered</Dial>
</Response>
what this does is transfer the call but when admin receives it,It disconnects the call.
And what I need like when jack make call to jenny and now jack want to transfer the call to jhonny and when call is transferred to jhonny, jack shound be disconnected from the call.
Twilio developer evangelist here.
You have two options here. Once the call is transferred away, the other caller will drop if it has nothing else to do. There are two ways you can achieve this.
You can either put the callers in a <Conference>. Then when the caller is transferred the other call remains in the conference room. There is a good tutorial on warm transfers using this technique, which might help.
Alternatively, if the side of the call that is dropping out right now is the one that generated the call from the Twilio REST API you can add more TwiML below the <Dial> verb to have the call continue. For example:
<Response>
<Dial>OTHER_NUMBER</Dial>
<Say loop="0">You are still on the call.</Say>
</Response>
Will just keep saying "You are still on the call" once the other end is transferred away.
You can also achieve this with the action attribute for <Dial>. Using the action attribute means that Twilio will make a webhook request to the URL you specify and use the TwiML from that response to carry on the call.

programmatically set room id in a Twilio conference

Does anyone know the best way to programmatically set the name/id of the conference room in the Twilio noun ?
<Response>
<Say>Joining a conference room</Say>
<Dial>
<Conference>MyRoom</Conference>
</Dial>
</Response>
My system will dole out new conference room ID's, dynamically, to keep the conferences small but I'm not sure how to associate the assigned user's room id in the to twiml app's code...
Ricky from Twilio here. Wanted to add some example code for anyone who may stumble on this question.
You need to return TwiML to give Twilio the instructions of what to do with a call but you can generate that TwiML however you'd like. For example, here is a simple PHP script that returns TwiML that places callers in a random conference room.
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>Joining a conference room</Say>
<Dial>
<Conference>Room<?php echo rand(0,2); ?></Conference>
</Dial>
</Response>

Use Say verb to all Conference participants

I'm setting up a pretty simple conference call system, where the user enters a PIN and is connected to a conference associated with that. I'm also setting it up so they record their name before entering the room.
My plan is to take the recording URL, then get the list of participants and make the REST API call to each caller modifying their call to to the Say "Now entering", then Play the recording url. I think I'm going to have to send them back into the room after that as well, I'm not sure.
I think that modifying each call will take them out of the Conference room, which is not ideal. Is there an easier way to use Say/Play to all members of a conference built into the REST API?
As of July 13th 2018, Twilio now allows you to send a POST request to the Conference (to announce something to the whole conference) or Conference Participant (to announce something to a single caller) resources with an AnnounceUrl property that links to either:
a WAV or MP3 audio file, or
a TwiML document that uses the <Say /> and/or <Play /> verbs.
Along with that property, you can also specify an AnnounceMethod property that lets you specify whether to GET or POST (the default) that URL.
A good place to send the aforementioned POST to play back your recorded name might be in a status callback that's set when you use the <Conference /> verb to put each user into the conference, like so:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference statusCallback="/conference/join-callback"
statusCallbackEvent="join">
{conference ID}
</Conference>
</Dial>
</Response>
The old workaround remains below for posterity.
Someone on the Twilio forums was interested in the very same question, and the answer is currently that there isn't a direct REST API call for that.
What you'll need to do is, when a participant joins the conference, you'll use the REST API to make Twilio dial back in to your application. You can choose how to detect that you're calling into your own conference however you like (for example, comparing the outbound and inbound phone numbers for equality); once you've detected that, you can join that call directly to the conference and use the TwiML <Say /> and <Play /> verbs to play back the introduction for everybody.
It's a little bit convoluted, but this way you won't be removing each participant from the conference (preventing them from hearing each other for a moment) and then rejoining them.
Here's something that should resemble a good end-to-end solution.
First, the user dials in and you go through the standard prompts to get the PIN for the conference room and their name.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/conference/pin" finishOnKey="#">
<Say>Please the conference pin number followed by the pound key.</Say>
</Gather>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Say your name and then press the pound key.</Say>
<Record action="/conference/name" finishOnKey="#" />
</Response>
Now, once you have the user's pin and recording, two things will happen; the response from the post to /conference/name will contain the <Conference> verb, placing the user in the room:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference>{conference ID}</Conference>
</Dial>
</Response>
...and, asynchronous to that, it will use the REST API to initiate a new call back into the conference room.
POST /2010-04-01/Accounts/{AccountSid}/Calls
From = {your conference phone number}
To = {your conference phone number}
SendDigits = wwww{conference PIN}#
Url = /conference/announce?name={name ID}
Now, the next bit gets confusing. Twilio will now be talking to your callback URL for the incoming end of the call, and the URL you specified above for the outgoing end of the call. Your incoming call handler will need to detect that the conference line is calling back into itself and behave differently; it will first need to respond with simple TwiML that allows the outgoing end of the call to enter the pin for the conference room.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/conference/announce-pin" finishOnKey="#" />
</Response>
The SendDigits parameter of the POST will provide the digits that bit of TwiML is expecting. That action should then respond by conferencing in the new call.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Conference>{conference ID}</Conference>
</Dial>
</Response>
The last piece of the puzzle is the TwiML emitted by the URL you specified in the POST. That's the markup that will run once the loopback call is added to the conference.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>/conference/name-recordings/{name ID}</Play>
<Say>has joined the call.</Say>
<Hangup />
</Response>
That markup runs, plays the caller's name and a message into the conference room, and then hangs up.

Resources