Twilio conference voicemail/machine detection

≯℡__Kan透↙ 提交于 2021-01-01 06:12:29

问题


I am building an application in which we add 20 people to a conference for an important discussion, and suppose one or two of participants (From the 20 people added to the conference) is not available and their voicemail is active, then in the middle of an important discussion those prerecorded voicemail messages/audio starts, this is very annoying for others in the conference. I want to prevent this from happening.

I have tried using ifMachine but it did not help, MachineDetection callback URL is not is also not getting called, same is the case for AnsweredBy as well.

I am following MachineDetection.

My code is as follows

const Twilio = require('twilio');
const client = new Twilio(account_sid, authToken);

mobileArr.forEach(function(number,ind) {
        console.log("mobile array iteration",ind, number,'    '+twilioCallBackUrl+'twilioMachineWebhook');
        client
          .conferences(conferences.title)
          .participants.create({
            machineDetection: 'Enable',
            url:twilioMachinecallback,
            to: number,
            from: user.twilioDetails.number,
            statusCallback: twilioCallWebhook,
            statusCallbackMethod: 'POST',
            statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
            Timeout: '15',
            method: 'GET',
        }, function(err, participant) {
            if (err) {
                console.error('conf failed because: '+ err + '   ' + helper.authToken + '   ' +client.accountSid);
            } else {

            }
        })
    })

I am new to Twilio please suggest and help if have I done anything wrong.


回答1:


Twilio developer evangelist here.

The participants resource does not list the machineDetection or Url parameter as available parameters when creating a call directly into a conference. This is because this API call dials a participant directly into the conference call.

To handle the machine detection you will need to make the call using the regular Calls resource. In this API request you can set machineDetection to Enable and set a Url. You'll need your URL to be able to handle the AnsweredBy parameter and either, if it is human, return the TwiML to dial your user into the <Conference> or just <Hangup> on the machine.

Let me know if that helps at all.




回答2:


Well, it turns out that AMD machine Detection is not a reliable option.

Hence I went for alternatives-to-amd which is also known as Call Screening.

It's reliable. The steps are as follows:

  1. You have to create all calls to be added to the conference.
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)
    })
});
  1. Then you have to use gather in 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());
    }
  1. Then add all these calls to a particular conference using the Gather method callback.
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());
    }

}

The code for gatherFailure is as follows

    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());

}

In this way by using gather anyone call detect whether call was answered by a human or not and perform any suitable action required.

Once again a big thank's to philnash.



来源:https://stackoverflow.com/questions/50271503/twilio-conference-voicemail-machine-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!