My First Action on Google Assistant

Juvar Abrera
4 min readFeb 18, 2018

--

Screenshot from assistant.google.com

What is Google Assistant?

Google Assistant is the one that lives on your Android phone when you say, “Ok, Google.” You can ask questions about the weather, the traffic, or something else.

It is ready to help in over 400 million different devices such as smart speakers like Google Home, Android phones, headsets, smartwatch, Chromebooks, Android TVs, and even iPhones.

My backstory…

I was on my bed while scrolling on my Facebook feed, about to sleep one night, then I saw one of my colleagues made his own application for Google Assistant. I told myself, what if I try to create my own app.

So, I got up on the bed, booted my laptop, and started creating my own app. I didn’t have the knowledge on how to actually create one but I tried to research on how to build one and just saw this one video on how to create from the ground up.

Design

I thought of making an app that is related to health since I’m a Developer of a project called CHITS (Community Health Information Tracking System) in a Research and Development institute at the University of the Philippines Manila. So, I tried to make a basic BMI Calculator.

Develop

I created an Agent at API.ai (currently as Dialogflow) and created one intent. I’m not gonna get too technical about this but basically, this will happen when the user says these phrases.

I started listing out what the user might say in order to execute the intent like:

  • What is my BMI?
  • Calculate my BMI.
  • What is my body mass index?

and more.

For me to calculate the BMI, I’ll be needing their weight and height as parameters. That time, the unit of the weight should be in kilograms and centimeters for the height.

And so, whenever the intent is called, it will automatically ask the user for their weight and height.

Since API.ai cannot calculate or do logic stuff, I’ll be needing a webhook or what they call Fulfilfment where API.ai passes the data to the webhook, do its calculation and return the result.

I created a new project at Google Cloud Platform where I can store my function to do the calculation whenever API.ai sends the weight and height. My function will calculate and return a response on what Google Assistant will say next.

function calculateBMI(assistant) {
let h = assistant.getArgument('unit-length');
let w = assistant.getArgument('unit-weight');
let bmi = (w.amount / (h.amount/100 * h.amount/100)).toFixed(2);
let category = getCategory(bmi);
assistant.ask('Your BMI is ' + bmi + '. ' + category);
}
function getCategory(bmi) {
if(bmi < 18.5)
return "You're currently underweight. Eat more foods.";
else if(bmi >= 18.5 && bmi < 25)
return "Great job maintaining your normal weight!";
else if(bmi >= 25 && bmi < 30)
return "You're overweight. I recommend you take your exercises every morning.";
else
return "You're currently obese.";
}

NOTE: This is an old version and will not work on current Dialogflow API.

Deploy

To test it out, Google provided a simulator to see what would happen if it was deployed on a smartphone or Google Home since I didn’t have Google Home nor Google Assistant on my phone.

This is what it looked like when you interact with it.

Sharing what I learned

After creating my first application, I’ve been sharing on how to Build An Application for Google Assistant and reached over 1,600 students in different universities in the Philippines.

Vuja de Tech Talks 2018 — January 20 at UST Manila
Google I/O 2017 Extended Naga — August 12 at Ateneo de Naga University
Google I/O 2017 Extended Palawan — July 28 at Palawan State University
Google I/O 2017 Extended Palawan — July 15 at University of the Philippines Los Baños
Google I/O 2017 Extended Baguio — July 8 at University of the Cordilleras

Create Your Own

If you have an idea of an app for Google Assistant, build your first app with Dialogflow now, deploy your app and enjoy community benefits like a FREE t-shirt, $200 Google Cloud credit, and even showcase your app at the Google I/O 2018!

--

--

Juvar Abrera

Developer at National Telehealth Center — University of the Philippines Manila