How do I know whether or not a call is answered?
For StatusCallback, I can set the following values:
initiated
ringing
answered
completed
When Twilio sends me statuses, I don't see a value for "answered" what I see are the following:
no-answer
busy
completed
initiated
failed
I'm wondering why there is no status returned for:
answered
though I'm setting "answered" as one of the values for StatusCallback.
What confuses me is that Twilio sends "Completed" irrespective of whether or not the call was answered or not.
I need a definite status for the call being answered. If the call is not answered then I need to retry again later or build a business logic around it.
When the call is not answered, then I get "not-answered".
When the call is answered, then I get "completed", but "completed" does not necessarily mean the call was actually answered assuming that the call went to the voicemail box or something.
On a side note, I am also setting the "IfMachine" parameter in the call request. Though I know that it is an experimental feature, I get the call status as "completed" as in this case, my expectation is "not-answered".
How do I know if the call was actually answered?
Megan, also from Twilio!
Just wanted to clear a few things up here. You mention using StatusCallback which expects a URL. The answered value is actually set using StatusCallbackEvent as you can see here in the docs.
I don't know what language you're using but an example in Python (you can find other languages on that docs page):
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "YOUR_ACCOUNT_SID"
auth_token = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(account_sid, auth_token)
call = client.calls.create(
url="http://demo.twilio.com/docs/voice.xml",
to="+14155551212",
from_="+18668675309",
method="GET",
status_callback="https://www.myapp.com/events",
status_callback_method="POST",
status_events=["initiated", "ringing", "answered", "completed"],
)
print call.sid
And a final note about using IfMachine. For the time being, we actually recommend that you use Twilio's <Gather> verb to detect if a human picks up as explained in this question here.
Hope this helps!
Related
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.
I'm trying to add a participant to an existing conference. It works just fine, but now I want to add a statusCallback to be called when the ringing begins for the new participant.
Here's the line where I'm creating the new participant:
client.conferences(conferenceName).participants.create({
from: `client:${fromAgentId}`,
to: `client:${toAgentId}`,
statusCallback: statusCallbackUrl,
statusCallbackEvent: "initiated ringing answered completed",
statusCallbackMethod: "POST",
});
As I said, the new participant is successfully getting added to the conference, but the statusCallbackUrl never gets called.
According to these docs https://www.twilio.com/docs/voice/api/conference-participant?code-language=Node.js#parameters-1 it looks like the participants.create() method should accept a statusCallback, so I have no idea why it's not working. If anyone has an idea, I'd love to hear from you.
Answering my own question here.
It seems like it's a problem with the Twilio docs. Regarding the statusCallbackEvent parameter, the docs state:
Can be: initiated, ringing, answered, and completed. Separate multiple values with a space.
However, rather than separating multiple values with a space, the statusCallbackEvent parameter should be an array of values.
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
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.
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.