0
votes

I am using twilio auto pilot running a nodejs server. I start off in a default greeting, then run this login task, it hears me, it send the post and then the POST request has an empty body. i am at a loss. I tried making the POST to https and http. It does not go to collect on failure. I do not have a field ID setup as all I want to do is trigger the task and then send the COLLECT info on. Some direction would be appreciated. I did everything in the tutorial, though i am not sending to a twilio function. I do not understand why the body is empty.

{
"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"
                }
            }
        }
    }
]

}

Is there something else that I need to do? I thought it was simple. Collect the info and send it to my server, then my server would send a new twiml. All I do currently is just log the entire incoming request.

My plan is to have someone log in with the assistant. Call my phone number, it plays a digit in programmable voice, then hands it off to the assistant, then the assistant asks for the login id, sends the collected info to my server for processing and then I send a response back to the assistant from my server in the form of a TWIML / xml with login / pass /fail and their customer object so the assistant can have that in memory. Obviously i am just on step one but that is my plan. Help would be appreciated.

1

1 Answers

0
votes

I found the issue and it was with nodejs, for whatever reason, I needed to have jsonencoded in the first post then to urlencoded and then back urlencoded again. I had the third leg as jsonencoded. Hopefully this helps someone else out. I wish there were more examples on 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