警告,根据GCLOUD_PROJECT估算Firebase配置。 初始化firebase-admin可能会失败
在Firebase
功能日志中获取此错误:
我正在尝试读取Dialogflow中Firebase-Cloud Firestore数据库中的数据。但是无法连接到数据库,并且无法获得日志中的错误。
欢迎使用代码-内联编辑器(由Cloud Functions for Firebase支持)
Cloud Firestore中的集合名称-用户 文档-10和11(共2个) 字段-book_id和文本
有人可以帮我解决这个问题或面临类似问题吗?
我曾尝试为其他人遇到的错误提供不同的解决方案,但没有一个解决了我的问题。
package.json
中的节点版本更改为8 尝试Initializeapp
如下:
const admin = require('firebase-admin');
const app = dialogflow({debug: true});
admin.initializeApp();
它本身不会进入app.intent(welcome)
index.js
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const axios = require('axios');
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
const app = dialogflow({debug: true});
admin.initializeApp();
const db = admin.firestore();
db.settings({timestampsInSnapshots: true});
const collectionRef = db.collection('users');
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?`);
}
app.intent('welcome', (conv) => {
console.log("welcome agent invoked");
const book = (agent.parameters.book).toString();
const termRef = collectionRef.doc('10');
return termRef.get()
.then((snapshot) => {
const {text, book_id} = snapshot.data();
conv.ask(`Here you go, ${text}, ${book_id}. ` +
`What else do you want to know?`);
console.log('text:', +text);
console.log('book_id:', +book_id);
}).catch((e) => {
console.log('error:', e);
conv.close('Sorry, try again');
});
});
});
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": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
}
尝试从Cloud Firestore中的集合用户那里获取book_id
的值和文本值