【发布时间】:2022-12-12 12:43:55
【问题描述】:
下午好 我需要帮助,因为下面显示的设计程序设法将信息传输到控制台日志,但无法通过 agent.add 函数将其发送到 dialogflow。 mongo db 数据库中是人员的姓名、部门、职位和邮件等信息。它将从 dialogflow 接收位置和部门,并且程序必须能够在 mongodb 数据库中搜索满足这两个要求的人并将所有信息发送回 dialogflow。我认为关键是使用 find() 函数,然后知道如何将该信息放入数组,但我不知道如何操作。任何帮助表示赞赏。 (假设连接到 moongose 的所有功能都正常。)
function ConsultarDepartament(agent) {
var departament = agent.parameters.departamentos;
var cargo = agent.parameters.cargodepartamento;
contactodepartamento.find({departament : 'departament', cargo : 'cargo'})
.exec((err, res)=>{
if(err) return console.log('Error ' + err)
else console.log(res);
});
agent.add('The name and email of the person you are looking for is: '+);
}
`
++ 来自函数的结果是一个存储在“res”中的数组,来自 mongodb: { _id 6*** 部门:“自动”。 货物:“导演” 名称:“D*** 邮件:“d***” } 问题是我不知道如何从来自 mongodb 的变量“res”中获取名称和邮件并将其放入 agent.add 以将其发送到 Dialogflow。
++++ 存储在来自 mongodb 数据库的数组 (res[0].name) 中的值必须使用 agent.add 发送到 dialogflow。事实证明,在 visual studio 控制台中,值 res[0].name 显示正确,但是当您将其添加到 agent.add('The name is: '+res[0].name) 时,dialogflow 中的结果不是可用的。有谁知道你是否需要某种转换器?
【问题讨论】:
-
看起来你的代码有错误。您能否尝试将
agent.add('The name and email of the person you are looking for is: '+);更改为agent.add('The name and email of the person you are looking for is: ');。抱歉,如果您已经尝试过,或者这不是您的重点。 -
您好,感谢您的评论。来自该函数的结果是一个存储在“res”中的数组,来自 mongodb:{ _id 6*** department:“Automatic”。 cargo : "Director" name: "D*** mail: "d***" } 问题是我不知道如何从来自 mongodb 的变量 "res" 中获取名称和邮件以及将其放入 agent.add 以将其发送到 Dialogflow。
标签: node.js mongodb promise dialogflow-es dialogflow-es-fulfillment