好吧,事实证明 AMD 机器检测并不是一个可靠的选择。
因此,我选择了 AMD 的替代品,也称为Call Screening。
这是可靠的。步骤如下:
- 您必须创建要添加到会议的所有呼叫。
const Twilio = require('twilio');
const client = new Twilio(account_sid, authToken);
mobileArr.forEach(function(number,ind) {
client.calls
.create({
url: 'CallScreening call url',
from: user.twilioDetails.number,
to: number,
statusCallback: 'Your call status callback url',
statusCallbackMethod: 'POST',
statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
Timeout: '15',
method: 'POST'
})
.then(call => {
console.log(call)
})
});
- 然后你必须在url 中使用收集:'CallScreening call url'
const VoiceResponse = require('twilio').twiml.VoiceResponse;
exports.callScreeningWebhook = (req, res) => {
console.log('callScreeningWebhook');
console.log(req.body);
const twiml = new VoiceResponse();
const gather = twiml.gather({
input:'dtmf',
timeout: 20,
numDigits: 1,
action: twilioCallBackUrl+'gatherAction'
});
gather.say('Please enter any digits to join conference');
// Render the response as XML in reply to the webhook request
res.type('text/xml');
res.send(twiml.toString());
}
- 然后使用Gather方法回调将所有这些呼叫添加到特定会议。
exports.gatherAction = (req, res) => {
console.log('gatherAction');
console.log(req.body);
const twiml = new VoiceResponse();
if (req.body.Digits) {
var input = parseInt(req.body.Digits)
console.log('HEllo',typeof input);
if (!isNaN(input)){
console.log('JoIN conference data');
twiml.say('You are being merged to conference');
const dial = twiml.dial();
dial.conference({
statusCallbackMethod: 'POST',
statusCallbackEvent: 'start end join leave',
statusCallback: twilioCallBackUrl+'twilioConferenceWebhook'
}, conference.title);
console.log(twiml.toString());
console.log('JoIN Complete')
res.type('text/xml');
res.send(twiml.toString());
}else{
console.log('input parsing error');
twiml.say('Invalid input, Please try again')
twiml.redirect(twilioCallBackUrl+'callScreeningWebhook');
res.type('text/xml');
res.send(twiml.toString());
}
}else{
console.log('no input');
twiml.say('No input, Please try again')
twiml.pause({length: 10});
twiml.redirect(twilioCallBackUrl+'gatherFailure');
res.type('text/xml');
res.send(twiml.toString());
}
}
collectFailure的代码如下
exports.gatherFailure = (req, res) => {
console.log('gatherFailure');
console.log(req.body);
const twiml = new VoiceResponse();
twiml.hangup();
res.type('text/xml');
res.send(twiml.toString());
}
通过这种方式,通过使用收集任何人的呼叫来检测呼叫是否由人接听并执行所需的任何合适的操作。
再次非常感谢philnash。