[英]TypeError: Cannot read property 'Digits' of undefined
我在 Node.js Twilio 文檔中使用通過鍵盤收集用戶輸入(DTMF 音調)中的代碼來從通話中獲取用戶輸入。
但每次我撥入號碼時,我都會收到一個錯誤:“類型錯誤:無法讀取未定義的屬性‘數字’”
謝謝!
代碼:
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());
});
初始化Express后是否添加了以下內容?
// Body Parser Middleware
app.use(express.urlencoded({ extended: false }));
就像是:
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)
})
看起來文檔中有它,所以它可能在您的代碼中被意外遺漏了?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.