无法将 DialogFlow 与 Firestore 集成

Not able to integrate DialogFlow with 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 中创建了一个 'dialogflow' 集合和一个 'agent' 文档。

这些都不是错误,也不应该阻止您的 webhook fulfillment 工作。

"estimating Firebase Config" 错误只是说您没有明确设置 Firebase 配置,因此它根据环境做出一些假设 - 最值得注意的是,您正在使用 Cloud Functions,所以它假设同一个项目并访问其他项目的默认设置。如果您在同一项目中使用管理员访问数据库,这应该没问题。

有关 "Billing account not configured" 的消息仅表示 - 默认情况下您使用的是 Spark Plan,它对每天可以拨打的电话数量有限制,并且只能访问 Google的网络。由于您的代码看起来只是在使用 Firestore,这应该不是问题,但是如果您需要访问外部网络(或者当您的使用率非常高时),则需要升级到 Blaze 计划,其中包括Spark Plan 的免费套餐,但允许外部网络访问。