When sending responses from our Actions on Google conversational tools, there are a number of different ways in which we can present content to our users. In this post we’re going to look at adding responses to our conversations using the Simple Response.
When building responses for our conversation tools we have the ability to send what is known as a Simple Response — this a response that is supported for both visual (actions.capability.SCREEN_OUTPUT) and audio (actions.capability.AUDIO_OUTPUT) output. Consisting solely of textual content, a visual response will look something like this on screen:
The textual content which is shown within this response has a limitation of 640 characters — if your response exceeds that then it will truncated at the first line break before that limit is reached. However, even though this limit is available it is important to be mindful about just how much content you are displaying within each bubble. Imagine the same scenario as a natural conversation — you don’t want to overwhelm the user, so keep it short and rely only the information that is required.
Creating a Simple Response
To create a simple response, you’ll need to first add it to your imports for the actions on google SDK:
const {
SimpleResponse,
actionsOnGoogle} = require('actions-on-google');
The next step is using your conversation instance to send a response. To do so, you need instantiate a new instance of the SimpleResponse class and provide the content to display.
conv.ask(new SimpleResponse({
speech: 'This is the content that is spoken',
text: 'This is the content that is displayed',
}));
There are two arguments that have been provided here. First of all, speech is a required argument and is the content that is spoken to user. We also have the optional text argument, which is used as the content to be displayed to the user. Seeing as text is optional, if not provided then the content of speech will also be used as the display content as well as spoken.
The two arguments provided here are not required to be the same. You may want to provide additional, non-vital, information to the user on screen that may not necessarily need to be spoke — and vice versa.
The Simple Response is a great way to as questions, end conversation or give display simple content to the user. Remember to bear in mind the content that you are returning with the Simple Response — keep the information simple in order to not overwhelm the user. We’ll explore other response types soon to help you be aware of the best way to display content in your conversations.