【发布时间】:2019-11-18 16:16:51
【问题描述】:
我正在构建一个聊天机器人,但在 Dialogflow 中从 Firebase 获取数据时遇到了问题。
我希望用户输入他的姓名,让机器人查询 Firebase 并检查姓名是否存在。如果是 “用户存在” 否则 “用户 n 不在数据库中”。
[这是目前使用的代码][1]
function SaveName(agent){
const number = agent.parameters.number; // when I input the number in Fialogflow
const docRef = db.collection('names').doc(sessionId);
return docRef.get()
.then(doc => {
if (!doc.exists) {
agent.add('No data found in the database!');
console.log(doc);
} else {
agent.add(doc.data().orders);
}
return Promise.resolve('Read complete');
}).catch(() => {
agent.add('Error reading entry from the Firestore database.');
agent.add('Please add a entry to the database first by saying, "Write <your phrase> to the database"');
});
}
【问题讨论】:
标签: dialogflow-es chatbot dialogflow-es-fulfillment