【问题标题】:Read data from Firebase in Dialogflow在 Dialogflow 中从 Firebase 读取数据
【发布时间】: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


    【解决方案1】:

    configuring the fulfillment 可以为您的代理提供此服务。

    1. 转到意向,选择您的意向,然后向下滚动到履行部分。
    2. 点击为此意图启用 webhook 调用(参见 Custom webhook)。
    3. 创建 webhook(您可以在 Fulfillment - 内联编辑器中启用 inline editor 以执行此操作)。
    4. 在您的 webhook 中,查询 Firestore(请参阅 this answer)。

    请注意,任何人都可以知道您的数据库中是否存在用户。 如果您正在为 Google 助理构建,请查看account linking

    【讨论】:

    • 它没有用,但你可以参考我的代码并查看我的错误函数 SaveName (agent){ store.collection('names').doc('value').get().然后(doc => { if (doc.exists) { console.log(doc.data()); res.send(doc.data()); } else { res.send("Nothing"); } }) .catch(reason => { console.log(reason); res.send(reason); }); }
    • 您能否使用代码示例工具将您的代码包含在问题中,而不是链接屏幕截图?它会让你更容易帮助到你!
    【解决方案2】:

    我遇到了一些类似的问题,即在代理交互中未显示获取的详细信息。这也发生在给定here 的模板上。然后,我只是从 ReadFromFirestore Intent 中删除了响应,并得到了预期的提取查询。我再次尝试将响应放回去并调用意图,并​​且响应在默认响应和 firestore 查询响应之间交替出现。 尽管如此,不让它对我有用,并且认为也会对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      • 1970-01-01
      • 2018-03-26
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多