Cannot put caller into conference - twilio

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...

Related

Add call id to existing twilio numbers

Our application will make out calls to customers using different Twilio numbers. Here is our sample code:
r.Dial customer_number,
:method => 'POST',
:timeout => '30'
We want to add a caller id/number to all these numbers so customers could always see one number if we call them. Is such option available on Twilio? We purchased a verified phone number which could be used as caller number.
Twilio developer evangelist here.
If you have a verified number that you want to use as the caller ID then you just need to add one more attribute to your TwiML. The callerId attribute lets you specify the caller ID that will appear to the called party when Twilio calls.
You can update your TwiML to:
r.Dial customer_number,
:method => 'POST',
:timeout => '30',
:calledId => "YOUR_VERIFIED_NUMBER"
And your caller ID will be used for all your calls.
Megan from Twilio here.
If I am understanding correctly, it seems like this could be a good case for one of our Copilot features, Sticky Sender where Twilio will maintain a mapping of the To and From numbers.
Otherwise, the OutgoingCallerId instance resource represents a single verified number that may be used as a caller ID when making outgoing calls via the REST API and within the TwiML <Dial> verb. And there are some examples in Ruby there.
Let me know if this helps!
Edit: I stand corrected that the Sticky Sender feature only works with messaging services and not calling.

How to tell if forwarded inboundcalls in Twilio were missed?

I have a twilio app: When someone calls the Twilio number and forwards it to a verified phone number. I'd like to know if that forwarded call was missed.
Is this even possible? Is it possible to do call progress events on forwarded inbound calls via Twiml? If so, what's the syntax?
I work with the devangels at Twilio.
It seems like you might be looking for the 'no-answer' Status parameter as seen here: https://www.twilio.com/docs/api/rest/call#call-status-values
Also looks like you're using PHP so the syntax would be something like this for a loop of calls:
foreach ($client->account->calls->getIterator(0, 50, array(
"Status" => "no-answer"
)) as $call

Twilio Phone Poll Call

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.

Twilio - Get the most recent Conference call

I'm trying to find the fastest way to get a Conference Sid from an ended call's request. Since the Participant is removed from the Conference when the call ends, searching isn't possible (and not implemented in the PHP library anyways). I'm assuming the call left the most recent Conference, since its 'action' parameter is associated with its Dial into the Conference.
How do I get the most recent Conference using the PHP helper library?
Twilio evangelist here.
I don't think there is a way to just get the last conference directly from the API. What you can do is use the helper library to get a list of the conferences.
$client = new Services_Twilio('AC123', '123');
foreach ($client->account->conferences as $conference) {
print $conference->date_created;
}
When you do, each conference should include a DateCreated and a DateUpdated property that you can sort by to find the last one created or updated.
Hope that helps.

Twilio call transfer from in-call

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>

Resources