Every app is different, and not all app functionality matches an available App Actions built-in intent. For cases where there isn't a built-in intent (BII) for your app functionality, you can instead use a custom intent to extend your app with App Actions.
Like BIIs, custom intents follow the actions.xml
schema and
act as connection points between Assistant and your defined fulfillments.
Custom intents also have intent parameters, which you can map to parameters in
your corresponding fulfillment.
Unlike BIIs, custom intents require query patterns to describe example queries that a user might say. This approach differs from built-in intents, which each model common ways that users express that intent.
Limitations
Custom intents have the following limitations:
- The name of a custom intent must not begin with "actions.intent".
- The name of a custom intent must be unique among custom intent names for your app.
- Only certain data types are available for parameter extraction by Google Assistant. See Supported types for the list of supported types.
- Only the en-US locale is supported for custom intents (device and Assistant language settings must both match).
Supported types
Custom intents support the following schema.org types for parameter extraction:
https://schema.org/Text
https://schema.org/Date
https://schema.org/Time
https://schema.org/Number
Defining App Actions with custom intents
As with other App Actions that use built-in intents, you define a custom intent
in the <action>
element in actions.xml
. Provide the name of
the custom intent in the intentName
attribute, and reference a query patterns
resource file in the queryPatterns
attribute:
<action intentName="custom.actions.intent.EXAMPLE_INTENT" queryPatterns="@array/ExampleQueries">
<!-- Define parameters -->
<!-- Define fulfillment -->
</action>
We recommend naming your custom intents using the prefix "custom.actions.intent" to distinguish them from both built-in intents and Android intents (which function differently). Custom intent names must not begin with "actions.intent", because that namespace is reserved for built-in intents.
For each parameter, provide the supported schema.org type
that best describes the meaning of the parameter. For example, you can use
https://schema.org/Number
to describe a number you expect to receive:
<action intentName="custom.actions.intent.EXAMPLE_INTENT" queryPatterns="@array/ExampleQueries"> <parameter name="number1" type="https://schema.org/Number" /> <parameter name="text1" type="https://schema.org/Text" /> <!-- Define fulfillment --> </action>
Fulfillment definition in actions.xml
uses the same format with custom intents
as it does with built-in intents. The following code describes an App Action
that uses the referenced query patterns to trigger the "EXAMPLE_INTENT"
custom intent and its corresponding fulfillment:
<action intentName="custom.actions.intent.EXAMPLE_INTENT" queryPatterns="@array/ExampleQueries"> <parameter name="number1" type="https://schema.org/Number" /> <parameter name="text1" type="https://schema.org/Text" /> <fulfillment urlTemplate="https://example.com/custom-requests/{?number_of_items,item_name}"> <parameter-mapping intentParameter="number1" urlParameter="number_of_items" /> <parameter-mapping intentParameter="text1" urlParameter="item_name" /> </fulfillment> </action>
Query patterns
Each custom intent you use requires a set of queries expected from the user for that intent. This approach is unlike built-in intents, where queries are already modeled for common ways that users express tasks they're trying to do or information they seek.
In an Android resource file (usually /res/values/strings.xml
), specify query
patterns as items in a string array. When your
App Action is invoked, Google Assistant checks the user query against your
query patterns as part of matching the user's intent for fulfillment. Each query
pattern you provide represents a phrase that you consider valid for the
corresponding custom intent.
When providing query patterns for custom intents, expect each pattern to follow an explicit invocation like "open ExampleApp and" or "start ExampleApp and". For example, consider the following user queries:
- "Hey Google, open ExampleGameApp and start making a cake."
- "Hey Google, open ExampleGameApp and start making an apple pie."
- "Hey Google, start ExampleGameApp and craft 5 cake items."
- "Hey Google, use ExampleGameApp to produce cake 5 times."
To match user queries, provide query patterns that contain the portion of the query after the invocation phrase. For information you want to extract from the query (like text or a number provided by the user), you assign values to the corresponding intent parameter with placeholders in the query pattern.
From the custom intent's <parameter>
element, take the value of the name
attribute, prefix it with $
, and use the prefixed value in your query
patterns. For the actions.xml
file created above in Defining App Actions with custom intents,
the number1
and text1
intent parameters correspond to the query pattern
placeholders $number1
and $text1
, respectively.
The following code describes query patterns that match the above user queries and extract values for item names and the number of items to be made:
<resources>
<string-array name="ExampleQueries">
<item>start making a $text1</item>
<item>start making an $text1</item>
<item>craft $number1 $text1 items</item>
<item>produce $text1 $number1 times</item>
</string-array>
</resources>
Query patterns support Conditionals. For example, "set (an)? appointment $date $time". In this case both "set appointment today at noon" and "set an appointment today at noon" are valid queries.