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.
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 install node// now test it in terminal
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.
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
- Cloud Firestore Triggers
- Realtime Database Triggers
- Remote Config Triggers
- Firebase Authentication Triggers
- Google Analytics for Firebase Triggers
- Crashlytics Triggers
- Cloud Storage Triggers
- Cloud Pub/Sub Triggers
- HTTP Triggers
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.
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.