首页 > 解决方案 > 无法将 DialogFlow 与 Firestore 集成

问题描述

我想在我的 DialogFlow 机器人中使用 Firestore,但它显示了某些错误。这是我的 index.js 代码:

function writeToDb () {
    console.log(`Inside writeToDb`);
    // Get parameter from Dialogflow with the string to add to the database
    const databaseEntry = {
        'eMail':'shashank@gmail.com'
    };

    console.log(databaseEntry);
    // Get the database collection 'dialogflow' and document 'agent' and store
    // the document  {entry: "<value of database entry>"} in the 'agent' document
    const dialogflowAgentRef = db.collection('dialogflow').doc('agent');
    return db.runTransaction(t => {
      t.set(dialogflowAgentRef, {entry: databaseEntry});
      return Promise.resolve('Write complete');
    }).then(doc => {
      agent.add(`Wrote "${databaseEntry}" to the Firestore database.`);
    }).catch(err => {
      console.log(`Error writing to Firestore: ${err}`);
      agent.add(`Failed to write "${databaseEntry}" to the Firestore database.`);
    });
  }

这是我的 package.json:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "8"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0",
    "i18n" : "^0.8.4",
    "@google-cloud/firestore": "^0.16.1",
    "firebase-admin": "^6.0.0"
  }
}

这些是我得到的错误:

Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
Billing account not configured. External network is not accessible and quotas are severely limited. 
Configure billing account to remove these restrictions

我已经在我的 Firestore 中制作了一个“对话流”集合和一个“代理”文档。

标签: firebasegoogle-cloud-firestoredialogflow-es

解决方案


这些都不是错误,不应阻止您的 webhook 实现工作。

“估计 Firebase 配置”错误只是表示您没有明确设置 Firebase 配置,因此它根据环境做出一些假设 - 最值得注意的是,您正在使用云函数,因此假设相同项目并访问其他项目默认设置。如果您使用管理员访问同一项目中的数据库,这应该没问题。

关于“未配置计费帐户”的消息意味着 - 默认情况下,您使用的是Spark 计划,该计划限制了它每天可以拨打多少电话,并且只能访问 Google 的网络。由于您的代码看起来只是使用 Firestore,这应该不是问题,但如果您需要访问网络外部(或者当您的使用率非常高时),您需要升级到 Blaze 计划,其中包括Spark 计划的免费层,但允许外部网络访问。


推荐阅读