Google Assistant Output
Learn more about output templates for Google Assistant.
Introduction
Jovo offers the ability to create structured output that is then translated into native platform responses.
This structured output is called output template. Its root properties are generic output elements that work across platforms. Learn more about how generic output is translated into a Google Assistant response below.
{ message: `Hello world! What's your name?`, reprompt: 'Could you tell me your name?', listen: true, }
You can also add platform-specific output to an output template. Learn more about Google Assistant-specific output below.
{ // ... platforms: { googleAssistant: { // ... } } }
Generic Output Elements
Generic output elements are in the root of the output template and work across platforms. Learn more in the Jovo output template docs.
Below, you can find a list of generic output elements that work with Google Assistant:
message
reprompt
listen
quickReplies
(called suggestions in Google Assistant)card
carousel
(called collection in Google Assistant)
message
The generic message
element is what Google Assistant is saying (or displaying) to the user:
{ message: 'Hello world!', }
Under the hood, Jovo translates the message
into a firstSimple
response object (see the official Google Assistant docs):
{ "prompt": { "firstSimple": { "speech": "<speak>Hello world!</speak>", "text": "Hello world!" } } }
The resulting speech
property gets automatically wrapped into SSML tags. For text
, SSML is removed.
It's also possible to turn message
into an object with a speech
and a text
property:
{ message: { speech: 'Hello listener!', text: 'Hello reader!' }, }
This is then turned into the following response:
{ "prompt": { "firstSimple": { "speech": "<speak>Hello listener!</speak>", "text": "Hello reader!" } } }
The text
property is limited to 640 characters. By default, Jovo output trims the content to that length. Learn more in the output sanitization documentation.
reprompt
The generic reprompt
element is used to ask again if the user does not respond to a prompt after a few seconds:
{ message: `Hello world! What's your name?`, reprompt: 'Could you tell me your name?', listen: true, }
Under the hood, Jovo translates the reprompt
into NO_INPUT_1
, NO_INPUT_2
, and NO_INPUT_FINAL
.
Note: For Google Assistant to wait for a user to answer a question, the listen property needs to be added.
listen
The listen
element determines if Google Assistant should keep the microphone open and wait for a user's response.
By default (if you don't specify it otherwise in the template), listen
is set to true
. If you want to close a session after a response, you need to set it to false
:
{ message: `Goodbye!`, listen: false, }
If listen
is set to false
, Jovo sets the expectUserResponse
in the Google Assistant response to false
.
The listen
element can also be used to add dynamic entities, called type overrides in Google Assistant. Learn more in the $entities
documentation.
quickReplies (Suggestions)
The generic quickReplies
element translates into a concept called suggestions on Google Assistant. You can learn more in the official Google Assistant docs.
{ // ... quickReplies: ['Yes', 'No'], }
Under the hood, Jovo translates quickReplies
into the following:
{ "suggestions": [ { "title": "Yes" }, { "title": "No" } ] }
If you define your quickReplies
using objects instead of strings, the text
property will be used for the resulting title
:
{ quickReplies: [ { text: 'oh yeah', // this is used for 'title' value: 'yes', }, // ... ], }
card
The generic card
element can be used to display a basic card in Google Assistant. Learn more about basic cards in the official Google Assistant docs.
{ // ... card: { title: 'Hello world!', subtitle: 'Some subtitle', content: 'Welcome to this new app built with Jovo.', imageUrl: 'https://jovo-assets.s3.amazonaws.com/jovo-icon.png' }, }
Under the hood, this gets translated into the following object as part of the response to Google Assistant:
{ "card": { "title": "Hello world!", "subtitle": "Some subtitle", "text": "Welcome to this new app built with Jovo.", // Taken from 'content' "image": { "alt": "Hello world!", // Taken from 'title' "url": "https://jovo-assets.s3.amazonaws.com/jovo-icon.png" } } }
carousel (Collection)
A generic carousel
element is a horizontally scrollable set of card
items. In Google Assistant, this is called a collection. Learn more in the official Google Assistant docs.
{ // ... carousel: { title: 'Select an element', selection: { intent: 'SelectElementIntent', entityType: 'ElementType', }, items: [ { title: 'Element A', content: 'To my right, you will see element 2.' selection: { entities: { element: { value: 'a' } } } }, { title: 'Element B', content: 'Hi there!', selection: { entities: { element: { value: 'b' } } } } ], }, }
It includes the following properties:
selection
(required): This is used to map a selection of an item to both anintent
and anentityType
. The type is needed to create a type override (see official Google documentation).items
(required): An array of elements to be displayed. They also need to include aselection
property with anentities
map. If the array consists of only 1 item, the output is converted to acard
.title
(optional): A string that gets displayed at the top.
Google Assistant Output Elements
It is possible to add platform-specific output elements to an output template. Learn more in the Jovo output template documentation.
For Google Assistant, you can add output elements inside an googleAssistant
object:
{ // ... platforms: { googleAssistant: { // ... } } }
nativeResponse
The nativeResponse
property allows you to add native elements exactly how they would be added to the Google Assistant JSON response.
{ // ... platforms: { googleAssistant: { nativeResponse: { // ... } } } }
You can find examples for the Google Assistant response format in the official Google documentation.
scene
By using nativeResponse
you can add information about Google Assistant scenes like this:
{ // ... platforms: { googleAssistant: { nativeResponse: { scene: { name: 'SceneName', slots: {}, next: { name: 'SomeScene', } } } } } }
This way, you can transition to a scene (like SomeScene
in the example above).