在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):frogermcs/Google-Actions-Java-SDK开源软件地址(OpenSource Url):https://github.com/frogermcs/Google-Actions-Java-SDK开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):DeprecatedThis project is now deprecated. Google has created their Java library for Google Actions, which I recommend to use. Thanks for your support! https://github.com/actions-on-google/actions-on-google-java Unofficial Google Actions Java SDKOfficial Google Actions SDK is written in Node.js. But in many situations voice interfaces like Google Home or Google Assistant will extend or replace mobile apps. If you are old fashioned Android engineer and the most of your code is already written in Java, why not reuse it and build voice extension to app on your own? And this is the main reason to build Google Actions Java SDK - enabling as much developers as possible to build their brilliant ideas for Google Assistant and Home. Currently this is just working proof of concept of Google Actions Java SDK. It means that there is no documentation, fixed interface, (not much) unit tests and many, many others. Google Actions Java SDK is build based on official Node.js library, but it's not a mirror copy of it. The goal is to make it fully compatible with Conversational Protocol of Assistant Platform. About projectProject is split into two modules: Assistant Actions Java SDKThis code is responsible for handling requests and responses compatible with Conversational Protocol. Assistant Actions Java SampleExample projects showing how Assistant Actions SDK can be used in AppEngine Java project. For now Servlet is able to greet user and repeat utterance. How to work with limited SDKEven if it's very early stage project and there is not much utils in it, entire communication with Google Actions is based on proper responses. So even if you find any limitations you can always build DownloadLibrary can be downloaded from jCenter: repositories {
jcenter()
}
dependencies {
compile 'com.frogermcs.gactions:gactions:0.3.1'
} CodeHere is example code showing how to use Google Actions Java SDK AssistantActions assistantActions =
new AssistantActions.Builder(new AppEngineResponseHandler(response))
.addRequestHandlerFactory(StandardIntents.MAIN, new MainRequestHandlerFactory())
.addRequestHandlerFactory(StandardIntents.TEXT, new TextRequestHandlerFactory())
.addRequestHandlerFactory(StandardIntents.PERMISSION, new MyPermissionRequestHandlerFactory())
.build();
assistantActions.handleRequest(request); To build Example implementationHere are the most important classes from example AppEngine Java implementation
public class ActionsServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AssistantActions assistantActions =
new AssistantActions.Builder(new AppEngineResponseHandler(response))
.addRequestHandlerFactory(StandardIntents.MAIN, new MainRequestHandlerFactory())
.addRequestHandlerFactory(StandardIntents.TEXT, new TextRequestHandlerFactory())
.addRequestHandlerFactory(StandardIntents.PERMISSION, new MyPermissionRequestHandlerFactory())
.build();
assistantActions.handleRequest(parseActionRequest(request));
}
//...
}
public class AppEngineResponseHandler implements ResponseHandler {
private final HttpServletResponse httpServletResponse;
@Override
public void onPrepareContentType(String contentType) {
httpServletResponse.setContentType(contentType);
}
@Override
public void onPrepareResponseHeaders(Map<String, String> headers) {
for (String headerName : headers.keySet()) {
httpServletResponse.addHeader(headerName, headers.get(headerName));
}
}
@Override
public void onResponse(RootResponse rootResponse) {
gson.toJson(rootResponse, httpServletResponse.getWriter());
}
}
public class MainRequestHandler extends RequestHandler {
MainRequestHandler(RootRequest rootRequest) {
super(rootRequest);
}
@Override
public RootResponse getResponse() {
return ResponseBuilder.askForPermissionResponse("See how permissions work",
SupportedPermissions.NAME);
}
}
public class MyPermissionRequestHandler extends PermissionRequestHandler {
MyPermissionRequestHandler(RootRequest rootRequest) {
super(rootRequest);
}
@Override
public RootResponse getResponse() {
UserProfile userProfile = getUserProfile();
if (isPermissionGranted() && userProfile != null) {
return ResponseBuilder.askResponse("Hey " + userProfile.given_name + ". It's nice to meet you!" +
"Now tell me something so I could repeat it.");
} else {
return ResponseBuilder.askResponse("Hey. I don't know your name, but it's ok. :)" +
"Now tell me something so I could repeat it.");
}
}
}
public class TextRequestHandler extends RequestHandler {
TextRequestHandler(RootRequest rootRequest) {
super(rootRequest);
}
@Override
public RootResponse getResponse() {
return ResponseBuilder.tellResponse("You've just said: " + getRootRequest().inputs.get(0).rawInputs.get(0).query);
}
} How to deploy this project to our Google CloudThis description isn't very detailed. It's pretty similar to description in official documentation, but instead of Node.js we are using Java environment on AppEngine. Google Cloud
ConfigurationFiles to edit:
If you have Google Cloud SDK already installed on you machine, and you are ready to deploy, use this gradle task:
TestingJust visit Web Simulator and start testing! TODOThis is very general list of things planned to do to make this project as useful as possible. Your commitment is highly appreciated!
LicenseSee LICENSE.md. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论