All Projects → frogermcs → Google Actions Java Sdk

frogermcs / Google Actions Java Sdk

Licence: other
(Deprecated) Unofficial Google Actions Java SDK - for Android engineers and all Java lovers

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Google Actions Java Sdk

Golang Samples
Sample apps and code written for Google Cloud in the Go programming language.
Stars: ✭ 3,088 (+1002.86%)
Mutual labels:  google-cloud, appengine
Ruby Docker
Ruby runtime for Google Cloud Platform
Stars: ✭ 122 (-56.43%)
Mutual labels:  google-cloud, appengine
GaeSupportLaravel
Run Laravel on Google App Engine
Stars: ✭ 22 (-92.14%)
Mutual labels:  appengine, google-cloud
Elixir Runtime
The community-supported runtime for Elixir on Google App Engine.
Stars: ✭ 158 (-43.57%)
Mutual labels:  google-cloud, appengine
deploy-appengine
A GitHub Action that deploys source code to Google App Engine.
Stars: ✭ 184 (-34.29%)
Mutual labels:  appengine, google-cloud
appengine-java-standard
Google App Engine Standard Java runtime: Prod runtime, local devappserver, Cloud SDK Java components, GAE APIs, and GAE API emulators.
Stars: ✭ 141 (-49.64%)
Mutual labels:  appengine, google-cloud
server
The ViUR application development framework - legacy version 2.x for Python 2.7
Stars: ✭ 12 (-95.71%)
Mutual labels:  appengine, google-cloud
rowy
Open-source Airtable-like experience for your database (Firestore) with GCP's scalability. Build any automation or cloud functions for your product. ⚡️✨
Stars: ✭ 2,676 (+855.71%)
Mutual labels:  google-cloud
ipranges
🔨 List all IP ranges from: Google (Cloud & GoogleBot), Bing (Bingbot), Amazon (AWS), Microsoft (Azure), Oracle (Cloud) and DigitalOcean with daily updates.
Stars: ✭ 38 (-86.43%)
Mutual labels:  google-cloud
bigtable
TypeScript Bigtable Client with 🔋🔋 included.
Stars: ✭ 13 (-95.36%)
Mutual labels:  google-cloud
ob google-bigquery
This service is meant to simplify running Google Cloud operations, especially BigQuery tasks. This means you do not have to worry about installation, configuration or ongoing maintenance related to an SDK environment. This can be helpful to those who would prefer to not to be responsible for those activities.
Stars: ✭ 43 (-84.64%)
Mutual labels:  google-cloud
gcp-firewall-enforcer
A toolbox to enforce firewall rules across multiple GCP projects.
Stars: ✭ 77 (-72.5%)
Mutual labels:  google-cloud
option-pricing-models
Simple python/streamlit web app for European option pricing using Black-Scholes model, Monte Carlo simulation and Binomial model. Spot prices for the underlying are fetched from Yahoo Finance API.
Stars: ✭ 16 (-94.29%)
Mutual labels:  google-cloud
pipeline-editor
Cloud Pipelines Editor is a web app that allows the users to build and run Machine Learning pipelines without having to set up development environment.
Stars: ✭ 22 (-92.14%)
Mutual labels:  google-cloud
Cloud Code Intellij
Plugin to support the Google Cloud Platform in IntelliJ IDEA - Docs and Issues Repository
Stars: ✭ 256 (-8.57%)
Mutual labels:  google-cloud
wake-on-lan
Use any SmartThings switch (including a virtual one) to wake up a device on your LAN
Stars: ✭ 20 (-92.86%)
Mutual labels:  google-home
Worker
Worker runs your Travis CI jobs
Stars: ✭ 265 (-5.36%)
Mutual labels:  google-cloud
node-red-contrib-nora
Node Red Google Home integration
Stars: ✭ 77 (-72.5%)
Mutual labels:  google-home
google-cloud-utilities
Docker images and scripts to deploy to Google Cloud
Stars: ✭ 26 (-90.71%)
Mutual labels:  google-cloud
gcptree
Like the unix tree command but for GCP Org Heirarchy
Stars: ✭ 24 (-91.43%)
Mutual labels:  google-cloud

Deprecated

This project is now deprecated. Google has created their Java library for Google Actions, which I recommend to use. Thanks for your support!

https://medium.com/google-developers/announcing-the-java-kotlin-client-library-for-actions-on-google-217828dead

https://github.com/actions-on-google/actions-on-google-java

Unofficial Google Actions Java SDK

Official 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 project

Project is split into two modules:

Assistant Actions Java SDK

This code is responsible for handling requests and responses compatible with Conversational Protocol.

Assistant Actions Java Sample

Example 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 SDK

Even 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 RootResponse object by hand which in a moment of writing this is fully compatible with Conversational Protocol. Same with RootRequest - object should reflect all data which Google Actions send to us.

Download

Library can be downloaded from jCenter:

repositories {
    jcenter()
}

dependencies {
    compile 'com.frogermcs.gactions:gactions:0.3.1'
}

Code

Here 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 AssistantActions object, we need to pass implementation of ResponseHandler interface. This class will be responsible for passing json response to Google Actions. Then we need to build intents mapping to delegate request to proper RequestHandlers. RequestHandlers are responsible for preparing response for Google Actions.
At the end we need to pass request coming from Google Actions to our AssistantActions object.

Example implementation

Here are the most important classes from example AppEngine Java implementation

ActionsServlet - entry class in our endpoint.

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));
    }

    //...
}

AppEngineResponseHandler - implementation or ResponseHandler. Method onResponse(RootResponse rootResponse) passes back prepared response to HttpServletResponse.

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());
    }
}

MainRequestHandler - In response to initial Intent assistant.intent.action.MAIN we are asking user for NAME permission.

public class MainRequestHandler extends RequestHandler {
    MainRequestHandler(RootRequest rootRequest) {
        super(rootRequest);
    }

    @Override
    public RootResponse getResponse() {
        return ResponseBuilder.askForPermissionResponse("See how permissions work",
                SupportedPermissions.NAME);
    }
}

MyPermissionRequestHandler - whether permission is granted or not, we asking user to tell us something so we'll be able to repeat this response.

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.");
        }
    }
}

TextRequestHandler - finally we're replying what user's just said.

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 Cloud

This 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

  • Follow steps from here: https://cloud.google.com/sdk/docs/. At the end you should have created Project, know your application id, and be able to use gcloud on your computer.

Configuration

Files to edit:

  • google-actions-java-sample/src/main/webapp/WEB-INF/appengine-web.xml -> Edit application_id (your project id from https://console.cloud.google.com/, if not edited it's fancy name like "mythic-origin-36343").
  • google-actions-java-sample/action.json -> Edit application_id (setup endpoint where Google Actions will be able to reach your servlet)

If you have Google Cloud SDK already installed on you machine, and you are ready to deploy, use this gradle task:

$ ./gradlew google-actions-java-sample:appengineDeploy

Testing

Just visit Web Simulator and start testing!

Web Simulator

TODO

This is very general list of things planned to do to make this project as useful as possible. Your commitment is highly appreciated!

  • Better project structure, code cleanup and style rules
  • Add ssml support to responses
  • API.AI support (based on official SDK)
  • Keep conversation context
  • Unit tests (at least 70% coverage)
  • Build and distribute as a java library

License

See LICENSE.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].