我正在Dialogflow上创建一个机器人,并且正在使用Dialogflow实现动态响应并将Firebase实时数据库作为数据库。
我要在这里做的是,假设一家提供某些设施的医院在该国设有几个中心(地点)。现在,当用户请求此类医院时,机器人应能够向他输出附近医院的位置。我在Firebase实时数据库中确实有所有此类医院的列表(具有唯一的经度和纬度)。我的解决方法是,我将获得用户的准确位置,并将其与数据库中可用的位置进行比较,以找到最近的医院。现在,我希望使用Google Place API(我有一个计费帐户和API密钥)向用户输出有关该医院的详细信息(例如医院的地址,联系方式,网站,营业时间等)。
尽管我可以通过经度和纬度获得用户的准确位置,但是在处理Google Place API时仍然遇到一些问题。这是我在“ Firebase日志”中遇到的一些错误:
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
和
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11)
at ServerResponse.header (/var/tmp/worker/node_modules/express/lib/response.js:767:10)
at ServerResponse.send (/var/tmp/worker/node_modules/express/lib/response.js:170:12)
at ServerResponse.json (/var/tmp/worker/node_modules/express/lib/response.js:267:15)
at callPlaceAPI.then.catch (/user_code/index.js:480:34)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
我尝试更改许多不同的初始化firebase-admin的方式,但是上述错误仍然相同。我是这样做的:
var admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://test-dia.firebaseio.com"
});
process.env.DEBUG = 'dialogflow:debug';
甚至是这个:
dmin.initializeApp({
credential: admin.credential.cert({
"type": "service_account",
"project_id": "took from Firebase Generated Private Key",
"private_key_id": "took from Firebase Generated Private Key",
"private_key": "took from Firebase Generated Private Key",
"client_email": "took from Firebase Generated Private Key",
"client_id": "took from Firebase Generated Private Key",
"auth_uri": "took from Firebase Generated Private Key",
"token_uri": "took from Firebase Generated Private Key",
"auth_provider_x509_cert_url": "took from Firebase Generated Private Key",
"client_x509_cert_url": "took from Firebase Generated Private Key"
}),
databaseURL: "https://test-dia.firebaseio.com"
});
process.env.DEBUG = 'dialogflow:debug';
我的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.5.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.0"
}
}
您能帮助我理解问题吗?我的index.js包含600多行代码,不过,我仍提供了指向其的链接供您考虑。此处:https://gist.github.com/shivam-k/49cfd05b36eb52d219f99b20cf285f03
开始阅读代码之前的一些重要事项:
任何有关如何调用Place API和解析结果的建议都将受到赞赏。您的任何建议对我来说都是非常令人鼓舞的。
{
"candidates" : [
{
"formatted_address" : "140 George St, The Rocks NSW 2000, Australia",
"name" : "Museum of Contemporary Art Australia",
"opening_hours" : {
"open_now" : false
},
"photos" : [
{
"height" : 3492,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/105784220914426417603/photos\"\u003eKeith Chung\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAA4fqUuhQuWUh11h_QEJJY5c14dM5V6tRjv9662oZdRxQdyvnmzK6b2ENgL9dtUb_bkSnIUTAzEmxdtJfLFQ1H_eqHDJkkiTedPu664OqkUOtxAfoBPCU01FOI1nN9RifJEhA47TjtbpLsT_yU6mfs8VZKGhRef9lr97rh2asJsCF3XBM-TH-InA",
"width" : 4656
}
],
"place_id" : "ChIJ68aBlEKuEmsRHUA9oME5Zh0"
}
],
"status" : "OK"
}
答案 0 :(得分:0)
只需将package.json中的firebase-admin更新为最新版本。当前f.e .:
....
"dependencies": {
"@google-cloud/firestore": "^0.16.1",
"firebase-admin": "^6.0.0",
"firebase-functions": "^1.0.0",
....
答案 1 :(得分:-1)
我遇到了同样的问题,可以通过选中“意图”页面的“实现”部分中的“启用webhook”按钮来解决此问题,
如果这不起作用,您可能想要克隆此示例项目,然后尝试在其中添加index.js文件。 https://github.com/dialogflow/fulfillment-firestore-nodejs