简体   繁体   中英

Autopilot and Functions collecting data he

I have a task in autopilot that collects data from a caller then calls a function using a redirect. I cant seem to access the post variables. please assist.

so when run this I get the following error

Error - 82002

Error on Twilio Function response

produced by this line of code

var first_name = memory.twilio.collected_data.lead_qual.lead_qual_first;

remove that line and it works fine just no access to the collected data.

following are the dependencies I have included, the task code and the function.

looks like this.. Dependencies......>

lodash 4.17.11 twilio 3.29.2 fs 0.0.1-security got 9.6.0 moment-timezone 0.5.14 moment 2.29.1 xmldom 0.1.27 twilio/runtime-handler 1.0.1 util 0.11.0 request 2.87.0

Task......>

    {
"actions": [
{
"collect": {
"name": "lead_qual",
"questions": [
{
"question": "What is your first name?",
"name": "lead_qual_first",
"type": "Twilio.FIRST_NAME"
},
{
"question": "What is your last name?",
"name": "lead_qual_last",
"type": "Twilio.LAST_NAME"
},
{
"question": "If we are disconnected what is the best phone number to reach you on??",
"name": "lead_qual_phone",
"type": "Twilio.PHONE_NUMBER"
},
{
"question": "What is your date of birth?",
"name": "lead_qual_dob",
"type": "Twilio.DATE"
},
{
"question": "Are you currently covered by disability, yes or no?",
"name": "lead_qual_disability",
"type": "Twilio.YES_NO"
},
{
"question": "Do you have any form of federal medicare, yes or no?",
"name": "lead_qual_medicare",
"type": "Twilio.YES_NO"
},
{
"question": "Do you have medicaid or another state sponsored insurance, yes or no?",
"name": "lead_qual_medicaid",
"type": "Twilio.YES_NO"
},
{
"question": "Finally, Are you currently insured, yes or no?",
"name": "lead_qual_insured",
"type": "Twilio.YES_NO"
}
],
"on_complete": {
"redirect": {
"method": "POST",
"uri": "https://health-agent-3097.twil.io/Evaluate-Answers"
}
}
}
}
]
}
 

Function......>

// This is your new function. To start, set the name and path on the left.

exports.handler = function(context, event, callback) {

// Require the component used to post.

const got = require("got");

// Time zone for EST to check times with.

let moment = require('moment-timezone');

const now = moment().tz('America/New_York');

// initialize the return object

var responseObject = {};

var first_name = memory.twilio.collected_data.lead_qual.lead_qual_first;

responseObject =

{

"actions":[

  {

    "say":"Force Override result"

  },

  {

    "redirect": {

      "method": "POST",

      "uri": "task://goodbye"

    }

  }

]
}

// This callback is what is returned in response to this function being invoked.

callback(null, responseObject);}

Twilio developer evangelist here.

memory is not one of the arguments passed to a Twilio Function. You are passed event , context and callback . You are using the callback correctly and the context includes your environment variables.

The event object is what you need here though. The event includes all the parameters sent to the Function. According tothe documentation on the Autopilot request you will be sent a Memory parameter. That Memory will be a JSON string that needs parsing. So instead, try accessing:

const memory = JSON.parse(event.Memory);
const firstName = memory.twilio.collected_data.lead_qual.lead_qual_first;

Let me know how you get on with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM