0
votes

So, I've been working with Autopilot tasks for a little here since the patch when you no longer need to build, and I've seen that when I get to the second redirect to another task and when that task listens, it just fails to listen and it goes back to its fallback task.

I've tried to not use a function between the redirect and such, I've used a direct post to my Twilio function, and none of that works. I do have a questionnaire of two questions, and the complete label is a redirect, and that is where my tasks start to fail.

 "actions": [
  {
   "say": {
    "speech": "I just have a few questions"
   }
  },
  {
   "collect": {
    "name": "questions",
    "questions": [
     {
      "question": "Is the weather nice today",
      "name": "q_1",
      "type": "Twilio.YES_NO",
     },
     {
      "question": "Do you like ice cream?",
      "name": "q_2",
      "type": "Twilio.YES_NO",
     }
    ],
    "on_complete": {
     "redirect": "MY FUNCTION LINK"
    }
   }
  }
 ]
}

Then the function will return this as a JSON:

responseObject = {
 "actions": [
  { 
   "redirect": "task://MY TASK" 
  }
 ]
};

Then the tasks goes like this:

{
 "actions": [
  {
   "say": "Would you like to be transfered over, or be called later?"
  },
  {
   "listen": {
    "tasks": [
     "transfer",
     "calllater"
    ]
   }
  }
 ]
}

But the tasks that as being listened to never completes, and my logs seem like the task that called it does not exist.

The task should go to the correct tasks that are being listed to, but it just crashes and goes back to the fallback task. I have to idea why this does not work, please let me know.

1
Uh, bump? I really need help with this guysRonanCraft

1 Answers

1
votes

Twilio developer evangelist here. 👋

I just took the code you posted and adjusted it and it works fine. Let me tell you what I did.

I created a welcome task

// welcome task
{
    "actions": [
        {
            "say": {
                "speech": "I just have a few questions"
            }
        },
        {
            "collect": {
                "name": "questions",
                "questions": [
                    {
                        "question": "Do you like ice cream?",
                        "name": "q_2",
                        "type": "Twilio.YES_NO"
                    }
                ],
                "on_complete": {
                    "redirect": "https://picayune-snout.glitch.me/api/collect"
                }
            }
        }
    ]
}

This tasks defines similar to your example an on_complete endpoint which I hosted on Glitch. The endpoints responds with JSON which looks like this.

module.exports = (req, res) => {
  res.setHeader('Content-Type', 'application/json');
  res.send(JSON.stringify(
    {
      "actions": [      
        {
            "say": {
                "speech": "Thanks for you information"
            }
        },
        { 
         "redirect": "task://continue" 
        }
      ]
    }
  ));
}

Then, I defined the continue task similar to yours:

{
    "actions": [
        {
            "say": "Would you like to be transfered over, or be called later?"
        },
        {
            "listen": {
                "tasks": [
                    "transfer",
                    "calllater"
                ]
            }
        }
    ]
}

calllater and transfer only use say and it works fine. Important piece is that you define samples for these two tasks so that the system can recognize them. Also you have to rebuild the model for the Natural Language Router.

Samples for a task

Rebuild model dialog

Hard to tell what you did wrong. :/