Twilio - How to dial third party number and add him to conference? - php

I am facing a small problem while using Twilio conference.
My API gets incoming call and puts caller to new and empty conference room:
<Response>
<Dial>
<Conference waitUrl="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient">Conf 1</Conference>
</Dial>
</Response>
So I got caller waiting in an empty conference room and listening music.
I want to dial some other number and to add it to this confrence room.
That number is non-twilio.
How can I do this?

You could use the Twilio REST API to make an outbound call, and direct that call into your conference room. In PHP this can be done like this:
(This is from the twilio-php helper library)
require('/path/to/twilio-php/Services/Twilio.php');
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create(
'some-twilio-number', // From a valid Twilio number
'other-number-to-call', // Number to call
'http://example.com/some_twiml'
);
The URL you use here should serve TwiML that puts the caller into the same room as your original call (exactly as you have in your question). In effect, one person called you, then you called the other person and put them into the same room.
(In the interests of full disclosure, I worked for Twilio.)

Related

Outgoing Dial Into Conference From Customer's Number

I am trying to have all my incoming calls automatically go to conference. This part can be achieved using:
<Response>
<Dial>
<Conference>Room <?php echo($_REQUEST['From']);?></Conference>
</Dial>
</Response>
This way, each caller goes into their own separate conference room. The part I can't figure out how to do is the outbound call from that point. I need to make a SIP call to my PBX using the customer's caller id so an agent can answer it. When they answer, they should be sent to the same conference room.
I found this for making outbound calls into a conference. However, I want the outbound call to the agent to use the caller id of the customer. This way, the agent can see the customer's phone number.
The main reason I want to use a conference and not a direct dial is because I want to make it possible for supervisors to call into an active call without interrupting the call between the agent and customer.
Twilio evangelist here.
I believe that when making SIP calls, the From parameter will take any alphanumeric string so you can just provide the customers caller ID as the From value:
$call = $client->account->calls->create($_REQUEST['From'], "sip:agent#example.com", "http://www.example.com/conference.xml", array());
echo $call->sid;
Hope that helps.

Twilio IVR Database Integration Two Inputs?

I have played around with database integration on Twilio, but how would I be able to ask for two inputs such as tracking number and password, and then for a status to be read if both are correct?
My main aim here is to protect our clients who need to get updates on their cases so that others cannot just randomly press a load of numbers and inadvertently get someone's update messages.
Do you have any coding example?
I've been adapting their PHP examples which are given in their How-to guides.
Thank you very much in advance for your help,
Dan
Twilio evangelist here.
So the pattern you can use in this scenario is basically something like this:
An inbound call causes Twilio to request the URL you have specified for your Voice Request URL. That URL returns TwiML.
https://www.twilio.com/docs/api/twiml
Maybe the <Say> verb telling Twilio to prompt the user for the first input (lets say tracking number) and the <Gather> verb to listen for the caller to enter tones. As part of the Gather verb you need to include the action parameter which tells Twilio what URL to request once the Gather completes.
<Response>
<Gather action="/gather-tracking-number.php">
<Say>Please enter your tracking number</Say>
<Gather>
</Response>
Once the user enters their tracking number and the Gather completes, Twilio will request the URL specified in the Gather verbs action parameter. As part of the request Twilio will pass you the digits the caller entered. Your app needs to persist those somehow. Database, session, whatever.
This URL also needs to return TwiML with the next prompt in it.
<Response>
<Gather action="/gather-passcode.php">
<Say>Please enter your customer pass code</Say>
</Gather>
</Response>
Also, as a cheap way of maintaining state across the request/responses, you can use the querystring. For example to pass the tracking number to the next page in your workflow you can throw it in the URL like this:
<Response>
<Gather action="/gather-passcode.php?trackingnumber=" . _REQUEST["Digits"]>
<Say>Please enter your customer pass code</Say>
</Gather>
</Response>
Hope that helps.

Twilio Caller ID set for outgoing Calls

In my web application I have used Twilio api for making calls,
params = {"PhoneNumber": 'xxxx123'};
params = {"callerId": 'aaaa987'};
params["PhoneNumber"] = 'xxxx123';
params["callerId"] = 'aaaa987';
Twilio.Device.connect(params);
But in receiver phone/twilio call logs did not get from number aaaa987, it is some other number like xyz567 every time.
How can I set from number for Twilio outgoing calls ?
Twilio evangelist here.
So to make sure I understand your question:
You want to use the Twilio Client for JavaScript to make a phone call from a browser to a regular PSTN phone
You want to have the Client pass parameters to Twilio to set the phone number and caller ID of the call to the PSTN phone
Assuming I understand your question correctly, it looks like you are on the right track, passing an array of values into the Connect function. Now, what Twilio will do with that array is we will take each item in the array and convert it into a parameter that we send with the HTTP request we make to the Voice Request URL you have configured for your TwiML app.
Based on the tags you set for your question, it looks like you are using PHP? If that's correct then you would just set the Voice URL to a PHP page that you have hosted on the internet.
That PHP page can use the $_REQUEST object to access the HTTP parameters Twilio is including in its request and use them to dynamically generate TwiML. In your case since you want to have Twilio dial out to another phone number, you are going to need to generate TwiML containing the <Dial> verb.
Here is a sample that shows how you can use the Twilio PHP Helper library to generate TwiML:
$response = new Services_Twilio_Twiml();
$response->dial($_REQUEST['PhoneNumber'], array(
'callerId' => $_REQUEST['callerId']
));
print $response;
In this case I am grabbing the PhoneNumber and callerId parameters from the HTTP request made by Twilio and injecting them into the dial method. This would result in the helper library generating some TwiML that looks like this:
<Response>
<Dial callerId="aaaa987">xxxx123</Dial>
</Response>
Your PHP page returns the generated TwiML to Twilio in response to Twilios HTTP request. Twilio then executes the TwiML making cool things happen, like a phone call to the number you've specified.
If you want a bit more of a step-by-step walk-through for Twilio Client for JavaScript, I'd suggest talking a look at the Twilio Client for JavaScript Quickstart. Its available in PHP and will take you through using Client for both inbound and outbound phone calls, including setting up a server side application in PHP to generate and return TwiML and also passing parameters into that PHP file.
Hope that helps.

Unable to get Twilio "call-recording" url

I am developing a Twilio based application for a online campaign management system, and for each campaign there will be a twilio number and a target number. Whenever somebody will call to a twilio number (assigned for a particular campaign), it will be forwarded to the particular target number. There are also two Check-box field (one for Call-Whisper and another for Call-Recording) for each campaign.
I got a reference for Call-Whisper and Call-Recording from :
Call Screening and Recording
But unable to understand how to get the call-recording url from this tutorial.
Kindly suggest.
Twilio evangelist here.
You will need to add an action attribute to the <Dial> tag. This attribute takes a URL as a parameter, and once the call completes Twilio will make a request to that URL. That request will contain a paramater called RecordingUrl, which will have the URL of the recorded file. So configure the <Dial action=""> to some URL on your server, and then you'll get the request so you can download/store the recording.
You can see more about this in the TwiML documentation for the Dial verb.
Hope this helps!

Twilio's receive sms and send a call..

I am trying to do this but it is not working....I was trying to text to my sandbox sms at Twilio so once twilio receive's that sms it would execute a script that should dial a number. This is not working as I get no error so I am assuming the only place where the Dial verb works is in the phone section of Twilio and not the sms part. Any help?
I want the sms to be a trigger that starts up a script which uses Twilio's dial verb to call people and give a message then hang.
The <Dial> verb is a top level one, so it should be a child of <Response>, i.e., not <Sms>. That said, Twilio's documentation strongly implies putting <Dial> in the <Response> for an SMS callback won't work; <Dial> is supposed to connect a current caller to another party. So, if this isn't working, you'll hit their REST API to initiate the call; you can POST the TwiML script with the message to speak and the instruction to then hang up.
Note this contradicts my first reply to your comment on your other Twilio question, my apologies for that.

Categories