错误-警告,缺少FIREBASE_CONFIG环境变量.初始化firebase管理将失败



我试图将现有的firestore数据库连接到Dialogflow实现。该函数已成功部署到Google CLoud函数,但我无法将数据添加到我的数据库中。我曾尝试更改节点版本8,但仍然失败。请帮帮我。

索引.js

'use strict';
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

admin.initializeApp({
apiKey: "Axxxx",
authDomain: "/xxxxx.firebaseio.com",
databaseURL: "https:/xxxxxx.firebaseio.com",
projectId: "mxxxxx8",
storageBucket: "xxxxx.com",
});
const functions = require('firebase-functions');
const settings = {timestampsInSnapshots: true};
var db = admin.firestore();
admin.firestore().settings({ timestampsInSnapshots: true });

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

function welcome(agent) {
agent.add(`Welcome to my agent!`);
}

function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}

// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});

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-admin": "~7.1.1",
"firebase-functions": "^2.2.1",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}

解决方案是将您的Firebase项目计划升级为Blaze plan。然后在Firebase项目下创建一个新的Dialogflow代理。

您的Firebase初始化似乎是错误的。以下是你应该怎么做:

.
.
.
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});
.
.
.

这应该行得通。

根据文档,应该是这样的

serviceAccount = require('./serviceAccount.json');
const adminConfig = JSON.parse(process.env.FIREBASE_CONFIG);
adminConfig.credential = admin.credential.cert(serviceAccount);
admin.initializeApp(adminConfig);

最新更新