Actions are entry points into your app that define the invocation and discovery model for your app. You declare Actions in a JSON file known as the Action package, which you later upload to your developer project when you want to test or submit your Actions project for approval. An Action package is a JSON file that defines the Actions in your Actions project.
To define Actions in your Action package, you create an intent that defines how the Action is invoked and the corresponding fulfillment endpoint for when the intent is triggered. You can create the following types of Actions:
- Default Action: 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 (for
example, "Hey Google, talk to ExampleAction"). This welcome intent is identified with
the
actions.intent.MAIN
intent name. - Additional Actions for deep-linking: You can create additional Actions in your Action package with intents that you define yourself. This allows users to invoke specific functionality by saying an Action name along with an intent (for example: "Hey Google, talk to ExampleAction to find some shoes").
See Intents and invocation for more information on how these invocation models work.
Define a default Action
Every Action package must have one and only one intent that handles the
actions.intent.MAIN
intent. This intent is triggered when users invoke your
Action by name (for example, "Hey Google, talk to ExampleAction").
To generate a boilerplate Action package file named action.json
, take the
following steps:
- Download the
gactions
CLI. - Create a local directory for your Action project's source files.
Run the following commands in the terminal:
$ cd PROJECT_DIRECTORY $ gactions init
Once the Action package file is generated, replace placeholder content with your
values. Here's an example of action.json
with changes for ExampleAction
:
{ "actions": [ { "description": "Default welcome intent", "name": "MAIN", "fulfillment": { "conversationName": "ExampleAction" }, "intent": { "name": "actions.intent.MAIN", "trigger": { "queryPatterns": [ "talk to ExampleAction" ] } } } ], "conversations": { "ExampleAction": { "name": "ExampleAction", "url": "https://www.example.com/ExampleAction" } }, "locale": "en" }
Define additional Actions
You can provide additional Actions that act as entry points. This lets users disambiguate their intent by letting them specify more details about what they want to do (for example, "Hey Google, talk to ExampleAction to find me some shoes.").
To define additional Actions:
-
In the
For example, the following code shows an additional "buy" Action that defines:actions
array, specify an Action for every entry point.- An intent name of
com.example.ExampleAction.BUY
parameters
to parse from the user input when this intent is triggered. This is useful if you need specific data from the Action phrase when users invoke the Action.queryPatterns
that define what users need to say to trigger the intent. Query patterns can include Schema.org types that define parameters to parse.
{ "description": "Direct access", "name": "BUY", "fulfillment": { "conversationName": "ExampleAction" }, "intent": { "name": "com.example.ExampleAction.BUY", "parameters": [ { "name": "color", "type": "org.schema.type.Color" } ], "trigger": { "queryPatterns": [ "find some $org.schema.type.Color:color sneakers", "buy some blue suede shoes", "get running shoes" ] } } }
- An intent name of
-
Specify the fulfillment for this intent by specifying a
conversationName
that corresponds to an item in theconversations
object.{ "conversations": { "ExampleAction": { "name": "ExampleAction", "url": "https://www.example.com/ExampleAction" } } }
Here's an example of a full Action package:
{ "actions": [ { "description": "Default welcome intent", "name": "MAIN", "fulfillment": { "conversationName": "ExampleAction" }, "intent": { "name": "actions.intent.MAIN", "trigger": { "queryPatterns": [ "talk to ExampleAction" ] } } }, { "description": "Direct access", "name": "BUY", "fulfillment": { "conversationName": "ExampleAction" }, "intent": { "name": "com.example.ExampleAction.BUY", "parameters": [ { "name": "color", "type": "org.schema.type.Color" } ], "trigger": { "queryPatterns": [ "find some $org.schema.type.Color:color sneakers", "buy some blue suede shoes", "get running shoes" ] } } } ], "conversations": { "ExampleAction": { "name": "ExampleAction", "url": "https://www.example.com/ExampleAction" } }, "locale": "en" }