Node.js + Google Assistant Integration

In this article, I will be showing you how to create a simple Node.js application that we can integrate with Google Assistant(and also with Google Home) and can handle the requests coming from the device. I have also used the weather service from Watson and Google’s Geoencoder API in this demo.

Running your app locally —

  1. Clone/Download zip of repository. Github link —
  2. Extract content of the zip.
  3. Open cmd to run the following code -
cd "folderpath where zip is extracted"
npm install

4. After the installation, run -

npm start

Setting up the ngrok link for your app —

  1. For this we will install ngrok. Download from here —
  2. Open another terminal and run the following command -
ngrok http 8080

8080 is the port number on which our app will run.

3. After that you will get a black terminal screen. Look for url after forwarding. It will appear similar to —

Keep a copy of it as it will be used later on to set up fb app.

Setting up the .env file

  1. You need to register for google geoencoder api from here —

Copy the API KEY in the .env file.

2. You also need to have a bluemix account and should have credentials for the Weather API. You can get it from here —

Copy the Username and Password of the SERVICE (by clicking the View Credentials menu) in the .env file.

Setting up the google actions —

1. Visit the following link —

2. Click Sign in with Google.

3. Click Create Agent on the top left.

4. Type in MiniHome and click Create

5. Now create an intent. Type in as shown. Put intent name also as HomeMini.

6. Double tap on whatever you typed in User says and chose the option as @sys.geo-state-us.

7. It will look like this -

8. Go to fulfillment tab on the left.

9. Enable the webhook.

10. Enter your ngrok domain followed by /weather.

11. Click Save at the bottom of the page.

12. Go to your MiniHome Intent.

13. At the bottom you will see Fulfillment. Click on it.

14. Enable Use Webhook option.

15. Go to Integrations Tab on left.

16. Click on Google Assistant.

17. Select Whats the weather intent in implicit invocation.

18. Click Test.

19. Keep the new screen open and set up the nodejs application.

Testing —

That was the end of the basic tutorial integrating Google Actions with Node.js. If you encounter any doubts, feel free to message below.