firebase - 在显示警告的 Firebase 函数中,根据 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败 - 错误消息
问题描述
我在部署时确实收到了一条错误消息。在显示警告的 Firebase 函数中,根据 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败
我已经定义了所有的 apikey 等,但数据库没有链接对话流。
请指教。
const functions = require('firebase-functions');
var config = {
apiKey: xxxxx,
authDomain: xxxxx,
databaseURL: xxxxx,
projectId: xxxxx,
storageBucket: xxxxx,
messagingSenderId: xxxxx,
;// your config object could be differ
const admin = require('firebase-admin');
admin.initializeApp(config);
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
const db = admin.database();
const action = request.body.queryResult.action;
if (action === 'product_description') {
const product = request.body.queryResult.parameters.Products.trim();
const ref = db.ref(`products/${product.toLowerCase()}/description`);
ref.once('value').then((snapshot) => {
const result = snapshot.val();
if (result === null) {
response.json({
fulfillmentText: `Product does not exists in inventory`
});
return;
}
response.json({
fulfillmentText: `Here is the description of ${product}: ${result}`,
source: action
});
}).catch((err) => {
response.json({
fulfillmentText: `I don't know what is it`
});
});
} else if(action === 'product_quantity') {
const product = request.body.queryResult.parameters.Products.trim();
const ref = db.ref(`products/${product.toLowerCase()}`);
ref.once('value').then((snapshot) => {
const result = snapshot.val();
if (result === null) {
response.json({
fulfillmentText: `Product does not exists in inventory`
});
return;
}
if (!result.stock) {
response.json({
fulfillmentText: `Currently ${product} is out of stock`,
source: action
});
} else {
response.json({
fulfillmentText: `We have ${result.stock} ${product} in stock`,
source: action
});
}
}).catch((err) => {
response.json({
fulfillmentText: `I don't know what is it`
});
});
} else {
response.json({
fulfillmentText: `I don't know what is it`
});
}
});`
这是我的 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.12.0",
"firebase-admin": "^8.8.0",
"firebase-functions": "^3.3.0",
"dialogflow": "^0.12.1",
"dialogflow-fulfillment": "^0.6.1"
}
}
解决方案
推荐阅读
- ndepend - NDepend 查询以确定正在调用其他 DLL 中的哪些方法
- java - 为 REST 服务中的每个端点创建单独的 SparkSession
- html - 为什么 HTML 表单不支持 PUT 和 DELETE
- r - 将两个向量与公共元素对齐
- slack - 是否可以在 Slack (Linux) 中将单词的一部分加粗?
- javascript - youtube 视频网址不适用于“video-react”npm 模块
- c# - 通过 lambda 创建实例
- hibernate - Spring Boot Data Jpa - @ManyToOne 加入 UUID id
- git - 暂时隐藏 Git 的特定更改
- javascript - 寻找js库推荐