【问题标题】:How to read data from firebase realtime database to Dialogflow如何从firebase实时数据库读取数据到Dialogflow
【发布时间】:2020-05-24 08:00:19
【问题描述】:

我是新手,我想知道如何将数据从 firebase 实时数据库读取到对话流。我想比较 DNI(id) 并从该表中获取只有该 DNI(id) 具有的信息。

这是我的代码:

      function askReunion(agent)
      {
      const dni = agent.parameters.dni ; 
        agent.add(`Wait a minute...`);
          return admin.database().ref('reunion').once("value").then((snapshot) => {
            var dniBd = snapshot.child("dni").val();
            if( dni == dniBd){
              agent.add(`here I will put the information of the dni ` );
            }
            else{
              agent.add(`You dont have any appointment. ` );
            }
          });
      }

这是我要读取结果的表格:

【问题讨论】:

    标签: firebase firebase-realtime-database dialogflow-es


    【解决方案1】:

    问题是您对once('value') 的调用正在从数据库中获取“重聚”对象的快照。该对象的所有子对象都具有诸如“-M84_ViEcYi0UzQifWhq”之类的名称。

    但是你正在检查一个名为“dhq”的孩子,并且没有这个名字的孩子。 每个子确实有一个同名的属性,但这不是你的代码得到的。

    听起来您可能想要针对每个子项的属性执行query,而不是执行引用获取。假设“dni”是唯一的,这可能看起来像这样:

    const ref = admin.database().ref('reunion');
    return ref.orderBy("dni").equalTo( dni ).once("value").then( snapshot => {
      if( snapshot.exists() ){
        agent.add( "Ok, I found your record." );
      } else {
        agent.add( "I don't have any record of that." );
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 2020-03-11
      • 2023-02-23
      相关资源
      最近更新 更多