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.
Related
Here is my requirement: I receive a request to validate some data/records. Records would be sent to the SQS queue per each request for further processing by another service/component. The message structure looks like this:
messageId: //a unique message id
requestId: //request id common between all messages/records for that request
record_body: {//key-value pairs}
Everything works fine. Now I want to figure out when all messages with the same request id have been read from the queue (I.e. there is no more message for that request id).
The idea that I have is to write each message/record to the database upon each read and then have another scheduled service that can be triggered (by cloudwatch) to check the number of records for each request and finally update the status of the request to complete if the number of records in the database are equal to the number of records in the original request.
I just want to share this to see if anybody else had this kind of requirement and how they approached it!
How about this ?
Include the number of requests and current request to the queue. Make sure the request goes to the queue in the same order.
Example - You have 4 requests for requestId - abc
You will send each request with values included (1:4) (2:4) (3:4) (4:4) in the order to the queue.
This way when you are reading from the queue you will read (4:4) last and you will know you have processed all the 4.
Another way to do is include total number of requests in the message in every message and while processing each message check whether it matches the original one as you have total in your message now. (by querying the database).
I'm using Java but the question is language-agnostic, so I posted it under twilio-PHP tag too.
My application needs to connect two customers: A and B. I want to transcribe the conversation and find out whether one of the parties did not pick up and screened the other to voicemail.
I'm following the steps in the click-to-call-tutorial
However, it looks like the Rest API supports recording but not transcription. I successfully can do:
Map<String, String> params = new HashMap<String, String>();
params.put("From", myTwilioNumber);
params.put("To", customerAPhoneNumber);
params.put("Url", "http://MyHandler.jsp");
params.put("IfMachine", "Hangup");
params.put("Record", "true");
Call call = client.getAccount().getCallFactory().create(params);
which gets the entire conversation recorded, but not transcribed!
As a side note -
params.put("IfMachine", "Hangup");
indeed hangs up, when reaches voicemail, but not before leaving a voicemail with random noise. Looks like Twilio's "probing" the response, and by the time it understands it got to voicemail, background noises have been recorded. Which is terrible user experience. Any advice?
Additionally, my call handling servlet does:
TwiMLResponse twimlResponse = new TwiMLResponse();
Say sayMessage = new Say(
"Hi, customer A, stay on line to speak with customer B?");
twimlResponse.append(sayMessage);
Dial dial = new Dial(customerBPhoneNumber);
twimlResponse.append(dial);
But when I'm looking at the TwiML Verbs , there is no place where I can set params.put("IfMachine", "Continue") . So the field call.getAnsweredBy() is null for the second call. In other words, I cannot know whether conversation between customer A and B ever happened.
Additionally, [TwiML Verb Record] ( https://www.twilio.com/docs/api/twiml/record ) does allow transcription, but if I do
twimlResponse.append(new Record());
it stops the conversation and records one of the customers.
So I cannot direct the REST API to transcribe, and TwiML Verbs does not even record the conversation in a way I want.
Can anyone help?
Thanks.
Twilio developer evangelist here.
I'm afraid that when recording both legs of a call, using the REST API, then transcription is not available. Transcription is only available on single messages recorded by the <Record> verb when the recording is under 2 minutes long.
I'd recommend recording the call and downloading the file to be sent off to a third party transcription service in order to transcribe longer, 2 legged calls like that.
In terms of the answering machine detection, it is an experimental feature and requires Twilio to listen to the first few seconds of a call to work out whether it is a machine or not. A good alternative, which can work as part of your <Dial> verb as well, is to use call screening. This is a good article on the pros and cons of AMD, as well as a good description of using human detection by call screening.
Let me know if this helps at all.
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!
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!
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.