Google Assistant: Bring Development to your Local Machine

Akshay Nandwana
Voice Tech Podcast
Published in
5 min readJul 20, 2019

Welcome to the fourth article of the series. Hope you had great fun creating count characters and win cool Google Swags. If not, please give a read to the previous article and Win the Prizes.

In this article, we are going to learn about how to bring development to our local machine. We are going to work on the terminal and also see about Node.js, Firebase command-line and text editor. Before starting with this article, if you are new to Actions on Google, please familiarize yourself with the previous articles in series.

Let’s begin with the Node.js.

Node.js is an open-source server runtime environment which allows you to run JavaScript on servers. Node.js uses asynchronous programming. It is a design pattern which runs the non-blocking code execution.

We have Modules in Node.js which are same as JavaScript Libraries. Set of Functions which we require in any of our project to perform specific tasks. Single File. And, A package is a directory of Modules and also consist of package.json file for metadata info.

So, To manage all these packages we have a manager which makes our work very easy is called NPM — Node Package Manager. This manager gets installed when we install Node.js.

Download Node.js from the official website https://nodejs.org/en/download/

If you are on a mac using brew, it will be very easy to set up Node.js. All you need to do is:

brew update
brew install node
// now test it in terminal
node -v
npm -v
// update node if you had old version
brew upgrade node

know more about Homebrew here. 🍺

If you are on windows, simply follow the wizard you get after double-clicking on node.js MSI file which you had downloaded from the official website. It is very easy and after installation, you can test it on command prompt — cmd.

node -v
npm -v

Let’s talk about Text Editor now. We have different options like WebStorm, Atom or Sublime. Setup any of the text editor and let’s go to step three.

Now, we are going to install the Firebase Command Line Interface. The Firebase Command Line Interface allows us to view, manage and deploy to firebase projects. To begin with this step, I hope you had done with npm installation. We are going to require npm for this step.

Cloud Functions for Firebase

Cloud Functions helps us to run the backend code on any specific event or action took place. For example — the user asks the assistant to know about our upcoming event. Event data has been added to the Firebase database. Now, it’s the cloud function who will deliver the data from the database to the user whenever it required.

Triggers which cloud function act on

Let’s install the command-line now. Run the below command on your terminal.

npm -g install firebase-tools// to update old firebase command-line interface
npm i -g firebase-tools

Check out here if you get any error after running this command.

// Login on firebase with your same account as on Actions on Google Console and Dialogflowfirebase login

Build better voice apps. Get more articles & interviews from voice technology experts at voicetechpodcast.com

Previously, we are using inline editor provided on the console which is a single file named index.js. When we bring the development on our local machine, this helps us in many ways like you can use version control to control projects.

I am using the project from count characters article.

First, create a folder on your local machine where you want to keep all your project file. Open Terminal and move to that folder.

// Initialize firebase to connect your local project with the project on consolefirebase init

This will ask you which feature you want to use. We will be requiring cloud functions so, move to Functions and press spacebar then hit enter.

Now, it will be going to ask for more things.

Select the firebase project with which you want to connect your Dialogflow project. Select it using spacebar and hit enter. Then select JavaScript and hit enter.

Firebase Initialization Done.

If there is any update available, it will ask you to update it.

Now, I need all my intents and other related files from Dialogflow as a zip. Open Dialogflow console -> Click on the gear icon on the top left ->Click on Export and Import and then click on Export as zip.

Now, put this zip file into your folder. We are ready for deployment now.

Go to your firebase console, Click on the gear icon on top (settings) -> Project settings -> and copy project id.

On your terminal run the following command

firebase use --project <your_project_id>npm installfirebase deploy --project <your_project_id>

Deployment Complete 👍

Go to firebase console -> Click on Functions from the left sidebar and copy the Request URL.

Open Dialogflow -> Go to fulfilment -> disable inline editor -> enable webhook -> paste the URL

Now, Test your action. Click on the “Google Assistant” on the right side.

Congratulations 🎉 We had successfully deployed our webhook to Firebase.

I had added some visual components to the assistant response. We are going to learn about them in upcoming articles.

Don’t forget to create and publish your action worldwide to Win a Google Home and an exclusive Google T-Shirt before 31st July.

If you find this reading useful, please click the 👏 button and share to help others find it! Feel free to leave a comment 💬 below.
Have feedback? Let’s be friends on
Instagram.

--

--

Akshay Nandwana
Voice Tech Podcast

Founder @AndroidEngineers | Ex-Android Engineer @Zee5 @Google @Doubtnut | 9k+ LinkedIn | Jetpack Compose | Android | Kotlin | Ex-GDSC Lead | Ex-GSoC Mentor