简体   繁体   English

类型错误:无法读取未定义的属性“数字”

[英]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.我在 Node.js Twilio 文档中使用通过键盘收集用户输入(DTMF 音调)中的代码来从通话中获取用户输入。

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

Is the below added after you initialize Express?初始化Express后是否添加了以下内容?

// Body Parser Middleware
app.use(express.urlencoded({ extended: false }));

Something like:就像是:

const express = require('express')

const app = express()

app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded

app.post('/profile', function (req, res, next) {
  console.log(req.body)
  res.json(req.body)
})

It looks like the documentation has it, so maybe it was accidentally omitted in your code?看起来文档中有它,所以它可能在您的代码中被意外遗漏了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:无法读取未定义的属性“_fieldsProto” - TypeError: Cannot read property '_fieldsProto' of undefined 类型错误:无法读取未定义的属性“ref” - TypeError: Cannot read property 'ref' of undefined Firebase,类型错误:无法读取未定义的属性“错误” - Firebase, TypeError: Cannot read property 'error' of undefined 类型错误:无法读取未定义的属性“CONTEXT” - TypeError: Cannot read property 'CONTEXT' of undefined 未捕获的类型错误:无法读取未定义的属性“initializeApp” - Uncaught TypeError: Cannot read property 'initializeApp' of undefined 类型错误:无法读取第 100 行未定义的属性“4” - TypeError: Cannot read property '4' of undefined at Line 100 TypeError:无法使用 nodejs 读取未定义的属性“byteLength” - TypeError: Cannot read property 'byteLength' of undefined with nodejs 类型错误:无法读取未定义的属性“长度”- Firebase - TypeError: Cannot read property 'length' of undefined - Firebase 类型错误:无法读取未定义的属性“地图”:firebase 和 angular 日历 - TypeError: Cannot read property 'map' of undefined : firebase with angular calendar Firebase recaptchaVerifier 显示未捕获的类型错误:无法读取未定义的属性“RecaptchaVerifier” - Firebase recaptchaVerifier showing Uncaught TypeError: Cannot read property 'RecaptchaVerifier' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM