I'll try to explain my requirement. I have 3 entities:
Controller
Caller-Recipient (Verified Number)
Recipient
The end goal is to have Recipient receive a call from Caller-Recipient as caller-id, but Caller-Recipient should not be the one that initiates it. The Controller will initiate a call between Caller-Recipient and Recipient. Here's how I intend to do it.
The Controller will call the Twilio-Number.
The TwiML will dial Caller-Recipient.
Once Caller-Recipient receives the call, it'll dial Recipient and connect to the same call.
The call between Caller-Recipient and Recipient convenes.
How can I achieve this?
You can do this using the /Calls Resource, as described below (Make an outbound call to a phone number - code example), initiating the call first to the Caller-Recipient. Once they answer, Twilio will reach out to the URL associated to this API call for TwiML which should return a Dial``Number to the Recipient. You can set the callerId to a Twilio number or Verified Caller ID.
Making Calls
TwiML Dial Verb
TwiML Number Noun
TwiML for Programmable Voice
Related
I am having alot of trouble wrapping my brain around how to transfer an inbound call using Twilio. The idea is:
Call Comes In
Call is Connected to A Receptionist
Receptionist Greets and Dials Extension - Presses #.
Caller is transferred to the specified # / sip device.
I have implemented a portion of this flow. I used conference tag on the initial call in to force the caller into a room with hold music, and as that call comes in I dial the receptionist and then have the receptionist join the conference. This works perfectly.
What I cant figure out is how to grab the input from the receptionists phone and then act on it. For example, if the receptionist pushes #200* (or something to that effect), I want extension 200 dialed, and the caller in the conference put back on hold until the transferred party answers (all of which should be easy once I can grab the input and act upon it).
Any help on this is appreciated.
Thanks.
Twilio developer evangelist here.
Thanks for the extra detail in the comments. Your receptionist is dialed into a conference to deal with the incoming call using startConferenceOnEnter to stop the hold music and make the connection. This is a good start.
You say you also have endConferenceOnExit for the receptionist. I would remove that because in order to achieve this we are going to want to remove the receptionist from the conference and leave the caller in it while we sort out the transfer.
So, instead you're going to want to add hangupOnStar to your receptionist's TwiML. When the receptionist hits * the call with either request the action attribute for the original <Dial> or, if that is not present, will continue to the next TwiML verb after <Dial>. Either way, this is where you want to include a <Gather input="dtmf">. This will start Twilio listening for keypad tones.
Your receptionist can then dial the extension to connect to and press # to finish (the default finishOnKey. This will send a webhook to the action attribute of the <Gather> with the Digits in the body of the request. You can then pick those Digits out and initiate a new call to the user with that extension. When that call connects you can then drop them into the original conference.
So, that should look a bit like:
Receptionist TwiML:
<Response>
<Dial hangupOnStar="true">
<Conference startConferenceOnEnter="true" endConferenceOnExit="false">CALLERS_CONFERENCE_ID</Conference>
</Dial>
<Gather action="/transfer" input="dtmf" finishOnKey="#">
<Say>Please enter the extension you want to dial</Say>
</Gather>
</Response>
Then the /transfer action should, in pseudo code, do something like:
/transfer
def transfer
extension = params["Digits"]
twilioClient.calls.create( to: getNumberFromExtension(extension), from: TWILIO_NUMBER, url: "https://example.com/connect" )
return "<Response><Hangup/></Response>" # this hangs up the receptionist
end
Finally, the /connect endpoint referenced in the new call above should return TwiML to drop the new caller into the conference:
<Response>
<Dial>
<Conference startConferenceOnEnter="true" endConferenceOnExit="true">CALLERS_CONFERENCE_ID</Conference>
</Dial>
</Response>
You could even make the /connect endpoint the same as the original receptionist TwiML, which would allow the next person on the call to also transfer out by pressing * and dialling another extension.
Let me know if this helps at all.
Aim: Put incoming calls into conference.
What I would like to achieve is:
generate call signal to all available agents
put an incoming call into conference
when agent picks up, its connected to the conference
On an incoming voice call I have this code:
$response = new Twiml();
$dial = $response->dial([
'callerId' => $input['From'],
]);
$dial->client('testagent',
[
'url' => "/twilio/conference/create"
]);
How do I expand this twiml with an instruction to put an incoming call to conference, right after calls to agents are created?
Currently agent successfully resides in conference, while incoming call is still ringing...
Twilio Developer Evangelist here.
Couple of bits to understand about how the TwiML you're generating above works:
The <Dial> verb tells Twilio hold on to the call it just answered while we place an outbound call (to one instance of Client in your case). If that outbound call is answered, we will directly bridge those two calls together (no conference in between).
The TwiML returned by the url parameter you've included in the <Client> noun will get executed only on outbound leg we dialed and before Twilio directly bridges the two calls together. There is a limited subset of TwiML that you can return from that URL and unfortunately <Dial> isn't on of them: https://www.twilio.com/docs/glossary/call-whisper
Its possible to use a technique called a simuldial to have Twilio dial out to multiple agents: https://www.twilio.com/docs/api/twiml/client#examples-2. In this scenario whichever agent answers the call first will get bridged to the original incoming call. There is no conference involved in that scenario. Its a direct bridge but the direct bridge makes it pretty hard to do things like put a call on hold, transfer it to another party or add a third person. If you don't care about any of those scenarios then that might be an option for you.
If you do care about any of the above, I highly recommend using TaskRouter.
Hope that helps.
I managed to do this with an additional Twilio REST call and a route for agents
Added 'action' which executes after agent picks up a call and updates its leg:
$response = new Twiml();
$dial = $response->dial([
'callerId' => $input['From'],
'action' => '/twilio/conference/join',
]);
$dial->client('testagent',
[
'url' => "/twilio/conference/create"
]);
when agent route "/twilio/conference/create" is executed before sending dummy Twiml, I execute this Twilio Rest call:
$call = $client->account->calls($input['CallSid'])->fetch();
$call->update([
"url" => "/twilio/conference/join"
]);
This puts agent leg into conference, disconnects the caller which executes 'action' route on behalf of customer
I would really like to know why this couldnt be done with Twiml response on agent route...
I am looking into the possibility to implement call tracking with Twilio.
What I would need is that right at the start of an incoming call I would like to be able to change the destination number for that call.
How is this achievable with Twilio via API?
Reading the API docs I found the that there is a real-time call and message routing feature (here) and followed the example (here) but it's not what I would like to achieve.
Thanks ahead for any suggestion and help!
--Steve
Twilio developer evangelist here.
You absolutely can dynamically change the destination number for calls on Twilio. When you are forwarding calls you use the <Dial> noun in TwiML like so:
<Response>
<Dial>YOUR_NUMBER_HERE</Dial>
</Response>
However, if you serve your TwiML dynamically you can return whatever number in the <Dial> tag that you want, based on whatever conditions you want. For example in Ruby using Sinatra:
post "/voice" do
if params["From"] === SOME_SPECIAL_NUMBER
number = FORWARDING_NUMBER_1
else
number = FORWARDING_NUMBER_2
end
"<Response>
<Dial>#{number}</Dial>
</Response>"
end
Let me know if this helps at all.
we have integrated Phone Poll in our Website, But when originating the call to a number, by default call made 3 times, but we want to control the call from default 3 times to either only one or two or more than 3 times. how is it possible?
Twilio evangelist here.
It sounds like you are making three calls to your customer all at the same time. I'm not sure why you are doing that, but I suspect what you want to do instead is wait for the first call to complete, then if needed make a second and possibly third call.
There are a couple ways to know if the call completes or not. When you make your first outbound call, you can include the StatusCallback parameter in your call to to the REST API. The StatusCallback parameter lets you specify a URL that Twilio will make an HTTP request to when the call ends.
To do this in PHP, you can use the options parameter in the create method. This parameter takes an array that lets you add extra parameters to your request:
call = $client->account->calls->create(
'9991231234', // From this number
'8881231234', // Call this number
'http://example.com/call.xml',
array(
'StatusCallback' => 'http://example.com/callback',
'StatusCallbackMethod' => 'GET'
)
);
When Twilio makes its request to the URl you've specified as the StatusCallback, you can check the CallStatus parameter to see why the call ended. In the case of no-answer your application can queue up another call to the customer.
$callstatus = $_REQUEST["CallStatus"];
if (
$callstatus == "no-answer" ||
$callstatus == "busy" ||
$callstatus == "failed") {
//caller never answered, line was busy or call failed, so do something about that
}
If the caller answers, then you are going to use the <Gather> verb to let the customer enter in 1, or some other value. The Gather verb includes a parameter named action that lets you specify a URL that Twilio should request once the user has entered a digit. You can check the Digits parameter in this request to see if they pressed 1 or some other number. If they did not press 1, you can either re-prompt the customer to try entering the digits again or hangup and have your application queue up another call to the customer.
Hope that helps.
I'm not finding a definite answer from the Twilio docs on this. I'm trying to build a phone system that can place the other party on hold while in-call and only from the phone. Example: There are two agents working with me out in the field. I get a call on my mobile (away from a computer) and find that the other agent would need to speak to the person I'm on the phone with. I would like to be able to press something into the phone that would either directly transfer the other person to the agent, or place them in a queue. I could then call the other agent and he could retrieve the person from the queue. All of which would need to happen just from our phones.
I've found some documentation on this, but it seems to all require me to be at a computer, which wont be possible.
Is this even possible with Twilio?
Twilio evangelist here.
This sounds like it might be a good place to use some <Conference>s.
Lets define the actors in your scenario: Agent1, Agent2, Field.
Lets say that Field calls Agent1. Instead of connecting the two directly with a <Dial> you could <Dial> Field into a <Conference> (lets call it ConferenceA), then use the REST API to initiate an outbound call to Agent1. When they answer <Dial> them into the same <Conference>. The system will need to grab the CallSid's of both Agent1 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.
Using <Conference> in this scenario gives you more flexibility to manipulate each leg of the call independent of the other than you would have if you use <Dial> to connect Field and Agent1.
So now Agent2 calls Field. Agent2 would go through the same process, just in reverse. Agent2 would get dialed into a <Conference> (lets call it ConferenceB) and your system would use the REST API to call Field. When Field answers they get <Dial>ed into the same conference as Agent2. Again, the system will need to grab the CallSid's of both Agent2 and Field, as well as the Sid of the <Conference>, persist them in some type of storage to use later.
Now, Field needs a way to tell the system to connect Agent2 with Agent1. To do that you can utilize the <Dial>s hangupOnStar attribute in the TwiML you hand Twilio when you dial Field into the ConferenceB. The <Dial> verb would look something like:
<Dial hangupOnStar="true" action="[process_hangup_url]">
<Conference>ConferenceB</Conference>
</Dial>
hangupOnStar tells Twilio to disconnect the caller (Field) from whoever they <Dial>ed (the conference), but still makes a request to the URL defined in the <Dial> verbs action attribute. That is important because when Field needs to tell the system to redirect Agent2 into the ConferenceA with Agent1, and the request to the URL in s action attribute gives the system the opportunity to prompt Field to see if thats what he wants to do. So you might have Twilio execute some TwiML like this:
<Response>
<Gather action=[gather_handler]>
<Say>Press 1 to connect this caller to another<Say>
</Gather>
</Response>
If Field presses one, the system (who knows all of the CallSids for all of the parties involved here, and the conference sids), can use the REST API to redirect Agent2 out of the ConferenceB and into ConferenceA.
It makes for a bit more complicated of a system, but it should work for you.
Hope that helps
Redirect an incoming call to new url:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);
// Get an object from its sid. If you do not have a sid,
$call = $client
->calls("CAe1644a7eed5088b159577c5802d8be38")
->update(
array(
"url" => "your_url/test.xml",
"method" => "POST"
)
);
echo $call->to;
XML Code:
---------
<Response>
<Redirect method="POST">url goes here</Redirect>
</Response>