Actions on Google is a developer platform that lets you create applications to extend the functionality of Google Assistant. Learn how to build actions from scratch under 10 mins with this simple tutorial. The tutorial is divided into two parts. You can find part 2 at this link.

What we’ll build?

In this tutorial, we’ll be building an Action for Google Assistant which would allow anyone to find nearby places which serve the dish they’re craving for! You can find the entire code for the tutorial and the app here. You can watch the demo video here. We have also published our final application on Google Assistant here, so you can try it out live on your phone! Here are few important things, we’ll be covering in this article:

How to create a custom webhook and host it on your own server instead of using cloud functions.

How to access location of the user using permission helper intent.

How to store data in userStorage.

Getting Started from basics

Let’s start from the beginning by defining some key terms that would be commonly used in this post.

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. Fulfillment: A service, app, feed, conversation, or other logic that handles an intent and carries out the corresponding Action.

To start building the action, you’ll first need to create an Actions project as follows:

Open the Actions Console

Click on Add/import project.

Click on Create Project and press SKIP on the next screen

Click Build > Actions in the left nav.

Click Add your first Action.

Select at least one language for your Action, followed by Update.

On the Custom intent card, click Build. This will open the Dialogflow Console in another tab.

Click on build and you will be directed to Dialogflow Console

Press on Create to begin customizing how your Dialogflow agent responds to user requests

Start Talking

Users start talking with the action through an invocation. (An example of an explicit invocation is a phrase like “Hey Google, talk to MovieTime”). The Assistant then tries to match the user’s input to one of your Actions (it will be MovieTime in this case).

The welcome intent in an entry point for users to start conversations. It’s triggered when users explicitly invoke an Action by saying its name.

You can customize the response accordingly

Now that the welcome intent is added, we can test our app on the simulator.

In the Dialogflow Console left navigation, click on Integrations. Then, click on Google Assistant > Integration Settings. Click Test to update your Actions project and load it into the Actions Console simulator. To test your Action in the simulator, type “Talk to find my food” into the Input field and press enter.

Now when the action is invoked in the above figure, the welcome intent you wrote is shown.

Making it conversational

Now that you have created a welcome intent, it’s time to get into the core of the app.

Create the ‘findRestaurant’ intent

Let’s start with find my food intent. The one which is responsible for extracting the dish and finding the best restaurant for that particular dish!

Once you have created an intent, you can name it and start adding training phrases as shown below.

Try to form questions which user might ask for finding his food and rephrase them to come up with multiple sentences. Now you can notice that rosogulla, bhalla, italian, naan, daal makhani etc are all types of food the user might say therefore we have to club them in some way for the assistant to understand.

We can create an Entity which represents a category of things, which in our case is a category of food.

We have created an entity names cuisine where we have entered some common names for the types of food. Notice the ‘Allow automated expansion’ checkbox, this will help dialogflow understand the terms that are not mentioned in the cuisine list and might be related to food.

Once this is done, in the intent, you need to enable Webhook for our intent

Dialogflow will automatically extract parameters it recognizes from user speech which triggers this intent; in this case, the cuisine parameter. Once it obtains this information, Dialogflow makes it available to your fulfillment.

That’s it for this part of the tutorial. In part 2, we’ll be finishing code for the webhook and complete the application.