【发布时间】:2019-07-05 08:48:05
【问题描述】:
我正在尝试从触发的 webhook 意图使用与我的数据库相同的连接池。我正在使用基本样板文件 (https://github.com/actions-on-google/dialogflow-webhook-boilerplate-java)。
每个触发的意图都会向我返回ActionRequest,但是,它不包含ServletContext。那么,如何使用actions-on-google-java 库获得正常的请求上下文? (https://github.com/actions-on-google/actions-on-google-java/blob/master/src/main/kotlin/com/google/actions/api/ActionRequest.kt)
我已尝试寻找其他方法来获取池,但我对 Java 的经验有限。
// this is what i would like to achieve but ActionRequest is limited
@ForIntent("DB test")
public ActionResponse DbTest(ActionRequest request)
{
...
DataSource pool = (DataSource) request.getServletContext().getAttribute("my-pool");
try (Connection conn = pool.getConnection())
{
// do database stuff
}
...
}
【问题讨论】:
-
既然您说您对 Java 的经验有限,您是否尝试过改用 Node.js 客户端库? developers.google.com/actions/reference/nodejsv2/overview
标签: java dialogflow-es actions-on-google google-home dialogflow-es-fulfillment