1

I'm doing a chatbot similar to helpdesk (Dialogflow - inline editor). I'm able to write to datastore but I`m facing some issues with read out of data, it is a basic operation of finding UserID but code is not kicking off -please help code below.

const Datastore = require('@google-cloud/datastore');
const datastore = new Datastore({
  projectId: 'bot-datastore-mnddjv'
});


      function write(agent) {
        var name = agent.parameters.name;
        var sur = agent.parameters.sur;
        var uid = agent.parameters.uid;
        const taskKey = datastore.key('Key');
        const entity = {
          key: taskKey,
          data: {
            name: name,
            sur: sur,
            uid: uid
          }
        };
        return datastore.save(entity).then(() => {
          console.log(`Saved ${entity.key.name}: ${entity.data.item_name}`);
          agent.add(`Stored ${name},${sur}`); -----> That part is working

        });
      }

      function read(agent){
        const query = datastore.createQuery('Key').filter('name');

        return datastore.runQuery(query).then(() =>{
          const sortA = query.order('name');
          const sortD = query.order('name',( {descending:true})); 
          agent.add("Scores: ",sortA); ----//  This funcion is not working 
        });
      }   

  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('Zapis', write);
  intentMap.set('Odczyt', read);

  agent.handleRequest(intentMap);
});
Tomek J
  • 11
  • 2
  • Can you update your question to show how you are declaring `datastore`, and any libraries that you may be importing? It isn't clear which "datastore" you're using, or its exact configuration. The more information you can provide, the better chances we have of being able to help. – Prisoner Jan 22 '20 at 21:05
  • Thanks for quick review, code is updated . – Tomek J Jan 22 '20 at 21:16

1 Answers1

1

The issue seems to be in your usage of filter().

You need to use an operator like =, > etc. so if that condition is met the query will run.

Here is a sample code from the documentation.

const query = datastore
  .createQuery('Task')
  .filter('done', '=', false)
  .filter('priority', '>=', 4)
  .order('priority', {
    descending: true,
  });
Waelmas
  • 1,894
  • 1
  • 9
  • 19