使用 Twilio 函数将 JSON 解析为数组 javascript [英] Parse JSON into array javascript with Twilio Function
问题描述
尝试创建一个聊天机器人,它会在中途访问网络服务并根据之前的回复提出问题.
Attempting to create a chat bot that will hit a web service midway through and ask questions based on previous responses.
我创建了一个函数,该函数将返回一组人员,然后我将输入这些姓名并要求用户选择一个.
I have created a function that will return an array of people that I will then text these names and ask the user to pick one.
Twilio 函数
exports.handler = function(context, event, callback) {
const employees = [{ name: 'Mark', id:15 }, { name: 'Scott', id:16 }, { name: 'Steve', id:17 }];
callback(null, employees);
};
我希望这会返回 function_1.parsed 值,但所有内容都存储在 function_1.body 中,我无法按我希望的方式访问它.
I would hope this would return function_1.parsed values, but everything is stored in function_1.body and I can't access it the way I hoped.
这是我的日志视图.
有人知道我如何将它发送到 Parsed 而不是 body 吗?如果我提交一个简单的对象,它将返回解析后的值.
Anyone know how I can send this to Parsed instead of body? If I submit a simple object it will return to the parsed value.
exports.handler = function(context, event, callback) {
const employee = { name: 'Mark', id:15 };
callback(null, employee);
};
推荐答案
这里有诀窍,将它包装在一个对象中:
here is the trick, Wrap it in an object:
{"result":
[{ name: 'Mark', id:15 }, { name: 'Scott', id:16 }, { name: 'Steve', id:17 }]
};
这篇关于使用 Twilio 函数将 JSON 解析为数组 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!