如何从 firebase 实时数据库读取数据到 Dialogflow
How to read data from firebase realtime database to Dialogflow
我是新手,我想知道如何从 firebase 实时数据库读取数据到 dialogflow。我想比较 DNI(id) 并从 table 中获取只有 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. ` );
}
});
}
这是我要阅读结果的 table:
问题是您对 once('value')
的调用正在从数据库中获取 "reunion" object 的快照。这个object的所有children名字都是“-M84_ViEcYi0UzQifWhq”。
但是 您随后正在检查一个名为 "dhq" 的 child,并且没有 child 具有此名称。 Each child 确实有一个 属性 这个名字,但这不是你的代码得到的。
听起来您可能想要针对每个 children 的属性执行 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." );
}
});
我是新手,我想知道如何从 firebase 实时数据库读取数据到 dialogflow。我想比较 DNI(id) 并从 table 中获取只有 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. ` );
}
});
}
这是我要阅读结果的 table:
问题是您对 once('value')
的调用正在从数据库中获取 "reunion" object 的快照。这个object的所有children名字都是“-M84_ViEcYi0UzQifWhq”。
但是 您随后正在检查一个名为 "dhq" 的 child,并且没有 child 具有此名称。 Each child 确实有一个 属性 这个名字,但这不是你的代码得到的。
听起来您可能想要针对每个 children 的属性执行 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." );
}
});