简体   繁体   English

从Java向Google Assistant发送请求

[英]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. 我们开发了带有Dialogflow的Google Action,可响应用户的个性化请求并执行一些需要一定时间(通常为几分钟)的任务。

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. 我们的目标是使用Google Assistant的“广播”功能宣布任务的结果,但是我们找不到将命令发送到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. 我们的代理会收到用户的请求并启动执行任务的Java应用程序,因此,该Java应用程序必须在完成该过程后与Google Assistant进行通信。

From the Java application we can communicate with the agent using Dialogflow RPC API , but not with Google Assistant. 在Java应用程序中,我们可以使用Dialogflow RPC API与代理进行通信,但不能与Google Assistant进行通信。

Is there any way to send the request to Google Assistant from the Java app? 是否可以通过Java应用程序将请求发送到Google Assistant? or... since we can communicate with our Google Action Agent... how could we send the request through the agent? 或...由于我们可以与我们的Google Action Agent通信...我们如何通过该代理发送请求?

In other words, could the agent communicate with google assistant to use any of its features, for example, "Broadcast ..."? 换句话说,代理可以与Google Assistant通信以使用其任何功能,例如“广播...”吗?

We have checked Google Assistant SDK as alternative, but we are confused about it. 我们已经检查了Google Assistant SDK作为替代方案,但对此感到困惑。

Please, excuse me for my bad English. 拜托,请原谅我英语不好。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

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. 动作通常是对话式的,而不是花一些时间来回答答案,这就是为什么履行必须执行多长时间的限制为5秒。 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. 首先,您可以使用“助手”之外的其他方法来传递答案-可能使用Firebase Cloud Messaging之类的方法或向用户发送电子邮件。

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. 在这种情况下,您的Java程序将在信息可用时通过助手将通知发送给用户并存储结果。 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. 在这种方案下,您将触发Java程序,该程序将获取结果,然后以实现服务器可以访问的方式存储该结果。 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. 在对用户的答复中说您正在处理结果时,您会在“媒体响应”中包含一段播放15秒的音频。 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. 否则,只需发送媒体回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM