收集后 twilio autopilot 为空 body,然后重定向到我的服务器

twilio autopilot empty body after collect and then redirected to my server

我正在使用 twilio auto pilot 运行连接 nodejs 服务器。我以默认问候语开始,然后 运行 这个登录任务,它听到我的声音,它发送 post 然后 POST 请求有一个空的 body。我很茫然。我尝试将 POST 设为 https 和 http。它不会在失败时收集。我没有字段 ID 设置,因为我只想触发任务,然后发送收集信息。一些方向将不胜感激。我做了教程中的所有内容,但我没有发送到 twilio 函数。我不明白为什么 body 是空的。

{
"actions": [
    {
        "collect": {
            "name": "collect_login",
            "questions": [
                {
                    "question": "what is your number?",
                    "name": "loginID",
                    "type": "Twilio.NUMBER_SEQUENCE"
                }
            ],
            "on_complete": {
                "redirect": {
                    "method": "POST",
                    "uri": "https://server.com/pm/auto/login"
                }
            }
        }
    }
]

}

我还需要做些什么吗?我以为很简单。收集信息并将其发送到我的服务器,然后我的服务器将发送一个新的 twiml。我目前所做的只是记录整个传入请求。

我的计划是让人用助手登录。 拨打我的 phone 号码,它用可编程语音播放一个数字,然后交给助手,然后助手询问登录 ID,将收集到的信息发送到我的服务器进行处理,然后我发回响应从我的服务器以 TWIML / xml 的形式发送给助手,其中包含登录/通过/失败和他们的客户 object,这样助手就可以将其保存在内存中。显然我只是第一步,但这是我的计划。帮助将不胜感激。

我发现了问题,它与 nodejs 有关,无论出于何种原因,我需要在第一个 post 中进行 jsonencoded,然后进行 urlencoded,然后再次返回 urlencoded。我有第三条腿作为 jsonencoded。希望这可以帮助其他人。我希望 twilio 上有更多示例。

app.post('/pm/twil/v/login', jsonencodedParser, function (req, res) {
const rt = new VoiceResponse();

rt.say('Hello how are you doing today?')

rt.play({
    digits: 'wwwwww'
});
rt.play({
    loop: 1
}, 'https://server.com/pm/5.wav');
rt.play({
    digits: 'wwwwww'
});
rt.play({
    loop: 1
}, 'https://server.com/pm/5.wav');

const gather = rt.gather({
    numDigits: 6,
    action: '/pm/twil/v/pD',
  });

gather.say('enter in your i d number to login');
console.log(rt.toString());
rt.play({
    digits: 'wwww'
});
res.send(rt.toString());
})//end post

app.post('/pm/twil/v/pD', urlencodedParser, function (req, res) {
const rt = new VoiceResponse();
console.log('request.body in pd');
console.log(req.body);


if (req.body.Digits) {
for(var i = 0; i < userGlobList.length; i++){

  if(req.body.Digits == userGlobList[i].userId){
rt.say('Logged in. Remember everytime you call it costs 2 credits');


rt.say('your balance is '+ userGlobList[i].credits+' credits');
rt.account = userGlobList[i].userId;
if(userGlobList[i].credits !== 0){
  const gather = rt.gather({
    numDigits: 1,
    action: '/pm/twil/v/LoggedIn',
  });
gather.say('1 for call, 2 for text,');
rt.play({
    digits: 'ww'
});
}
if(userGlobList[i].credits == 0){
  rt.say('Please have credits added to your account');
  rt.hangup();
  }//if
  break;
}//end if
////SAVE CUSTobj and minus credits for lookup


}//for

rt.say('Error no account')
 }//if
console.log(rt.toString());

res.send(rt.toString());
})/////////end post

app.post('/pm/twil/v/LoggedIn', urlencodedParser, function (req, res) {
const rt = new VoiceResponse();
console.log('request.body in LoggedIn');
}
if (req.body.Digits == 1) {
  console.log('in voicemail');
rt.say('welcome to voicemail');
}//endif

if(req.body.Digits == 2){
  console.log('in text');

}//end if

if(req.body.Digits != 1 && req.body.Digits != 2){
  rt.say('Not an option');
}

rt.hangup()

console.log(rt.toString());

res.send(rt.toString());
})//end post