actions-on-google / actions-on-google-java

Java/Kotlin library for Actions on Google
Apache License 2.0
286 stars 39 forks source link

How to programmatically fetch parameter from a parent intent for use in a follow-up intent #24

Closed fitsie007 closed 5 years ago

fitsie007 commented 5 years ago

What is the best way to retrieve a parameter from a parent context for use in a follow-up intent in actions-on-google? The DialogFlow documentation shows how to retrieve a parameter manually (https://dialogflow.com/docs/contexts/input-output-contexts), but I would like to access a parameter at a certain depth/lifespan within a series of follow-up intents. For example, I have tried something like the following, but it doesn't work.

@ForIntent("third-context-followup")
   public ActionResponse myIntent(ActionRequest request) {
String param1 = (String) request.getParameter("second-custom-followup.param");
String param2 = (String) request.getParameter("first-context.second-custom-followup.param");
...
}
Fleker commented 5 years ago

You probably want to use session storage:

public ActionResponse simpleResponseAppData(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  Map<String, Object> data = request.getConversationData();
  data.put("count", 1);
  return responseBuilder
      .add("Hi there, what can I help you with today?")
      .build();
}
fitsie007 commented 5 years ago

I intend to do something like the following: example_follow_up_intent_goal

The conversation will flow with textual training responses until about the fourth follow-up. I would then like to access the parameter, from say the second-follow-up, using a web-hook. Are you saying I would have to convert the intent that gets the parameter to one that uses a web-hook in order to access contextual parameters? I thought since the parameter is in the context, I would be able to access it without making an additional web-hook with session storage.

aradwyr commented 5 years ago

Closing due to no direct issue with the client library itself. This is a general question and is better suited for Stack Overflow -- Github issues are for reporting bugs contained in Actions on Google samples or client libraries, thank you for understanding.