Chatfuel不解析json返回的整个JSON字符串。欢迎任何帮助。
虽然从API返回的JSON如下所示(在postman中):
{
"messages": [
{
"text": "i think you should study"
},
{
"text": "Mikrobiologi"
}
]
}信使机器人只发送第一条短信。
我的应用程序代码:
router.get('/ask/:question', function(req, res){
var output = [];
var keywords = req.params.question.split(' ');
var answer = qHandler.search(keywords);
answer.then(function(books){
output.push({text: 'i think you should study'})
for (var i = books.length; i > 0; i--){
output.push({text: books[i-1].title});
if (i-1 > 0){
output.push({text: ' and '});
}
};
res.send({messages: output});
});
});我尝试更改顺序,在返回字符串之前和之后添加更多硬编码文本。
在“邮递员”中,一切看起来都是应该的,但是聊天似乎不解析插入书名的文本对象。
发布于 2017-08-04 08:50:53
看起来你的代码是正确的。请确保在不使用answer.then(function(books){下的邮递员的情况下,使用HTTP值获取参数。
这里的我可以在纯javascript中完成这段代码
var books = [
{
title: 'asdfasdf'
},{
title: 'asdfasdf'
},{
title: 'asdfasdf'
},{
title: 'asdfasdf'
},{
title: 'asdfasdf'
}]
var output = [];
output.push({ text: 'i think you should study' })
for (var i = books.length; i > 0; i--) {
output.push({ text: books[i - 1].title });
if (i - 1 > 0) {
output.push({ text: ' and ' });
}
};
console.log(output);https://stackoverflow.com/questions/45501964
复制相似问题