使用对话流程从数据存储中读取数据

问题描述 投票:0回答:1

我正在做一个类似于帮助台的聊天机器人(Dialogflow-内联编辑器)。我可以写入数据存储区,但是读取数据时会遇到一些问题,这是查找UserID的基本操作,但是代码并未启动-请在下面提供帮助代码。

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);
});
firebase google-cloud-firestore integration dialogflow datastore
1个回答
0
投票

问题似乎出在您使用filter()

您需要使用=,>等运算符,因此如果满足该条件,查询将运行。

这里是documentation的示例代码。

const query = datastore
  .createQuery('Task')
  .filter('done', '=', false)
  .filter('priority', '>=', 4)
  .order('priority', {
    descending: true,
  });
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.