错误-警告,缺少FIREBASE_CONFIG环境变量.初始化firebase-admin将失败 [英] Error- Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
本文介绍了错误-警告,缺少FIREBASE_CONFIG环境变量.初始化firebase-admin将失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将现有的Firestore数据库连接到Dialogflow实现.该函数已成功部署到Google CLoud Function,但是我无法将数据添加到数据库中.我试图更改节点版本8,但仍然失败.请帮助我.
I tried to connect my existing firestore database to Dialogflow fulfillment. The function deployed to Google CLoud Function successfully but I cannot add data to my database. I have tried to change the node version 8 but still failed. Please help me.
Index.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代理.
The solution is upgrade your Firebase project plan to Blaze Plan. Then make a new Dialogflow agent under that Firebase project.
这篇关于错误-警告,缺少FIREBASE_CONFIG环境变量.初始化firebase-admin将失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文