Search code examples
javadialogflow-esactions-on-googlegoogle-assistant-sdkgoogle-home

Send requests to Google Assistant from Java


We have developed a Google Action with Dialogflow that responds to personalized requests from users and performs some tasks that require a certain amount of time, usually several minutes.

Our goal is to announce the result of the tasks using the "Broadcast" feature of Google Assistant, but we can't find a way to send the command to Google Assistant.

Our agent receives the user's request and launches a Java application that executes the task, so it is the Java application that must communicate with Google Assistant when the process is finished.

From the Java application we can communicate with the agent using Dialogflow RPC API, but not with Google Assistant.

Is there any way to send the request to Google Assistant from the Java app? or... since we can communicate with our Google Action Agent... how could we send the request through the agent?

In other words, could the agent communicate with google assistant to use any of its features, for example, "Broadcast ..."?

We have checked Google Assistant SDK as alternative, but we are confused about it.

Please, excuse me for my bad English.

Any help would be appreciated. Thanks!


Solution

  • The "Broadcast" feature is not available to user-developed Actions, and probably not a good scheme to use in any event - if users will need to wait for a while for an answer, they probably don't want the answer suddenly announced when they're not expecting it.

    Actions are typically meant to be conversational, rather than taking a while to reply with the answer, which is why there is a 5 second limit on how long the fulfillment has to do processing. If you do need to take a while, you have a few options available to you:

    First is that you can use some other method outside of the Assistant to deliver the answer - possibly using something like Firebase Cloud Messaging or sending email to the user.

    Similarly, you might be able to use notifications. In this scenario, your Java program would send a notification through the Assistant to the user when the information is available and store the result. The user can then activate the notification to continue the conversation and get the result. This has the advantage that the answer isn't just blurted out, possibly when the user isn't ready for it, but does have a downside that speakers don't (yet) support notifications.

    You can also look into using a Media Response to set up a way for you to poll for new messages periodically. Under this scheme, you would fire off the Java program which would get the result and then store this in a way your fulfillment server can access. In your reply to the user saying you're working on the results, you would include a Media Response for some audio that plays for, say, 15 seconds. When the audio finishes, your Action will be called again and you can check to see if the result is available. If so, you send the result and continue or end the conversation. Otherwise, just send a Media Response.