dialogflow-fulfillment-nodejs icon indicating copy to clipboard operation
dialogflow-fulfillment-nodejs copied to clipboard

In Firebase Functions showing Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail - error message

Open Cupidslayer opened this issue 6 years ago • 5 comments

I am creating a bot on Dialogflow, and I am using Dialogflow-fulfillment for dynamic response and Firebase Real-time Database as a database.

What i am trying to do is creating a chatbot for inventory management which query a product from the inventory from a mobile app.

Here are some errors that I am getting in "Firebase Logs": Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail.

const functions = require('firebase-functions'); 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`
    });
}

});`

Here is the 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" } }

Please advise.

Thank you.

Cupidslayer avatar Dec 08 '19 13:12 Cupidslayer

hello, I tried the same tutorial and I have same warning and always responding either (default response) or "product does not exist in inventory" if u found a solution tell me please

FarahBedoui96 avatar Dec 26 '19 18:12 FarahBedoui96

I am facing the same issues if someone find the solution please guide me

krishan1kamal avatar Jun 10 '20 03:06 krishan1kamal

Same issue facing and a weird thing is that I'm fetching the data from the firestore and displaying on the try it now section but on the web demo its not fetching data. Any solution for this.

Ajju2211 avatar Jun 11 '20 14:06 Ajju2211

We are facing similar issue, any one help on this.

AGU1988 avatar Jul 25 '20 07:07 AGU1988

any luck?

sauravotonobots1 avatar Jul 29 '20 15:07 sauravotonobots1