Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Why does the agent.add() function display an empty string
db.findMarami(Scholarship, {}, {scholarship_type:1, _id:0}).then(resultArray => {
      let list = resultArray.map(scholarship => scholarship.scholarship_type);
      final_list.push(list);

      string = final_list.toString();
      //console.log(list.toString());
      console.log(string);
      agent.add(string);
  }).catch((error) => { console.log(error) });

This is a code i have for finding data inside a mongodb schema and i would like to use the value from resultArray to add it into the dialogflow chatbot. Inside the promise, the global variable string changes value but after the query, it seems to be empty. When i use the agent.add() function (for displaying text in the chatbot) it does not update the string at all even if the console.log() displays the value in cmd. (DIALOGFLOW MONGODB NODEJS)

function scholarshipTypes(agent){
    //static data handling should be shown here
 
    agent.add("There are numerous types of scholarships within DLSU. Listed below are the types of scholarships.");
    //mongodb operations to obtain static data from db

      db.findMarami(Scholarship, {}, {scholarship_type:1, _id:0}).then(resultArray => {
      let list = resultArray.map(scholarship => scholarship.scholarship_type);
      final_list.push(list);

        string = final_list.toString();
      //console.log(list.toString());
        console.log(string);
        agent.add(string);
    }).catch((error) => { console.log(error) });

    agent.add("More scholarship details:");
    agent.add(new Suggestion("Deadlines"));
    agent.add(new Suggestion("Requirements"));
    agent.add(new Suggestion("Application Forms"));
  }

Above is the full function used by Dialogflow

        findMarami: function (model, query, projection, callback) {
    return model.find(query, projection);
  },

Here is the code to search the db

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda