Actions on Google is a developer platform that lets you create software to extend the functionality of Google Assistant, Google's virtual personal assistant, across more than 1 billion devices, including smart speakers, phones, cars, TVs, headphones, and more. Users engage Assistant in conversation to get things done, such as buying groceries or booking a ride. (For a complete list of what's possible, see the Actions directory.)

As a developer, you can use Actions on Google to easily create and manage delightful and effective conversational experiences between users and your own third-party fulfillment service. The codelab covers beginner-level concepts for developing with Actions on Google. You do not need any prior experience with the platform to complete the codelab.

What you'll build

You'll build a simple Conversational Action with the following features:

What you'll learn

What you'll need

The following tools must be in your environment:

Optional: Get the sample code

You can get the full project code for the codelab from the GitHub repository.

So, how does an Action work?

To start a conversation, the user needs to invoke your Action through Assistant. Users say or type a phrase like, "Hey Google, talk to Google IO." That tells Assistant the name of the Action to talk to.

From that point forward,, the user is talking to your Action and giving it input. The conversation continues as a two-way dialog until the user's intent is fulfilled or the conversation is finished.

Look at what happens behind the scenes during a conversation.

You create Actions by creating an Actions project and defining two things for each action—the intent and the fulfillment.

The next section describes how to set up your Actions project in the Actions Console.

Change your Google permission settings for your temporary login account

  1. Go to Activity controls.
  2. Ensure that the following permissions are enabled:

Create an Actions project

Actions projects are containers for your Action(s) with the metadata (name, description, and category) that becomes your Actions directory listing.

To start building Actions, you need to create an Actions project as follows:

  1. Open the Actions Console.
  2. Click on New project. Instead of creating a new project, click on the Project name field and then select the existing project that's been created for you (it should start with "IOCodelabs 19" followed by additional digits). Click Import project.
  3. In the Welcome to your project screen, rather than pick a category, scroll to the More options section and click on the Conversational card.

  1. Click Build > Actions in the left navigation bar.
  2. On the Create Action dialog, select Custom Intent and click Build. That opens the Dialogflow Console in another tab.

  1. You'll see the I/O 2019 Codelabs login screen. Click Confirm.
  2. Sign in using your temporary codelabs login credentials (you can find those by clicking the G icon in the upper-right corner of the browser). The login address should end with @iocodelabs.
  3. In the permissions dialog that pops up, click Allow.
  4. Accept the terms of service and click Accept.

How Actions work with Dialogflow

You might wonder how Assistant parses the semantic meaning of user input, such as spoken utterances. That's done via natural language understanding (NLU), which allows Google's software to recognize words in speech.

For your Actions, Google provides a service called Dialogflow to let you easily handle NLU. Dialogflow simplifies the task of understanding user input, extracting key words and phrases from the input, and returning responses. You define how all that works within a Dialogflow agent.

The following diagram shows an example of how Dialogflow (represented by the second column from the right) handles user input from Assistant and sends requests to your fulfillment (represented by the rightmost column).

Create a Dialogflow agent

Now that you built your Actions project, create a Dialogflow agent and associate it with your project.

  1. You should already be in the Dialogflow Console with your Actions project name at the top.
  2. Click Create.

If the agent creation is successful, you will be in the Intents page and you can begin customizing how your Dialogflow agent responds to user requests.

Users start the conversation with your Actions through invocation. (An example of an explicit invocation is a phrase like, "Hey Google, talk to MovieTime.") Assistant then tries to match the user's input to one of your Actions.

Create a welcome intent

Every Actions project must have a welcome intent that acts as an entry point for users to start conversations. The welcome intent is triggered when users explicitly invoke an Action by uttering its name.

By default, Dialogflow creates a welcome intent for you. Modify the welcome intent that users trigger when they say, "Hey Google, talk to my test app."

  1. In the Intents page of the Dialogflow Console, click on Default Welcome Intent.

  1. Delete all of the other text responses by clicking the trash icon next to each one.

  1. Under the Responses section, click Enter a text response and type, "Welcome! What is your favorite color?"
  2. Click Save. You should see an Intent saved notification briefly pop up.

Test the welcome intent

The Actions Console provides a web interface for testing called the simulator. The interface lets you simulate hardware devices and their settings. You can also access debug information, such as the request and response that your fulfillment receives and sends.

Test your Action in the Actions Console simulator.

  1. In the Dialogflow Console left navigation bar, click on Integrations. Then, click on Google Assistant > Integration Settings.
  2. Click Test to update your Actions project and load it into the Actions Console simulator. (If you see a Check auto-preview setting dialog, you can leave the Auto-preview changes option enabled, then click Continue.)

  1. To test your Action in the simulator, type "Talk to my test app" in the Input field and hit enter.

When your Action's welcome intent is invoked, Assistant responds with the greeting message and prompts the user to provide their favorite color.

Debug your Action

The panel on the right shows debugging information that's useful when testing your Action.

Now that users have a way to start a conversation, keep the ball rolling.

Now you need to learn the basics of setting up slot-filling, an important capability in Dialogflow that allows you to collect a set of values from the user through natural, back-and-forth conversation. The capability is useful if your Action needs a specific set of parameter values to fulfill the user's intent.

To see slot-filling in action (no pun intended!), you'll create a new intent to see the color response. When the user speaks or types their response, Dialogflow parses the user's input to extract the information that your fulfillment needs—namely, the color—and sends it to your fulfillment. Your fulfillment then autogenerates a lucky number to send to the user.

To implement the response, you need to add two components in the Dialogflow Console—a Dialogflow intent and a Dialogflow webhook.

You define Dialogflow intents in your agent to control how you want Dialogflow to process user requests.

In the welcome intent, you asked the user for a favorite color. Now you need to make an intent to capture the information. To do that, you need to use two specific sections of an intent— training phrases and parameters—to parse the information that you need from users.

Create a Dialogflow intent

To create the Dialogflow intent, do the following:

  1. In the Dialogflow Console, close the Assistant integration settings page if you have it opened. In the left navigation bar, click on Intents, then click on Create intent.
  2. In the intent name field at the top, type in "favorite color" as the name of your new intent. Click Save.
  1. Under Training phrases, add the following user expressions by typing in the following phrases, then click Enter on your keyboard:
  1. Under Action and parameters, create the prompt text to ask the user for their favorite color. You should see a line with color in the Parameter Name field. The parameter entry is automatically created by Dialogflow because it is able to auto-annotate words and phrases that it recognizes as entities in the training phrases. On that line, do the following:

  1. Under the Fulfillment section in the page (not the left navigation bar), click Enable Fulfillment. (You may need to expand the section by clicking on the downward-pointing arrow.)
  2. Turn on Enable webhook call for this intent.
  3. Click Save.

After you completed those steps, Dialogflow will automatically extract parameters that it recognizes from user speech that triggers the intent (in this case, the color parameter). Once it obtains that information, Dialogflow makes it available to your fulfillment.

In this section, you implement a Dialogflow webhook that contains the logic to construct a conversational response. You also try your Action in real time by using the Actions Console simulator.

The Dialogflow webhook contains the logic for dynamically constructing response messages to send to the user.

Build your webhook

Use the Dialogflow Console's inline code editor to build and deploy the webhook. To build a webhook for your Action, do the following:

  1. In the left navigation bar, click Fulfillment.
  2. Toggle Inline Editor to Enabled.

  1. Replace the contents of index.js with the following code:


'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
    const luckyNumber = color.length;
    // Respond with the user's lucky number and end the conversation.
    conv.close('Your lucky number is ' + luckyNumber);

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
  1. Click Deploy. (You need to wait a couple minutes for Dialogflow to provision and deploy your webhook code. When the code is successfully deployed, you see an updated Last deployed timestamp next to the Deploy button.

Understand the code

The code for the webhook is implemented in JavaScript. When you use Dialogflow's inline code editor, it deploys your webhook code on a managed environment in the cloud using Cloud Functions for Firebase.

The webhook code uses the Actions on Google Node.js client library to respond to HTTP requests that Assistant sends to your webhook. The library allows you to create a DialogflowApp object, which acts as a wrapper for the Dialogflow API.

In this case, an app variable of the DialogflowApp object type is created. The app.intent() function is used to declare a callback to handle the favorite-color intent.

The callback receives the following two important arguments:

The callback generates the user's lucky number by determining the length of the word for their color (For example, the six-character word "orange" would return a favorite color of six). It then uses the close method of the Conversation object parameter to respond to the user and end the conversation. The response is a simple string (such as, "Your lucky number is 6.")

The figure shows how the variable color on line 21 of the webhook implementation uses the parameter name that you defined earlier in the Dialogflow Console. For example, if the user said "My favorite color is green," then your variable color on line 21 would have the value "green."

Test your Action

Test your Action.

  1. Open the Actions Console and select your Actions project.
  2. Click the Test tab at the top. Click on the X button at the top of the output window, which exits you from any conversation that you might have started earlier in the simulator.
  3. Type "Talk to my test app" in the Input field and hit Enter on your keyboard.

The simulator then performs an explicit invocation by calling your welcome intent. Once you're mid-conversation, you can trigger the ‘favorite color' custom intent by providing a color. For example, try testing with the following phrases:


You know the basics of building conversational user interfaces with Actions on Google.

What you covered

What's next

Explore the following resources to learn more about Actions on Google:

Follow @ActionsOnGoogle on Twitter for the latest announcements and tweet with #AoGDevs to share what you build!

Feedback survey

Before you go, please fill out a brief survey about your experience.