【问题标题】:Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail警告,基于 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败
【发布时间】:2019-06-13 07:07:25
【问题描述】:

我正在 Dialogflow 上构建一个机器人,并且我正在使用 Dialogflow-fulfillment。但是,每当我部署时,我都会收到错误消息:

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"
  }
}

【问题讨论】:

    标签: dialogflow-es actions-on-google


    【解决方案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 以了解 Actions on Google 客户端库可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 2019-11-08
      • 1970-01-01
      • 2019-06-14
      • 2021-12-20
      • 2019-09-29
      • 2018-05-23
      • 2019-04-23
      • 2021-01-23
      相关资源
      最近更新 更多