警告,根据GCLOUD_PROJECT估算Firebase配置。初始化firebase-admin可能会失败

时间:2019-06-13 07:07:25

标签: dialogflow actions-on-google

我正在Dialogflow上构建一个机器人,并且正在使用Dialogflow实现。但是,无论何时我部署,都会收到错误消息:

Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail

我正在尝试从代码访问外部API。这是正确的方法吗?还是由于其他原因导致的错误?

P.S .:我是Dialogflow的新手。

这是index.js文件:

'use strict';

const functions = require('firebase-functions');
const request = require('request');
const admin = require('firebase-admin');
admin.initializeApp();
const {dialogflow} = require('actions-on-google');
const app =dialogflow();

function helper() {
   var username = '<USER_NAME>',
     password = '<PASSWORD>',
     sugar_id = '<SUGAR_ID>',
     from_date = '2019-06-10',
     to_date = '2019-06-11',
     url1 = '<SOME_URL_HERE>',
     auth = "Basic " + new Buffer.from(username + ":" + password).toString("base64");
  return new Promise((resolve, reject)=> {
    request(
         {
             url : url1,
             headers : {
                 "Authorization" : auth,
                 'x-api-key': '<API_KEY>',
                 'x-source': '<X_SOURCE>'
             }
         },
         (error, response, body) => {
             if(error) throw error;
            console.log('success 1');
             // console.log(JSON.parse(response.body));
             var obj = JSON.parse(body);
             if(obj.data!==null) {
                 // console.log(obj.data[0].booking_id);
                 var latest_booking_id = obj.data[0].booking_id;
                 var url2 = '<SOME_URL_HERE>';

                 request(
                     {
                         url: url2,
                         headers : {
                             "Authorization" : auth,
                             'x-api-key': '<API_KEY>',
                             'x-source': '<X_SOURCE>'
                         }
                     },
                     (error, response, body) => {
                         if(error) throw error;
                       console.log('success 2');
                         var obj = JSON.parse(body);
                       if(error) reject(error);
                       console.log(obj);
                       resolve(obj);
                     }
                 );
             } else {
                 console.log('No booking found.');
             }

         }
     );

  });
}   

app.intent('customer details', (conv) => {
  helper().then((res)=> {
    conv.ask(res);
  }).catch((err)=> {
    throw (err);
  });
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

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.9.1",
    "firebase-functions": "^2.0.2",
    "request": "^2.88.0"
  }
}

1 个答案:

答案 0 :(得分:1)

该问题可能会有所帮助:Making an HTTP POST request from fulfillment in Dialogflow。引用囚犯的答案:

  

通过网络调用使用promise的最简单方法是使用程序包   例如request-promise-native。使用此代码,您的代码可能看起来   像这样:

var options = {
  uri: url,
  method: 'POST',
  json: true,
  headers: { ... }
};
return rp(options)
  .then( body => {
    var val = body.someParameter;
    var msg = `The value is ${val}`;
    agent.add( msg );
  });

我注意到您需要actions-on-google库。如果您要为Google助手构建操作,请查看Google's codelabs以了解Google客户端库上的操作。