【发布时间】:2019-11-20 12:40:35
【问题描述】:
我在 Google Cloud Firestore 中有一个数据库,其中包含一组文档,每个文档都包含以下参数: 国家、标题、网址、日期。
我需要根据 Dialogflow 中的输入返回两个单独的内容。第一个是3条最新消息的头条,第二个是法国3条最新消息的头条。 我将在 Dialogflows 内联编辑器(即 javascript)中执行此操作,但它似乎与 javascript 并不完全相同,例如在节点中。
我已经用下面的代码解决了第一个问题:
function TopNews_Global(agent) {
agent.add('Here are the latest Global news');
let documents = db.orderBy('Date', 'desc').limit(3);
return documents.get()
.then(snapshot => {
snapshot.forEach(doc => {
agent.add('-' + doc.data().Headline + '.');
agent.add('Link:(' + doc.data().URL + ')');
});
return Promise.resolve('Read complete');
}).catch(() => {
agent.add('Error reading entry from the Firestore database.');
});
}
db 是我在 firebase 中的收藏。
以下代码是我要返回的第二件事的解决方案,这就是我卡住的地方。无法像我一样对两个不同的字段进行过滤和排序。但是必须有办法解决这个问题 - 这是我想做的一件非常简单的事情。
https://firebase.google.com/docs/firestore/manage-data/export-import
function TopNews_France(agent) {
agent.add('Here are the latest French news');
let documents = db.orderBy('Date', 'desc').where('Country', '==', 'France').limit(3);
return documents.get()
.then(snapshot => {
snapshot.forEach(doc => {
agent.add('-' + doc.data().Headline + '.');
agent.add('Link:(' + doc.data().URL + ')');
});
return Promise.resolve('Read complete');
}).catch(() => {
agent.add('Error reading entry from the Firestore database.');
});
}
【问题讨论】:
标签: javascript google-cloud-firestore dialogflow-es-fulfillment