Node Red nodes to receive and respond to Google Action requests from Google Assistant.

Google Assistant is Google's personal assistant that provides the voice recognition and natural language processing behind Google's Android and Home devices. Google Actions allow you to build conversational agents that interact with the user using a query-response conversation style.

This node is a wrapper around Google's actions-on-google-nodejs client library using the Actions SDK.

The node runs an Express web server to listen for Action request from Google. By using a separate web server from Node Red, it allows the node to listen on a different port. This allows the Action listener to be exposed to the Internet without having the rest of Node Red also exposed. The web server is required to run HTTPS so you will need SSL certificates. Self signed certificates are OK.

Action requests are received by the Google Action input node and converted into a message. The message contains some metadata about the conversation and the raw text of the user's input. State data about the conversation can be passed back and forward to track the state of the conversation.

Once the request has been process, the response is passed to the Google Action Response node which returns it to Google Assistant for delivery to the user. The response message is contained in msg.payload either as plain text or Speech Synthesis Markup Language (SSML).

A response can either complete the processing of the action or can request further information from the user.

To deploy your app, you will need an account on Google Actions.

Create a new project in the console and make a note of the project id.

Do not define any action in the Google Actions Console as we are going to use the gactions CLI utility to configure your app on Google Assistant.

Install the gactions CLI utility on your machine.

Copy the example action.json to your local drive and modify it to suit your application. The main thing you will need to change is the url of your Node Red server. (Documentation about the structure of the action.json).

Now use the gactions CLI utility to publish your app onto Google Assistant.

gactions test -preview_mins 9999999 -action_package action.json -project your-project-id

You can test you app using the simulator in the Google Actions console or from any device linked to your Google account. To access your app say:

Hey Google, talk to my test app

Be aware that Google Assistant isn't really intended to run private apps. It is possible to have a private app by keeping your app in test mode perpetually. One of the difficulties though is that Google requires your app to have a unique name from any other app published by anyone else and you can't use any registered brand name.

Also be aware that there is no security mechanism in this implementation yet. Google uses OAuth2.0 to authorise users to access your end point. It will be added in a future release (or send me a pull request :-).

The following is a sample flow to process action requests. It will respond to questions involving the words 'number' or 'fancy' like 'pick a number', 'what is your number', 'what number are you', 'say something fancy', 'talk fancy talk', etc.