It's actually pretty simple to do.
As @lizziepika mentioned, you have to utilize functions.
First, let's say you want to collect data from a question like so:
TASKS Example
{
"actions": [
{
"collect": {
"name": "contact",
"questions": [
{
"question": "Are you a human?",
"name": "contact_human",
"type": "Twilio.YES_NO"
}
],
"on_complete": {
"redirect": {
"method": "POST",
"uri": "https://Your_Twilio_Function_Domain.twil.io/Function_Name"
}
}
}
}
]
}
On complete, the Autopilot will redirect to a Twilio Function.
A great example of a Twilio function for autopilot can be found here.
https://github.com/twilio/autopilot-templates/blob/master/Functions/simple_response.js
I have tweaked it for our example.
exports.handler = function(context, event, callback) {
//we get the Memory from the answered questions.
let memory = JSON.parse(event.Memory);
//set up an array of object "actions" for the autopilot to continue.
let actions = [];
let responseItem;
//get the answer from Memory
let human = Memory.twilio.collected_data.contact.answers.contact_human.answer; //Yes or No
if(human === "Yes"){
responseItem = {
"say": "ANSWER YES - You are human"
};
actions.push(responseItem);
}else{
responseItem = {
"say": "ANSWER No - You are NOT human"
};
actions.push(responseItem);
}
responseItem = {
"redirect": {
"method": "POST",
"uri": "task://next_task"
}
};
actions.push(responseItem);
let respObj = {
"actions": actions
};
callback(null, respObj);
};
The beauty of this is that you can have the function respond with anything that would be present in a task. You can have the function respond with questions, actions, redirects, etc, as long as the payload is the same form as Autopilot Tasks.