Twilio Phone Poll Call - twilio

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.

Related

Twilio statusCallback: answer call or not

I use Twilio to make phone calls during which the user can reply by pressing key. My problem is that I want to manage 4 cases:
1) the user answer and press 1
2) the user answer and press another key than 1
3) the user answer and press no key
4) the user don't answer
For cases 1, 2 and 3, everything is OK:
I have a "Gather" in my XML, with an "action" URL, a time-out and a actionOnEmptyResult="true"
For managing case 4, I use a statusCallback url, with 'statusCallbackEvent' => ['answered','completed']
What I notice in my Log is that I receive exactly the same data in case 3 (user answer but press nothing) and in case 4 (user don't answer the call).
Maybe this came from the fact after a few "rings" the call fall in voice-box, fooling Twilio which believe it's an "answer" event.
In my LOG I see (case 3 or 4) this 3 events:
Call to my statusCallback with CallStatus = in-progress
Call to my return hook with msg = Gather End and Digits = ""
Call to my statusCallback with CallStatus = completed
So my question is: how can I know the difference between "answer the call and press nothing" and "don't answer the call" ?
Edit: if I refuse the call, result is the same. So I get the same "hook" and statusCallback call, with same data if the user pick-up and give no reply, if he doesn't pick up or if he refuses the call...
Twilio developer evangelist here.
You may want to handle the "doesn't answer the call" slightly differently. If the user doesn't answer, your action URL is still called but the parameter CallStatus sent to the webhook will be no-answer. In this case you can <Hangup/> the call and mark it as not answered.
There is one other issue. If the call is answered by a voicemail then your call will attempt to continue as normal. You can put this down as a call that was answered but didn't enter anything, or you can try using Twilio's answer machine detection to detect whether a human or machine answered the call. If it's a human you continue as usual, but if a machine answers you can also mark it as not answered and <Hangup/> the call.
Let me know if this helps at all.

Need help understanding how sending a redirect instruction in Twilio taskrouter works using Twilio Functions

I am trying to use the redirect instruction to take the customer and worker into a conference call in that is of fixed length (using timeLimit) but is variable in the sense that the timeLimit is determined by calling another function.
I am having issues understanding the documentation regarding this instruction. I know I must pass a call_sid and a url, but is the call sid the sid of the customers call to my number or the conference call I will redirect to and if it is the customer's call_sid how do I get it.
Also with the twiml url is this what I use to redirect the customer or worker to the call?
And where in this step would I create the conference call?
As you can see I'm lost regarding the API and would appreciate any guidance on where to look.
EDIT CODE:
exports.handler = function(context, event, callback) {
callback(null, {"instruction": "redirect",
"call_sid": "I DONT KNOW WHAT GOES HERE",
"url": "I DONT KNOW WHAT GOES HERE",
});
};
This is my assignment callback url but I don't know what the last two arguments are exactly asking for. This is the doc I'm using for reference at the bottom of the page https://www.twilio.com/docs/taskrouter/handle-assignment-callbacks

Cannot put caller into conference

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

What does the Twilio statusCallback file look like?

I am sending a voice message via Twilio and specifying a callback url for all the statuses but I don't think it is actually getting called because I have not been able to find out what the call back file is supposed to look like. What does the callback file look for? Is it a form being sent in? What does my "callbackfilename" code look like? I cannot find that info anywhere. thanks
These are my params:
params["StatusCallback"]= "http://XXXX.com/events/callbackfilename";
params["StatusCallbackMethod"]="POST";
params["StatusCallbackEvent"]="initiated";
params["StatusCallbackEvent"]="ringing";
params["StatusCallbackEvent"]="answered";
params["StatusCallbackEvent"]="completed";
params["IfMachine"] = "Continue";
Twilio developer evangelist here.
The StatusCallback comes much the same as a TwiML request for an incoming calls. It's sent as form encoded data (application/x-www-form-urlencoded) and includes all the regular parameters sent in an incoming call request.
You also get a bunch of bonus parameters, listed here. You can see those parameters below too:
CallStatus A descriptive status for the call. The value is one of queued, initiated, ringing, in-progress, busy, failed, or no-answer. See the CallStatus section for more details.
CallDuration The duration in seconds of the just-completed call. Only present in the completed event.
RecordingUrl The URL of the phone call's recorded audio. This parameter is included only if Record=true is set on the REST API request and does not include recordings from <Dial> or <Record>. RecordingUrl is only present in the completed event.
RecordingSid The unique ID of the Recording from this call. RecordingSid is only present in the completed event.
RecordingDuration The duration of the recorded audio (in seconds). RecordingDuration is only present in the completed event.
Timestamp The timestamp when the event was fired, given as UTC in RFC 2822 format.
CallbackSource A string that describes the source of the webhook. This is provided to help disambiguate why the webhook was made. On Status Callbacks, this value is always call-progress-events.
SequenceNumber The order in which the events were fired, starting from 0. Although events are fired in order, they are made as separate HTTP requests and there is no guarantee they will arrive in the same order.
If you want to check these parameters and that they're getting sent, you could set up something like a RequestBin which records the requests so that you can inspect them easily.
Let me know if this helps.

Twilio connection parameters missing "To" parameter

I'm developing a Rails Twilio-based application and want to show to my user the number that the caller is calling (because in my application, a user can be associated with multiple numbers).
Here's the code:
Twilio.Device.incoming (conn) ->
$("#log").text("Receiving call from:" + conn.parameters.From)
$("#log").text("Calling to:" + conn.parameters.To)
ringtone.play()
$('.answer').click ->
ringtone.pause()
# accept the incoming connection and start two-way audio
conn.accept()
However, the conn.parameters object does not have a To parameter as the documentation says.
For now, I can get the number being called only server side, with params["Called"], but that is not what I need.
Any ideas ?
Megan from Twilio here. I'd like to share some of what I learned after recently getting Twilio Client up and running.
The way I imagine your call flow is that a 'user' in your application represents an agent with multiple sales lines connected to Twilio numbers configured to a TwiML app. When a customer or the 'caller' finds one of those numbers and dials it, you want to display to the user-agent which of the Twilio numbers the customer is calling.
In the code above conn.parameters.To likely represents your default_client, if you specified one. But conn.parameters.From should actually display the number the caller is calling, which if I am understanding correctly is the desired behavior.
Hope this helps!

Resources