dialogflow / dialogflow-fulfillment-nodejs

Dialogflow agent fulfillment library supporting v1&v2, 8 platforms, and text, card, image, suggestion, custom responses
Apache License 2.0
597 stars 282 forks source link

How can I transfer the information from mongodb database to dialogflow with node.js? #347

Open usuario12345679 opened 1 year ago

usuario12345679 commented 1 year ago

Good afternoon I need help because the designed program shown below manages to transfer the information to the consolelog but it is not able to send it to dialogflow through agent.add function. In mongo db database is the information of people with name, department, position and mail. From dialogflow it will receive the position and the department, and the program must be able to search in the mongodb database a person who fullfils those two requirements and send all the information back to dialogflow. I think the key is to use the find() function and then know how to take that information to an array, but I don't know how. Any help is appreciated. (All functions for connecting to moongose are assumed to be OK.)

`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: '+);
     }`
usuario12345679 commented 1 year ago

++ The result coming from the function is an array stored in "res" as coming from mongodb: { _id 6 department : "Automatic". cargo : "Director" name: "D mail: "d***" } The problem is that I don't know how to get from the variable "res" that comes from mongodb, the name and the mail and put it in agent.add to send it to Dialogflow.

usuario12345679 commented 1 year ago

A value that is stored in an array (res[0].name) coming from the mongodb database, has to be sent to dialogflow by using agent.add. It turns out that in the visual studio console the value res[0].name appears correctly, but when you add it in agent.add('The name is: '+res[0].name) the result in dialogflow is NOT AVAILABLE. Does anyone know if you need some kind of converter?