gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'Digits' of undefined in twilio when gathering user input from call

转载 作者:太空宇宙 更新时间:2023-11-03 23:51:06 24 4
gpt4 key购买 nike

我使用了 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” 的错误。我想获取用户在通话过程中输入的号码。提前致谢!!

最佳答案

您的初始请求似乎没有正确的body。尝试在 if 语句中添加检查:

if (request.body && request.body.Digits) {
// switch / case
} else {
gather();
}

关于javascript - 类型错误 : Cannot read property 'Digits' of undefined in twilio when gathering user input from call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59471076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com