[英]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.