【发布时间】:2024-05-23 12:50:01
【问题描述】:
我使用了Gather User Input via Keypad (DTMF Tones) in Node.js twilio 文档中的代码 用于从调用中获取用户输入。
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());
});
当我拨打我的 twilio 号码时,我在 if 语句中收到类似“TypeError: Cannot read property 'Digits' of undefined”的错误。我想获取用户在通话过程中输入的号码。提前致谢!
【问题讨论】:
-
感谢您的快速响应。它现在工作正常。问题出在我的服务提供商呼叫 twilio 号码。我改变了我的服务现在工作正常:)
标签: javascript node.js twilio twilio-api twilio-twiml