Twilio, how to get Child Sid from Parent Sid? - twilio

please anybody has any solution regarding this? I have got parent sid from but i want child sid to get call duration. Or is it possible to get child sid separately using other parameter/ independently?

Twilio developer evangelist here.
You can find the child calls from a parent SID by using the Calls list resource and filtering by ParentCallSid.
Something like (with Node.js) this:
client.calls.list({
parentCallSid: parentCallSid
},
calls => console.log(calls);
);
And in PHP
$sid = "your_account_sid";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$calls = $twilio->calls->read(array(
"parentCallSid" => $parentCallSid
));

Related

How to switch an ongoing Twilio phone call to a <Pay> connector

I would like to use the < Pay> connector optionally while in an ongoing phone call. I cannot find out how to do trigger a new resource during an ongoing phone call.
You can modify an "in progress" call by passing new TwiML (XML) to execute which could contain your "<Pay>".
You must provide
the ID of the call you want to modify (the "CallSid" "CAe1644a7eed5088b159577c5802d8be38")
and an URL where Twilio will find the instructions (the "Url" "http://demo.twilio.com/docs/voice.xml")
I don't know what language you're using but in PHP with Twilio's library the code would look someting like this:
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account Sid and Auth Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
$sid = "ACc0966dd96e4d55d26ae72df4d6dc3494";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$call = $twilio->calls("CAe1644a7eed5088b159577c5802d8be38")
->update(array(
"method" => "POST",
"url" => "http://demo.twilio.com/docs/voice.xml"
)
);
print($call->to);
You can read more about this here
(https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress).

How to transfer twilio inbound call between clients

I'm struggling with implementation of transferring inbound call between two clients.
Twilio tutorials are as informative as it possibly can but i just can't get what do i need to do to transfer inbound customer call from one client to another.
This is simplified example of my controller's method that handles inbound call.
public function inbound(): Twiml
{
$this->twiml->dial()->client('publishers');
return $this->twiml;
}
And it works great.
But the trouble comes when an agent press "Forward Call" - somehow the caller gets disconnected from the call and two clients gets connected with each other.
This is a method, that updates current call.
public function redirect(Request $request)
{
$input = $request->all();
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$client = new Client($sid, $token);
$client
->calls($input['CallSid'])
->update(array(
"method" => "POST",
"url" => "https://some-api.ngrok.io/api/connect"
)
);
}
And this is method that returns new TwiML instructions for Twilio
public function connect(): Twiml
{
$this->twiml->dial()->client('collectors');
return $this->twiml;
}
What am I doing wrong? Would appreciate any advises.
Twilio developer evangelist here.
In Twilio calls there are two legs to each call, each between Twilio and the person on the phone/client.
When you are updating the call, you are sending the callSid of the agent's call and then updating their call with the new TwiML, thus connecting your two agents.
Instead, since the call is initiated by the incoming caller, you need to find the parent call SID. You can do that by fetching your current call from the API and using the call's parent_call_sid property to update the original incoming call.
Try something like this:
public function redirect(Request $request)
{
$input = $request->all();
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$client = new Client($sid, $token);
$call = $client
->calls($input['CallSid'])
->fetch()
$client
->calls($call->parentCallSid)
->update(array(
"method" => "POST",
"url" => "https://some-api.ngrok.io/api/connect"
)
);
}

How to record-from-answer-dual with Twilio's object oriented interface?

I understand how to enable the 'record-from-answer-dual' with the XML style command set, but I'm not finding any way to accomplish the same thing with the more object-oriented style code, such as:
<?php
require_once 'twilio-php-master/Twilio/autoload.php';
$response = new Twilio\Twiml();
$sayMsg = 'Attention! Attention! The network operations
center has opened a ticket concerning an ATMS failure in the Eastern
region. The ticket number is ECHO,1,5,7,4. I repeat, the ticket number is
ECHO,1,5,7,4. Thank you.';
$response->record();
$response->say($sayMsg, array('voice' => 'alice'));
$response->hangup();
echo $response;
I've tried adding it to the new line, and the record line as an array-style entry, similar to enabling the Alice voice. No dice.
I want to record the entire call, from answer, including the message spoken by Twilio.
Thanks for any information anyone can provide!
Twilio developer evangelist here.
<Record> is used to record messages from a call, not to record the TwiML that follows. It's more useful if you are building a messaging or voicemail system for voice.
Given that your message sounds like some kind of announcement, I am guessing that you are generating this call from the REST API. In that case, you can use the Record parameter when you place the call and the entire call will be recorded. In PHP, that would be something like this:
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/console
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);
$call = $client->calls->create(
$to, $from,
array(
"url" => $url,
"record" => true
)
);
Check out the documentation on the parameters you can use when making a call, including Record here.
Let me know if that helps at all.
Update from Jeffrey's comment
This is the Perl version, using the unofficial Twilio Perl module:
use WWW::Twilio::API;
my ($twilaccountsid, $twilauthtoken, $fromnum, $tonum, $twiml_uri) = #_;
my $twilio = WWW::Twilio::API->new(AccountSid => $twilaccountsid, AuthToken => $twilauthtoken);
my $response = $twilio->POST( 'Calls', From => $fromnum, To => $tonum, Record => 'true', Url => $twiml_uri);
return $response->{content};

Twilio inbound call status callback

I know I can set the status callback url when make a outbound call.
But how can I set a status callback url for an inbound call?
Twilio developer evangelist here.
You can either set your inbound call webhook in your Twilio Console by updating your numbers. Or you can set it via the REST API by POSTing an update to your number with the VoiceUrl parameter set to your new URL.
That would look like this in PHP:
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);
$number = $client->account->incoming_phone_numbers->get("your_phone_number_sid");
$number->update(array(
"VoiceUrl" => "http://example.com/voice"
));
Let me know if that helps at all.

Twilio Queue Sid

I am using the following code that I got from the twilio website. I need to get the QueueSid of my queue named "Sales". How do I go about doing this? If there is documentation for this subject please point me there as well. Thanks in advance!
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$accountSid = "ACYYYYYYYYYY";
$authToken = "XXXXXXXXX";
$client = new Services_Twilio($accountSid,$authToken);
// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$member = $client->account->queues->get('QU5ef8732a3c49700934481addd5ce1659')->members->get("Front");
$member->update(array(
"Url" => "https://dl.dropboxusercontent.com/u/11489766/learn/voice.xml",
"Method" => "POST"
));
echo $member->wait_time;
Twilio developer evangelist here.
You can search for all of your queues using the Queues list resource. Then you will want to filter by the Friendly name to get your queue. Try something like this:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$accountSid = "ACYYYYYYYYYY";
$authToken = "XXXXXXXXX";
$client = new Services_Twilio($accountSid, $authToken);
foreach($client->account->queues as $queue){
if ($queue->friendly_name == "Sales"){
$foundQueue = $queue;
break;
}
}
echo $foundQueue;

Resources