Google Assistant — An Introduction

Soumya Kanti Kar
wwdablu
Published in
5 min readJul 25, 2018

After buying my Pixel 2 device, I got a Google Home as a free gift as part of the pre-order offer. Once I had it, I was quite impressed. After using it for few days, it became a part of the daily life, news, weather, songs, jokes and trying out queries to see what the lady responds.

In all these, I wondered how about creating my own action for Google Assistant. Having a very basic knowledge on working with Amazon Alexa, I sat down to create a very simple workflow and learn it.

At first, let us understand few terminologies.

Action
An Action is an entry point into an interaction that you build for the Assistant. Users can request your Action by typing or speaking to the Assistant.

Intent
An underlying goal or task the user wants to do; for example, ordering coffee or finding a piece of music. In Actions on Google, this is represented as a unique identifier and the corresponding user utterances that can trigger the intent.

Fulfilment
A service, app, feed, conversation, or other logic that handles an intent and carries out the corresponding Action.

Google Code Labs — Part 1

First of, we need to create a project, as usual. For this, let us go to console. Once inside, create a project.

Provide me the name of the project

Once the project has been created. We need to build actions for it. On the left navigation you should see the option and it might look like this.

Empty actions as of yet

For this example we are going to build a custom action.

Select the custom intent

This would redirect you to the DialogFlow console. This is basically a NLU or Natural Language Understanding handler. That means, it allows us to interpret the phrases provided by the user and extract the applicable information.

As per Google’s definition:

  • Dialogflow: A web-based service provided by Google that uses an agent to process user input. This service allows you to integrate conversational apps with the Assistant, as well as with other conversation platforms.
  • NLU: Acronym for “Natural Language Understanding”. This refers to the capability of software to understand and parse user input.

The image below should provide a better understanding of the components in action for the process.

Google Code Lab — Part 1

In the DialogFlow console you should see something similar to this. It should specify your project name. If yes, click on the create button.

Dialog Flow

Once the agent has been successfully created, we will now be creating intents. There should already be a default welcome and fallback intent already created for our usage.

Default intents

Click on Default Welcome Intent. In the responses tab, remove all the default responses and once done, we will create a new response.

Empty response

Once we add a text response, click on the save button. Now, let us try to integrate. On the left nav, there should be an option called Integrations. On Google Assistant click on the integration settings.

Google Assistant Integration Settings

It should display the following settings dialog. Click on the Test button and click on the continue button on the next dialog. Once we have the simulator running it should be something like this.

Simulator running our test app

In here if we invoke the intent or say “Talk to my test app” using the microphone, then we will be greeted with the welcome string that we have provided.

Great! We have been able to initiate the conversation, but then again this is not a conversation. Hence, the next step for us would be to initiate the conversation mode.

Hence let us begin and create an intent. For doing this, you need to visit the dashboard console.

Once an intent has been created. We need to provide the training phrases. The option should look something similar to this.

Input for training phrases

Next we need to add the action and parameters. In this case, the NLU performs the magic and provides us the data what we are interested in.

Creating a parameter

Now, we might need to perform some action on the backend. For this purpose, we are going to use the WebHook.

Enable WebHook for this intent

Now, let us implement the WebHook. On the left navigation there should be an option for it called Fulfillment. Enable the inline editor for the purpose of this usage.

Enable inline editor

Once we add in the respective code, we can click on the deploy button. This would ensure that the JavaScript code is now in the cloud and can be invoked by the action to execute it.

index.js — Our JavaScript code which will be executed (WebHook)

The above portion of the code would be executed if the provided intent is found. In here, the input parameters are to the conversation object and the input provided by the user. This is same as the one we provided in the intent, that is $nextStep. So, as an example, when the user says “done” verbally, the value contained in the parameter nextStep will be string done.

In the Actions control panel, the action can be released to production so that it can be made available to others to try it. You can also test it on your own device if the email account on which the action is being developed is connected to a device. For example, here is the screenshot from my device wherein I am running the action.

Executing the action on Pixel 2 device

This is just an introduction to get a hands-on on the process, just to get a taste of the process. The next step is to create a more interactive action and see how it behaves. Till then, will wait for the action to be approved. 🤞

--

--

Soumya Kanti Kar
wwdablu
Editor for

Android developer. Interested in working on open source Android libraries and applications.