0

I’m trying to use the same connection pool to my database from the triggered webhook intent. I'm using the basic boilerplate (https://github.com/actions-on-google/dialogflow-webhook-boilerplate-java).

Every triggered intent does return ActionRequest to me, however, it doesn't contain ServletContext. So, how do I get normal request context using the actions-on-google-java library? (https://github.com/actions-on-google/actions-on-google-java/blob/master/src/main/kotlin/com/google/actions/api/ActionRequest.kt)


I have tried to find alternative ways to get the pool, but my experience with Java is limited.

// 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
    }
    ...
}
Lypyrhythm
  • 324
  • 2
  • 13
tubbelol
  • 1
  • 1
  • Since you said your experience with Java is limited, have you tried using the Node.js client library instead? https://developers.google.com/actions/reference/nodejsv2/overview – Max Wiederholt Jul 08 '19 at 21:27

1 Answers1

0

I don't see the ActionRequest providing the ServletContext, since it's independent of what handles the request.

Not too elegant, but you can create a method in your MyActionsApp (since you are using the basic boilerplate) to set the ServletContext from your request (HttpServletRequest) before you call handleRequest.

Create a constructor to pass that is also an option.