问题
I'm following the Answering Machine Detection Beta feature Twilio recently introduced to the API this year. I set the MachineDetection field to Enable
and set the MachineDetectionTimeout to 5 seconds. When I make the request using the request-promise
package in Node.JS, the following output is returned as a JSON body object:
{"sid": "MYSID",
"to": "+1845555555",
"to_formatted": "(845) 555-5555",
"from": "+18569972628", "from_formatted": "(856) 997-2628",
"phone_number_sid": null,
"status": "queued"
"start_time": null,
"end_time": null,
"duration": null,
"price": null,
"price_unit": "USD",
"direction": "outbound-api",
"answered_by": null,
"api_version": "2010-04-01",
"annotation": null,
"forwarded_from": null,
"group_sid": null, "caller_name": null,
"uri": "/2010-04-01/Accounts/mySIDaccount/Calls/C
A303d158baf885d4480284d4529ce49a8.json",
"subresource_uris":
{"notifications": "/2010-04\
01/Accounts/myaccount/Calls/\
CA303d158baf885d448028\
4d4529ce49a8/Notifications.json",
"recordings": "/2010-04 \
01/Accounts/myaccount/Calls/\
CA303d158baf885d4480284d4529ce49a8/Recordings.json"}
}
The answered_by
value is null
instead` of one of the 4 values specified to return back from the request (Twilio-API documentation):
- machine_start
- human
- fax
- unknown
Am I doing something wrong? My application route is as shown below:
var request = require('request-promise');
request.post({url: 'https://api.twilio.com/2010-04-01/Accounts/'+
config.accountSid+"/Calls.json",
form: {To: phoneNumber,
From: config.twilioNumber,
MachineDetection: 'Enable',
MachineDetectionTimout: 5,
Url: url},
auth: {user: config.accountSid,
pass: config.authToken
},
timeout: 10000
}).then(function(parsedBody){
console.log('\n\n\n\n'+parsedBody+'\n\n\n\n');
response.send({message: 'Transferring...'});
}).catch(function(parsedBody){
console.log(parsedBody);
response.status(500).send(parsedBody);
});
});
I even tried the curl route on my bash and came up with the exact same results.
回答1:
Twilio developer evangelist here.
When you make the request to start a call, as you are doing in this example, the API will respond successfully to let you know that the call has been started. At this stage the call may not even be ringing, so you can't know the result of the answer machine detection yet.
Instead, you will get the result of AnsweredBy
when the call connects and Twilio has either worked out if it is a machine or otherwise, or the answering machine detection times out. You will get the AnsweredBy result in the webhook that Twilio sends to your application at the URL you set in the request. It is at that stage that you can decide what to do with the call.
Let me know if that helps at all.
来源:https://stackoverflow.com/questions/45740616/retrieved-answered-by-response-as-null