警告,正在根据 GCLOUD_PROJECT 估算 Firebase 配置。初始化 firebase-admin 可能会失败
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
我正在 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"
}
}
这个问题可能有帮助:。引用 Prisoner 的回答:
The easiest way to use promises with network calls is to use a package
such as request-promise-native. Using this, your code might look
something like:
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 客户端库上的操作可能会有所帮助。
我正在 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"
}
}
这个问题可能有帮助:
The easiest way to use promises with network calls is to use a package such as request-promise-native. Using this, your code might look something like:
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 客户端库上的操作可能会有所帮助。