使用gactions CLI不带更新更新actions.json

问题描述 投票:1回答:1

我已经使用Actions SDK在Google上构建了Action。我希望能够以编程方式在服务器上更新actions.json。我不想使用助手CLI。是否有REST API或其他更新文件的方法?

actions-on-google
1个回答
1
投票

我能够嗅探Google与cli之间的交流。

更新操作

这里是您可以使用的curl请求。不要忘记添加Bearer(授权),在--data-binary之后,您将包括actions.json。最后一件事是,使用操作ID(替换为testskill)最后更改端点URL。

curl 
-H 'Host: actions.googleapis.com' 
-H 'content-type: application/json' 
-H 'authorization: Bearer AuthorisationKeyAsRandomStrings' 
-H 'user-agent: Gactions-CLI/2.2.4 (darwin; amd64; dev/NsZwRCulTKhlPxMfp)' 
--data-binary '{"localizedActionPackages":{"de":{"actions":[{"description":"Default welcome intent","fulfillment":{"conversationName":"testskill"},"intent":{"name":"actions.intent.MAIN","trigger":{"queryPatterns":["sprechen mit test skill"]}},"name":"MAIN"},{"description":"test intent","fulfillment":{"conversationName":"testskill"},"intent":{"name":"test_intent","parameters":[{"name":"color","type":"org.schema.type.Color"}],"trigger":{"queryPatterns":["suchen ein $org.schema.type.Color:color schuhe","kaufen ein $org.schema.type.Color:color shuhe","kaufen"]}},"name":"Test"},{"description":"ciao","fulfillment":{"conversationName":"testskill"},"intent":{"name":"ciao_intent","trigger":{"queryPatterns":["ciao","bye","pa"]}},"name":"Ciao"}],"conversations":{"testskill":{"name":"testskill","url":"https://ae8e6xx.ngrok.io/testskill"}},"locale":"de"}},"name":"agents/testskill"}' 
--compressed 'https://actions.googleapis.com/v2/agents/testskill:batchUpdateAllDraftActionPackages'

但是并不能保证将来会成功,因为Google可以在不通知任何人的情况下更改端点。因此,我建议您坚持行动cli。

获取没有gactions CLI的令牌

您需要访问以下网址:https://accounts.google.com/signin/oauth/oauthchooseaccount?access_type=offline&client_id=237807841406-o6vu1tjkq8oqjub8jilj6vuc396e2d0c.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Factions.builder&state=state&o2v=1&as=ZmeGyvTUA3FLgRPS1_rd1A&flowName=GeneralOAuthFlow

授权后,您将获得令牌。这需要与另一个curl请求一起发送。您需要用令牌替换PlaceYourUrlEncodedTokenHere,但需要对其进行url编码。

curl 
-H 'Host: accounts.google.com' 
-H 'content-type: application/x-www-form-urlencoded' 
-H 'authorization: Basic MjM3ODA3ODQxNDA2LW82dnUxdGprcThvcWp1YjhqaWxqNnZ1YzM5NmUyZDBjLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tOjZ1TlVQakZvd3pVRThTbGlWWlg2a2VZMA==' 
-H 'user-agent: Go-http-client/2.0' 
--data-binary "code=PlaceYourUrlEncodedTokenHere&grant_type=authorization_code&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob" 
--compressed 'https://accounts.google.com/o/oauth2/token'

[之后,您将收到来自google的json响应,其中包含access_token。您将以Bearer的身份添加到您的请求。

© www.soinside.com 2019 - 2024. All rights reserved.