自动驾驶仪和功能收集数据他

问题描述

我在自动驾驶仪中有一项任务,该任务从调用方收集数据,然后使用重定向调用函数。 我似乎无法访问帖子变量。请帮忙。

所以当运行这个我得到以下错误

错误 - 82002

Twilio 函数响应错误

由这行代码产生

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

删除该行,它工作正常,只是无法访问收集的数据。

以下是我包含的依赖项、任务代码函数

看起来像这样.. 依赖......>

lodash 4.17.11 twilio 3.29.2 fs 0.0.1-安全 得到 9.6.0 时刻时区 0.5.14 时刻 2.29.1 xmldom 0.1.27 twilio/运行时处理程序 1.0.1 实用程序 0.11.0 请求 2.87.0

任务......>

    {
"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,"name": "lead_qual_medicare",{
"question": "Do you have medicaid or another state sponsored insurance,"name": "lead_qual_medicaid",{
"question": "Finally,Are you currently insured,"name": "lead_qual_insured","type": "Twilio.YES_NO"
}
],"on_complete": {
"redirect": {
"method": "POST","uri": "https://health-agent-3097.twil.io/Evaluate-Answers"
}
}
}
}
]
}
 

功能......>

// 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 开发者布道者。

memory 不是传递给 Twilio 函数的参数之一。您已通过 eventcontextcallback。您正确使用了 callback,并且 context 包含您的环境变量。

event 对象正是您在这里所需要的。 event 包括发送到函数的所有参数。根据 the documentation on the Autopilot request,您将收到一个 Memory 参数。 Memory 将是一个需要解析的 JSON 字符串。因此,请尝试访问:

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

告诉我你是如何处理的。