'TypeError: Cannot read property 'Digits' of undefined

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.

but every time I dial in the numbers I'm just getting an error: "TypeError: Cannot read property 'Digits' of undefined"

Thanks!

code:

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source