r/javascript • u/theQuirkyTurtl3 • Mar 24 '19
I used Google Actions to keep track of my coffee consumption
Last week I started a personal blog called #myweekinjs. Essentially, I build something use JS and talk about what I did to build it. I am building these projects for about an hour a day after work so the scale or "fanciness" isn't that overwhelming.
This week I used Google Actions and Firebase Cloud Functions to keep track of the number of coffees I drink a day. I published the article here. All the code is available on Github if anyone wants to have a look at how (surprisingly) easy it actually is.
For anyone who is interested, the website is built with GatsbyJS.
7
u/kitaooji Mar 24 '19
Nice little thing you got there.👌 How do you trigger the intent? Do you just ask Google Assistant to add X coffees? If so how did you hook the firebase function to Google Assistant so that when you ask to add X coffees it knows to call the Firebase function?
6
u/theQuirkyTurtl3 Mar 24 '19
Cheers! You have to setup a few things first. One is a trigger to initiate it, in my case it is "Talk to Life Style". Then from there I can say "add X to coffees". A lot of the configuration is actually done through Actions on Google, DialogFlow and Firebase to connect all the parts together. A bit of Google magic "unfortunately" but once everything is connected it is awesome.
3
Mar 24 '19
This would be great for budget tracking. Of course, Google Assistant will probably add "ate E sense" to my expense column.
3
u/theQuirkyTurtl3 Mar 24 '19
I did think of that but I'm scared to see how much money I spend on coffee over a week haha I've gotten some shocking interpretations of what I said before.
3
Mar 24 '19
I just saw recently what I've spent in my entire time using Steam, and I'd really rather not think about it either 😅
1
3
u/bobbybonanza Mar 24 '19
Using Google Actions, is the only way to initiate via a "Hey Google, talk to xxx" command?
With IFTTT's integration, I canset up a command like "add X to coffees" that can be triggered directly from Google Assistant without first doing a "Hey Google, talk to xxx".
Do you know if there's a way with Google Actions to have Google assistant recognize the phrase without first doing a "hey Google talk to xxx" and then telling Google to "add X to coffees".
(I'm leaving out details about how the action is handled in IFTTT in response to my voice asking, "add X coffees", but IFTTT will parse out the X value to send to some defined backend service.)
1
u/theQuirkyTurtl3 Mar 25 '19
Not really sure. I know you can just string them both together in one sentence and it'll work. Like I said, I only have a small amount of time to work on these so if something works I just continue haha but it would be a lot better to just say the intent without the "hey google" bit
5
3
u/FrozenInferno Mar 24 '19 edited Mar 27 '19
So you used JavaScript to script your java?
2
u/theQuirkyTurtl3 Mar 24 '19
The Cloud Functions can be written in either Nodejs or Java, I used Node. Then the Stats page on the website is built with React 👌
2
u/jaman4dbz Mar 24 '19
How many total hours did it take you to make this do-dad. I feel like I would gotta stuck on one api or another and took a month to complete it :p
2
u/theQuirkyTurtl3 Mar 24 '19
Total was about 5 hours (for the Action bit) maybe another 2/3 for adding the Stats page on the website. The documentation is actually pretty good which helped a lot! Normally I'd be in the same boat haha
1
u/TotesMessenger Mar 25 '19 edited Mar 26 '19
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
[/r/googleassistantdev] I used Google Actions to keep track of my coffee consumption
[/r/reactjs] Statistic page pulls in firebase data using hooks on a Gatsby site.
 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
-10
u/s0lja Mar 24 '19
You know if you have a little self control you wouldn't need such tools. I can't believe people relying on technology for small things that can be controlled and keep in check with a little self discipline.
2
4
17
u/kogsworth Mar 24 '19
Pretty cool! You could add threshold parameters like 1 coffee per 4 hours or 3 coffees a day, so you could ask it 'Can I have a coffee right now?'. Advanced mode would be to add support for an internet connected coffee machine, and having it count your coffees automatically as it brews them and/or refuse to brew them if it exceeds the threshold