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.
Related
I need to save the call recording details including the audio file to database while making a call.
This is my twiML file.
<Response>
<Dial record="record-from-ringing-dual" recordingStatusCallback="https://example.com/record_data.php" action="https://example.com/test.php" callerId="xxxxxxxxxx">
xxxxxxxxxx
</Dial>
</Response>
What should I do in record_data.php file to save the recorded details to the database?
Can anyone help me on this? Thanks in advance.
Twilio developer evangelist here.
When you receive the recordingStatusCallback webhook, Twilio will send the following parameters in the body of the request.
AccountSid The unique identifier of the Account responsible for this recording.
CallSid A unique identifier for the call associated with the recording. This will always refer to the parent leg of a two leg call.
RecordingSid The unique identifier for the recording.
RecordingUrl The URL of the recorded audio.
RecordingStatus The status of the recording. Possible values are: completed.
RecordingDuration The length of the recording, in seconds.
RecordingChannels The number of channels in the final recording file as an integer. Possible values are 1, 2.
RecordingSource The type of call that created this recording. For recordings initiated when record is set on <Dial>, DialVerb is returned.
The RecordingUrl is where you can download the recording from to store on your own server.
Let me know if that helps.
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.
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.
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!
I have a question about Twilio's call forwarding concept.
I want to create an application that lets users forward their existing numbers to Twilio, which processes the necessary information, and forwards the call back to the user.
However, when I try to implement this, an infinite loop happens: The call is forwarded to Twilio, which forwards the call back to the user, which forwards the call to twilio...
How would I implement this on the Twilio side, since it is difficult to implement any code on the user side?
Here is my code on Twilio that forwards the call back to the user.
<?php
header("content-type: text/xml");
?>
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Response>
<Say>Hello User</Say>
<Dial>+1973XXXXXXX</Dial>
</Response>
This is tricky. How are users forwarding their existing numbers to Twilio?
The problem is that you want a rule for your cellphone like, "Forward all calls from my cellphone to my Twilio number, unless they are coming back to my cellphone from Twilio." I'm not sure if the call forwarding mechanism for your existing numbers is that sophisticated.
On the Twilio side, you could try returning different TwiML based on whether you've "seen" the call before (is it being forwarded for the first time, or the second time)? But you would have to forward the call to a third number, to avoid the forwarding problem you are already running into.
It is not possible to forward calls to a Twilio number and have that number call you back if you've set up call forwarding on your phone. Conditional call forwarding can only be used for unanswered or busy calls, and for some providers, certain numbers. However, AT&T and Verizon do not allow "forward all numbers but one" for call forwarding.
you are working with twilio call it is with the best solution that we have:
"But you would have to forward the call to a third number, to avoid the forwarding problem you are already running into."