How can I find the caller name with Twilio? - twilio

I want to get the caller name on either request url or status callback url. I am using C# code for purchasing the numbers.
option parameter is as below:-
options.VoiceUrl = ConfigurationManager.AppSettings["ServerUrl"] + "/Home/RaiseCallEvent";
options.StatusCallback = ConfigurationManager.AppSettings["ServerUrl"] + "/Home/EndCallEvent";
options.PhoneNumber = Number.PhoneNumber;
options.VoiceMethod = "GET";
options.VoiceCallerIdLookup = true; //for getting the caller name
options.StatusCallbackMethod = "GET";
IncomingPhoneNumber = TwilioClient.AddIncomingPhoneNumber(options);
I have done the VoiceCallerIdLookup as true now when twilio hits my voice url RaiseCallEvent or status call back url EndCallEvent then in which parameter I can get the caller name?

Twilio evangelist here.
If you've enabled VoiceCallerIdLookup on your IncomingPhoneNumber, then when Twilio makes its HTTP request to your Voice Request URL, it will include a parameter called CallerName. A complete list of all the parameters we send as part of the Voice Request is here:
https://www.twilio.com/docs/api/twiml/twilio_request
Hope that helps.

Related

Conf call: Wait for first person to respond, then connect second person

Basic case: System will call person A. If person A picks up the phone it will call person B and the 2 will be connected.
I read several answers here such as https://stackoverflow.com/a/20976996/1907888 but it's still unclear.
Would the following work? It would call PERSON_A if person responds it will connect to conference then call PERSON_B and connect to same conference? Do I need to start the conference first?
$response = new VoiceResponse();
$dial = $response->dial('PERSON_A');
if($dial->conference('Room 1234')) {
$dial = $response->dial('PERSON_B');
$dial->conference('Room 1234');
}
Twilio developer evangelist here.
When you control calls with Twilio there are two mechanisms by which it works. There is the Twilio REST API which your application can use to make things happen, like start or change a call. Then there are webhooks, which are HTTP requests that Twilio makes to your application when things change in a call, like someone dialling your Twilio number, entering data on the phone, or an person answering an outbound call. You respond to webhooks with TwiML, a subset of XML, with instructions for what to do with the call next.
In this case, you want to place a call to person A to start with. For this, you will need the REST API to make that call. When person A answers the phone, Twilio will then make a webhook request to your application to find out what to do next. It is at this point that you can both call person B, again using the REST API, and place person A into a conference call, by responding with TwiML.
So, your initial outbound REST API call should look a bit like this:
use Twilio\Rest\Client;
// Find your Account Sid and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$call = $twilio->calls
->create($personANumber, // to
$yourTwilioNumber, // from
["url" => "http://example.com/conference.php"]
);
The URL you send when you place the call will be where Twilio sends the webhook request. So, in response to example.com/conference.php in this case, you will need to dial another person and respond with TwiML to direct person A into the conference call.
This time, instead of sending a URL, you can actually send TwiML in the REST API response. Something like this:
use Twilio\Rest\Client;
use Twilio\TwiML\VoiceResponse;
// Find your Account Sid and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$twiml = new VoiceResponse();
$dial = $twiml->dial();
$dial->conference("Conference Name");
$call = $twilio->calls
->create($personBNumber, // to
$yourTwilioNumber, // from
["twiml" => $twiml->toString()]
);
echo $twiml.toString();
In this case, I have used the same TwiML for both legs of the call, because they are both entering the same conference. You could respond with different TwiML based on what's happening.
Let me know if that helps at all.

How to integrate audio call(User to User) using twilio API?

I want to integrate user to user audio call feature using Twilio API, is it possible in Twilio? if yes can you please provide a tutorial.
Here I have added the code:
1. For get token from the Twilio
$.post(url, function(data) {
// Set up the Twilio Client Device with the token
Twilio.Device.setup(data.token);
});
and it returns the token using function
public function newToken(Request $request, ClientToken $clientToken)
{
$forPage = $request->input('forPage');
$twilio = config('services.twilio');
$applicationSid = $twilio['applicationSid'];
$clientToken->allowClientOutgoing($applicationSid);
if ($forPage === route('dashboard', [], false)) {
$clientToken->allowClientIncoming('support_agent');
} else {
$clientToken->allowClientIncoming('customer');
}
$token = $clientToken->generateToken();
return response()->json(['token' => $token]);
}
When I make a call following javascript function start
function callCustomer(phoneNumber) {
updateCallStatus("Calling " + phoneNumber + "...");
var params = {"phoneNumber": phoneNumber};
Twilio.Device.connect(params);
}
and then browser ask for the enable microphone and after allowing it plays the small audio say's that "Application error occurred, Good bye!".
Twilio voice call please refer the following documentation step by step
QuickStartDemo
Twilio developer evangelist here.
The TwiML connects the outgoing call to the other user. When you set up the TwiML Application for outgoing calls you need to set a voice URL. When you make the call using Twilio.Device.connect then Twilio Client will connect to Twilio, Twilio will then make an HTTP request to the voice URL of your TwiML app, passing along the parameters that you send, to find out what to do with the call.
You are passing in a phoneNumber parameter, so that will be passed to your application. You've tagged this question with PHP, so here's an example (using the Twilio PHP library) of what you could do to dial onto the phone number that you are passing.
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;
$phoneNumber = $_REQUEST['phoneNumber'];
$response = new Twiml();
$dial = $response->dial();
$dial->number($phoneNumber);
echo $response;
Check out the documentation on Twilio Client for more details on how this works.

Status call back URL in twilio

I want to get the status of my call while using twilio.
I am configuring a status call back url for the same which is accepting a Post verb. But not sure What should the method of the REST webservices have in its POST method? If Twilio is posting back the status, then what should the POST method of the webservices do? Not able to get a idea on this, please help..
I am programming it in .net
Twilio developer evangelist here.
The status callback requests will send all the regular parameters that any Twilio Voice webhook sends as well as a few extra parameters that you can find in the documentation here.
Finally I found a solution how to get back status from twilio. Just design an Http Handler and use the context property to get back the parameters. The handler should look like this:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim callsid = context.Request.Params.Get("CallSid")
Dim FromNumber = context.Request.Params.Get("From")
Dim ToNumber = context.Request.Params.Get("To")
Dim callStatus = context.Request.Params.Get("CallStatus")
' ...
End Sub

How to make call through Twilio where two people will have live conversation?

I am trying to setup a call between two people and I am able to make a call but the person who pick up the call can listen pre-recorded voice mail. I want to have live conversation between these two people. I am not getting what should be the URL and how can I set it up.
My Sample PHP Code is -
require_once "application/helpers/Services/twilio-php-master/Twilio/autoload.php";
use Twilio\Rest\Client;
// Step 2: Set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "Axxxxxxxxxxxxxxxxxxxxxc0";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
// Step 3: Instantiate a new Twilio Rest Client
$client = new Client($AccountSid, $AuthToken);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
// Step 4: Change the 'To' number below to whatever number you'd like
// to call.
"+91my_number",
//$_POST['to'],
// Step 5: Change the 'From' number below to be a valid Twilio number
// that you've purchased or verified with Twilio.
"+1_twilioverified_number",
// Step 6: Set the URL Twilio will request when the call is answered.
array("url" => "http://demo.twilio.com/welcome/voice/")
);
echo "Started call: " . $call->sid;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
Is there anyone who can help me with this.
Thank you in advance. Awaiting for reply.
Twilio developer evangelist here.
Currently your code is working fine, the thing you need to change is the URL that is listed as "Step 6" in the comments. Currently that URL points to some TwiML that reads out a message.
Instead of reading that message, you will need to provide a URL that returns some TwiML that <Dial>s another <Number>. You see, when the first part of the call connects, Twilio makes an HTTP POST request to that URL to get the instructions for what to do next.
This URL needs to be available online for Twilio to make the HTTP request to. You can either deploy this TwiML to a server of yours, use a TwiML Bin from the Twilio console or test it out using ngrok on your local development machine.
The TwiML you want should look a bit like this:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Number>YOUR_NUMBER_HERE</Number>
</Dial>
</Response>
Let me know if that helps at all.

Twilio Call Issue from iOS App to Phone

I am trying to make call from my app to phone, My app executes a POST Request in which i am passing following parameters.
CallUrl = “https://api.twilio.com/2010-04- 01/Accounts/ACXXXXXXXXXXXXXXXXXXX/Calls.json”
From = “+MyTwilioNumber”
To = “+9179XXXXXXXX”
Url = “myserveraddress.com/data.xml”
AuthToken = “cdXXXXXXXXXXXXXXXXX”
AccountSid = “ACXXXXXXXXXXXXXXXX”
Url Returns-
<Response>
<Dial>
<Number>+9179XXXXXXXX</Number>
</Dial>
</Response>
Now what happens is that when call is received, I hear the number you are trying to call is busy.
Can anybody help me what’s going wrong ???
Also how can I get call status in my App like call is ringing, answered, disconnected ???
Twilio developer evangelist here.
It sounds like you are making the call correctly and just dialling a busy number. If that's not the case, then let me know and I'll see if I can help further.
As for getting events for when the call is ringing, answered, disconnected etc, you need to check out the statusCallback parameter. You pass a URL to get webhooks when the statuses you want to hear about (chosen via the statusCallbackEvent parameter happen.
Let me know if that helps at all.

Resources