【发布时间】:2019-05-08 07:42:59
【问题描述】:
我想将 Dialogflow 中的自定义聊天机器人与 PostgreSQL 数据库连接起来。场景是用户将他/她的查询提交给机器人,然后它将 SQL 查询提交给数据库。我知道应该使用 Webhook/Fulfillment and Integration,但问题是如何。
直到现在,我都尝试在 Fulfillment/Inside Editor 中通过放置...
const pg = require('pg');
const connectionString = process.env.DATABASE_URL || 'postgres://un:pass@localhost:5432/postgres';
const client = new pg.Client(connectionString);
client.connect();
const query = client.query('CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
query.on('end', () => { client.end(); });
...进入 index.js。此外,在尝试使用 Google Assistant 时,我总是会收到 Webhook 错误,但没有任何指示性解释:
textPayload: "MalformedResponse: Webhook error (206)"
我不想将机器人连接到其他中间网站;聊天机器人应该能够自己进行查询和检查数据库。
有人对我有什么建议吗? 谢谢!
日志摘录如下:
7:10:03.013 PM
dialogflowFirebaseFulfillment
Ignoring exception from a finished function
7:10:02.995 PM
dialogflowFirebaseFulfillment
Function execution took 10 ms, finished with status code: 200
7:10:02.986 PM
dialogflowFirebaseFulfillment
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:10:02.986 PM
dialogflowFirebaseFulfillment
Function execution started
7:09:49.540 PM
dialogflowFirebaseFulfillment
Ignoring exception from a finished function
7:09:48.543 PM
dialogflowFirebaseFulfillment
Function execution took 865 ms, finished with status code: 200
7:09:47.678 PM
dialogflowFirebaseFulfillment
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:09:47.678 PM
dialogflowFirebaseFulfillment
Function execution started
7:09:12.659 PM
dialogflowFirebaseFulfillment
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
7:08:41.442 PM
dialogflowFirebaseFulfillment
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
7:04:51.279 PM
dialogflowFirebaseFulfillment
Ignoring exception from a finished function
7:04:51.238 PM
dialogflowFirebaseFulfillment
Function execution took 896 ms, finished with status code: 200
7:04:50.343 PM
dialogflowFirebaseFulfillment
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
7:04:50.343 PM
dialogflowFirebaseFulfillment
Function execution started
7:04:33.195 PM
dialogflowFirebaseFulfillment
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
【问题讨论】:
-
嗨,你的 package.json 中包含 pg 了吗?
-
此外,您将无法连接到在 localhost:5432 上运行的 postgres 的本地实例。您必须使用托管的 postgres 服务。
-
我确实将 pg 添加到依赖项中,仍然一样。是的,我确实在 localhost:5432 使用它。 :( 谢谢。您认为使用其他数据库会更好/可以在本地设置?
-
您可以在 ElephantSQL 上设置 postgres 或在 mlab 上设置 MongoDB 并在全球范围内使用它!
-
如果您使用的是内联编辑器,您能否通过单击部署附近的履行页面上的查看执行日志来发布日志截图