gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:29:13 24 4
gpt4 key购买 nike

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

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

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

附注:我是 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"
}
}

最佳答案

这个问题可能有帮助:Making an HTTP POST request from fulfillment in Dialogflow 。引用囚徒的回答:

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 Assistant 构建操作,请查看 Google's codelabs Actions on Google 客户端库可能会有所帮助。

关于dialogflow-es - 警告,根据 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56575077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com