I have used the code from Gather User Input via Keypad (DTMF Tones) in Node.js twilio documentation for getting user input from the call.
app.post('/voice', (request, response) => {
const twiml = new VoiceResponse();
function gather() {
const gatherNode = twiml.gather({ numDigits: 1 });
gatherNode.say('For sales, press 1. For support, press 2.');
twiml.redirect('/voice');
}
if (request.body.Digits) {
switch (request.body.Digits) {
case '1':
twiml.say('You selected sales. Good for you!');
break;
case '2':
twiml.say('You need support. We will help!');
break;
default:
twiml.say("Sorry, I don't understand that choice.").pause();
gather();
break;
}
} else {
gather();
}
response.type('text/xml');
response.send(twiml.toString());
});
When i call to my twilio number i'm getting error like "TypeError: Cannot read property 'Digits' of undefined" at the if statement.I want to get what number user enters during the call.Thanks in advance!!