Google assistant says hello to your nodeJS service V1

Google Assistant and NodeJS service.

Google assistant Action (application) that you can create and deploy in a few easy steps.


Get a nodeJS service to drive a communication over Google Assistant. Assuming you have a google Deverloper account and know how to go through the basic configuration. The steps bellow are filtering out all the confusing options you have on how to interact with Google Assistant.

We will create an Action (Think of it as an application that the Google assistant launches on user's request). Then we will use the DialogFlow to configure the Intents (trigger words) that will forward the data to a nodeJS service that we will setup.

Invoke the first call to your script

Create/Import a google project

Creating the project is pretty straight forward. Make sure to pick a name for your assistant that will be easy to pronounce and the speech recognition will understand. It will make your life easier here, if you pick a common word. 

Assistant app configuration panel
You don't need to do much here. Go ahead set images, name and other details

Add new Agent in DialogFlow

Here you will create a Dialog flow project and link it to a google Project

Select V1 API that will be more compatible with the SDK but you can experiment with V2 as well and checkout the calls you'll be getting from the Agent.

main Dialogflow console

When you make changes to the above you will need to load and start again your agent by clicking TEST DRAFT in the Overview page of the Action's project

Main configuration point for the assistant app

Follow the page instructions to set up the basics about your Assistant.

Main configuration

Main configuration - App information

In App information section you can set up your assistant's looks. Like other google applications, you can set the display images, description etc. At the very start you can set your Assistant's name and pronunciation of it.

Here you will set how the user will activate (invite in the conversation) the assistant.

Prepare ngrok (expose localhost to a random external url)

Download ngrok from the link bellow, and simply expose the port that your server is going to listen on. For example:
./ngrok http 8000

Link the webhook

Now you are ready to set this URL on your dialog flow project. Select Fulfillment from the sidebar options and enable the Webhook. Enter the URL from ngrok's output in the URL field.
[Remember every time you reload your ngrok a new URL will be created, so you will need to come back to this page and update the entry]

Point the Webhook to your ngrok url

Trigger your first call to verify the connection

To test your webhook you can trigger now your assistant and check an incoming call to your ngrok output.

To start interacting with the assistant we need to setup a few Intents in the Dialog flow.

List of registered intents

The default and welcome intent are useful to get you to understand how intents work, for now we can leave them as is.

Intent definition

We need to create a new Intent,

  • name it "good morning"
  • set what the user will say to trigger this intent ("good morning")
  • you can set the text response to check that you intent works (not needed as we will reply from the webhook, but it's useful as a fallback response in case your script fails)
  • don't forget to check the fulfilment section to "Use webhook" (this will enable the intent to forward a request to your service  

You can use the section on the right side to test your intent as if the assistant is already activated, but you can do this in you real assistant (home, android, iphone etc) since your own account is enabled to be a tester to begin with.

to Test you intent and current configuration, go back to the main configuration page for the Action select the project you're working on and click Test Draft (no need to submit for publish)

Remember to use this anytime you make modification to the core project (not the Dialogflow)

Create a nodeJS project (or start with miss-duck) (instructions on Readme file)

const express = require('express')
const app = express();
const bodyParser = require("body-parser");
const Duck = require('./duck');

app.use(bodyParser.json());'/', (req, res) => {
const duck = new Duck(req, res);

app.listen(8000, () => console.log('Duck service!'))

In the main file:

  • set the port to 8000 (same one bound with ngrok to be exposed publicly) 
  • import our module (Duck.js)
  • make a new instance of the Duck class (module) (good practice if we need to scale our app later)
  • within that module we use take care of the "req, resp", so we don't need to do more here

const DialogflowApp = require('actions-on-google').DialogflowApp;

class Duck {
constructor(request, response) {
const app = new DialogflowApp({
request: request,
response: response
const MORNING_INTENT = 'input.morning';

function morningIntent(app) {
app.tell(`good morning to you too!`);

const actionMap = new Map();
actionMap.set(MORNING_INTENT, morningIntent);


module.exports = Duck

in the duck.js module:
  • import the DialogflowApp from the actions-on-google project
  • create an application object providing the request and the response
  • define the intent (should match the one configured in the "good morning" intent from the Dialogflow console.
  • create the handler function (morningIntent)
  • call app.tell() to make the assistant reply (this will replace the fallback response we defined in the Intent's configuration page
  • create a Map object and pass in a list of intents and the corresponding handler-functions
  • call handleRequest providing that Map

Running the assistant

You have a few ways to test your intent. 

a) from the DialogFlow console, when you define the intent you have direct access. On the right hand side you can see a "chat" window where you can type in the keyword to invoke your intent

b) in the simulator environment from the Action's console or from any device you already have access to your Google Assistant. This way, you will get the full experience. First, you need to activate the assistant. In our example we should type in (or say) "Talk to miss duck". Then the welcome intent will fire. (If you use a real Google assistant, first you will need to activate the main Assistant by "Hey/Ok Google").

Now you need to make sure while you're testing, when the Main Assistant is responding or yours. You should be able to see in the graphical interface the messages when Miss Duck "leaves" or you should notice a different voice when another Assistant is responding to your requests.

This is only the beginning

In a few steps we created a simple NodeJS service to handle input from a Google Assistant Action. Pretty basic setup to help you extend the basic flow and forward the communication from the users to your service. Try these first steps and continue by learning the best practices on how to provide a bi-directional communication fro great User eXperience. 



  1. You can use this program to evaluate, treat, and measure results. You can visually see how different words and phrases are spoken RoseMedical icSpeech Professional 3.6.0 Crack

  2. Synthesia Full Version lets you learn and play piano directly from your computer. The program can teach you to play piano with ease. Synthesia Free Download Full Version

  3. Merry Christmas To The Love Of My Life! Sending special wishes of Christmas cheer to the one I love so dear. I hope your day is as wonderful .Merry Christmas To The Love Of My Life


Post a Comment

Popular posts from this blog

Medium Publications

JavaScript CI Simple Start