您好,我正在使用json将mysql查询中的数据发送回facebook bot,我只是想知道这看起来是否正确,因为我无法使数据显示在结果区域中
app.get("/Getcompany", function(request, response) {
const cname = request.query.cname, query = `select * from clientdata_nsw where companyname = ${connection.escape(
cname
)}`;
connection.query(query, function(err, rows) {
if (err) {
console.log(err);
return;
}
console.log(cname);
rows.forEach(function(result) {
console.log(
result.companyname,
result.service,
result.phone,
result.open_times,
result.rating_facebook,
result.rating_goggle
);
});
response.json({
"version": "v2",
"content": {
"messages": [
{
"type": "text",
"text": "Company: {{result.companyname}}\nPhone: {{result.phone}}\nService: {{result.service}}\nOpen: {{result.open_times}}\nFacebook: {{result.rating_facebook}} Star\nGoogle: {{result.rating_goggle}} Star",
}
]
}
})
});
})