我正在研究一个dialogflow代理,并使用实现从Firestore中获取数据。 我有一个名为 Users 的Firestore集合,其中包含名称和位置字段。但是正在收到导致数据获取失败的错误。
警告,根据GCLOUD_PROJECT估算Firebase配置。 初始化firebase-admin可能会失败
代理商的履行代码如下
'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
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));
var name='';
var location='';
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
function getUserDetails(agent)
{
name= agent.parameters.name;
location=agent.parameters.location;
console.log("buyer name is " + name);
db.collection("Users").doc("101").set({
name: name,
location:location});
agent.add(`User has been inserted`);
}
intentMap.set('Buy Car', getUserDetails);
agent.handleRequest(intentMap);
})
答案 0 :(得分:1)
不建议使用Firebase Admin SDK的这种初始化形式:
admin.initializeApp(functions.config().firebase);
您应该这样初始化:
admin.initializeApp();