Assistant & … Pizza 🍕 — Tips & Tricks — Part 5

Build Actions on Google Assistant with Kotlin! — Utility in Kotlin

Omar Miatello
3 min readMar 17, 2020

This article is part of a series “Build Actions on Google Assistant with Kotlin!”
Overview | Dialogflow | Intent | Backend | Tips & Tricks

Previously on Incredible Amazing Pizza!

We want to help the customers of our imaginary “Incredible Amazing Pizza” restaurant, we create and manage the intent Ask Ingredients to respond to “What’s a Margherita like?”.

Now a few tips to improve our Action.

Final tips

Tip #1: Test on your device

Open the Actions on Google console, after the first test on the website, you can test your Action with Google Assistant on your device.
NOTE: The device needs to be logged with the same Google Account.

Just try, talk to your smartphone (or Google Home) and say: “Ok Google, talk to Incredible Amazing Pizza”.

It should work! 😁

Tip #2: Let’s make a good impression, handle the first visit!

You should handle differently the first visit and the following.

In the first visit, it’s important to show what the user can do with your Action, but from the second visit, it could be annoying.

After the first time, you can move faster and just say “welcome back” as if you remember that it is not the first visit.

Remember: repeat the same information can become frustrating to more experienced users. https://designguidelines.withgoogle.com/conversation/conversational-components/greetings.html#greetings-tapering

You can use request.user.isFirstAccess to handle the first visit.

inline val User?.isFirstAccess get() = this?.lastSeen == null

In this example, I defined isFirstAccess as Kotlin Extension property

Tip #3: Add support for multiple languages!

You can support multiple languages using the resources folder.

Define a string (for example bye), add the translation in resource_en_US.properties and in the other supported languages.

In your code add: response.addSimpleResponse(getString("bye")) to obtain the string translated for the current user.

Add resources_it_IT.properties in src/main/resources folder to support the Italian language! 🇮🇹

Tip #4: Add intent: Feedback

Add an intent to obtain user feedback. It’s useful to improve your Action.

Tip #5: Add intent: Bye

The user can always terminate the conversation with “stop” or “cancel” command, but that’s not nice.

Try to understand the right moment, usually when the user request is completed use .endConversation() to close the conversation.

Create a “bye” intent that could be triggered with: “ok, bye”, “stop”, “cancel”, “bye-bye”, “ok, thanks”, and so on …

Tip #6: Kotlin Template based on AoG example

Use my template, it’s based on the official Action on Google example, and use Kotlin extensions to simplify the development of your Action.

You can always read the source code here:

Mission completed! 🎉

You have your first Action, ready to be deployed for everyone or a few friends :)

--

--