让我的Google助手在特定词语时调用我的REST API。

huangapple go评论72阅读模式
英文:

Make my google assistant call my REST API on specific words

问题

开始一个新项目(基于Spring Boot的REST API),我想将它与谷歌连接起来。

基本上,我想通过对Google助手说特定的词来触发对我的REST API的调用。例如,如果我说“好的 {我的API名称}”,然后说“做这个”,它将以POST方式调用我API上的预定义端点,并将“做这个”作为载荷。

我已经查看了Google Actions API,但我感到很困惑...
这种可能吗?有什么建议吗?

我正在寻找一些易于配置的东西,Google始终可以触发相同的端点,我更愿意自己处理载荷的解释。

非常感谢!

英文:

Starting a new project (Rest api based on spring boot),, I would like to make it connected to Google.

Basically, I want, by saying specific words to google assistant, trigger a call on my REST API. For example, if I say "OK {myApiName}" and then "Do this", it will call a previously defined endpoint on my api as POST with "Do this" in the payload.

I've already checked the Google Actions API, but I am pretty lost...
Is this possible ? any advices ?

I'm in search of something easy to configure, Google can always trigger the same endpoint, I prefer to handle the interpretation of the payload myself.

Many thanks !

答案1

得分: 3

我不太确定我理解为什么你想从Google助手发起API调用,但要做到这一点,你可以构建一个Conversational Action,这是一个用于Google助手的应用程序。你可以使用Dialogflow以非常简单快速的方式实现它。

Dialogflow是一个自然语言处理工具,可以识别人类语言并“理解”用户的请求。

在Dialogflow中,你可以实现意图(intents)。意图用于将特定的词语或短语与一个“动作”关联起来。

在你的情况下,短语可以是“好的{myApiName},执行{this}”,关联的动作将是调用{myApiName},并使用载荷{this}。

在“Dialogflow Fulfillment”部分,你可以实现API调用并返回你想要的结果。

整个流程如下:

(流程图图片略)

要实现你的意图,你应该这样做:向Dialogflow指定“训练短语”,让它能够匹配用户的意图,并将载荷封装在一个“参数”中。参数只是一个变量,你需要将待发送到API的载荷存储在其中。

在这一点上,只需实现与你的意图关联的fulfillment,以便使用存储在参数中的相关载荷进行API调用。类似于这样的操作:

(代码图片略)

这比说起来要容易。希望我已经给你了解它如何工作的概念。我建议你阅读文档以更好地理解。

英文:

I'm not sure I understand why you want to make an API call from Google Assistant, but to do it, what you could do is build a Conversational Aciton, that is an app for Google Assistant. It is possible to do it in a very simple and fast way using Dialogflow.

Dialogflow is an NLP that recognizes human language and "understands" what the user is asking for.

Within Dialogflow you can implement intents. An intent is used to associate a certain word or phrase with an "action".

In your case the phrase could be "OK {myApiName} do {this}" and the associated action would be to call {myApiName} with payload {this}.

In the "Dialogflow Fulfillment" you can implement the API call and return the result you want.

The flow is this:

让我的Google助手在特定词语时调用我的REST API。

To implement your intent you should do something like this: specify to Dialogflow "trainging phrases" that allow it to match the user's intention and encapsulate the payload in a "parameter". A parameter is nothing more than a variable that you will need to store the payload to be sent to your APIs.

让我的Google助手在特定词语时调用我的REST API。

At this point, just implement the fulfillment associated with your intent to make the API call with the related payload saved in the parameter. Something like this:

让我的Google助手在特定词语时调用我的REST API。

It is easier to do than to say. I hope I have given you an idea of how it works. I suggest you to read the documentation to better understand.

答案2

得分: 0

我正在尝试使用IFTTT应用。在那里,您可以使用Google助手作为触发器来调用webhook。

英文:

I'm trying this using IFTT application. There you can use Google assistant as a trigger for a webhook call.

huangapple
  • 本文由 发表于 2020年3月15日 22:30:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/60693948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定