【发布时间】:2019-06-01 11:32:22
【问题描述】:
我正在 Dialogflow 上创建一个机器人,我正在使用 Dialogflow-fulfillment 进行动态响应,并将 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
开始阅读代码之前的一些重要事项:
- 您感兴趣的代码从第 353 行开始。因为只有在那之后,我才会获取位置并调用 Google Place API。
- 您在上一封电子邮件中提到的解析结果的方法由两部分组成。
- 从主函数调用包含解析结果的函数。不过,我仍然没有得到任何结果。
- 从主函数调用包含解析结果的函数从第 451 行开始。
- 包含调用 Place API 和解析结果的函数从第 499 行开始。
- 从对 testAPI 的调用中收到的 JSON(我出于测试目的从文档中获取)如下。
任何关于如何调用 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"
}
【问题讨论】:
标签: firebase-realtime-database google-places-api dialogflow-es