Build a Twilio Autopilot bot IVR that answers phone and follows instructions

拜拜、爱过 提交于 2019-12-11 04:29:58

问题


I am trying to build a bot that can answer a call. The caller would say a phrase like "Press 1" and the bot would play digits 1.

If the caller said Press 2, the bot would respond by playing digits 2, and so on.

Any insight would be helpful. Thank you

Lu


回答1:


Twilio developer evangelist here.

Welcome to StackOverflow!

This Node.js quickstart has the first few steps you'd need to make a voice bot with Autopilot.

First, you'd buy a Twilio phone number here. Then, you'd configure that number with the URL from your Twilio Autopilot bot. That number would be found under Channels on the lefthand side of your Autopilot bot. Click Programmable Voice and copy this URL and then paste it under Voice & Fax for when a call comes in next to webhook:

Next, you could then make a task for each possible phrase the user could say. If the phrase is "press 1", you could redirect to a Twilio Function that uses sendDigits to play DTMF tones when the call is answered. The Twilio Autopilot task could include this JSON:

{
    "actions": [
        {
            "redirect": {
                  "uri": "https://YOUR-TWILIO-FUNCTION-URL.twil.io/actions",
                  "method": "POST"
            }
        }
    ]
}

Then your Function code could be

const VoiceResponse = require('twilio').twiml.VoiceResponse;
const response = new VoiceResponse();
const dial = response.dial();
dial.number({
    sendDigits: 'wwww1928'
}, 'replace-with-number-to-dial');
console.log(response.toString());

Alternatively, you could have one Autopilot task and then use a conditional in the Twilio Function to check which number the user said. That would include code similar to this:

exports.handler = function(context, event, callback) {
    const VoiceResponse = require('twilio').twiml.VoiceResponse;
    const response = new VoiceResponse();
    const dial = response.dial();
    let responseObject = {};
    let memory = JSON.parse(event.Memory);
    console.log(memory.twilio.collected_data);
     let num = memory.twilio.collected_data.your_collect_function_name.answers.your_question_name.answer;
    console.log(num); //collected data from memory
    if(num == 0 || num == "zero") {
        dial.number({
            sendDigits: '0'
        }, 'replace-with-number-to-dial');
        console.log(response.toString());
    }
};

Let me know if this helps at all!



来源:https://stackoverflow.com/questions/58361539/build-a-twilio-autopilot-bot-ivr-that-answers-phone-and-follows-instructions

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