node.js - 自动驾驶仪和功能收集数据他
问题描述
我在自动驾驶仪中有一个任务,它从调用者那里收集数据,然后使用重定向调用一个函数。我似乎无法访问帖子变量。请协助。
所以当运行这个我得到以下错误
错误 - 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-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
任务……>
{
"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"
}
}
}
}
]
}
功能......>
// 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 to the 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.
推荐阅读
- javascript - 检查脚本是否已加载(并且对象存在于窗口空间中)的最佳实践?
- html - Textarea占位符字体大小html css
- android - 在 Android 上将一个 TextView 放在另一个 TextView 旁边以获得更长的文本
- netsuite - Suitescript - 无法更新销售团队 - salesrep
- prolog - 矩阵的Prolog行列式(递归)
- r - 在 Plotly R 中查看重叠散点的悬停信息
- python - 为什么 form._errors 在 generic.UpdateView 中工作,但在 generic.CreateView 中没有?
- sql - 选择字符串值前后的数字 - Presto SQL
- react-native - 单击另一个 BottomTabNavigatorTab 后,“重置”stackNavigator
- php - 如何解决 Google v3 reCaptcha 超时?