Google Assistant – How to create a simple chatbot

Google Assistant – How to create a simple chatbot

Hi,

I have used Google Assistant to build a simple chatbot that lets the users to manage team building locations (venues). A venue consists of these properties: number of rooms, number of guests, location and a short description. At this point the bot adds a venue in the system. Search functionality will be added later.

The steps that I followed to create this bot were:

1. Design the bot

2. Install the tools and write the code

3. Test and Deploy

Let's take one step at a time.

1. Design the bot

For this you can use some tools that are available online. I have used and recommend draw.io, a tool that draws many types of diagrams and lets you save them even in Google Drive.


2. Install the tools and write the code

The tools and technologies I’ve used are:

  • Node.js
  • DialogFlow – Platform used for building bots (owned by Google).
  • Firebase – Development platform used to build, monitor and host projects (owned by Google)
  • Cloud DataStore – NoSql database service (owned by Google)

3. Test and Deploy

The bot can be easily integrated with lots of different frameworks: Facebook Messenger, Slack, etc. The advantage is that you write your code once and you can deploy to multiple platforms very easily, like below:

DialogFlow has its own framework that lets you test the bot directly in the browser by typing commands or by voice.

CHALLENGES

One of the challenges that I faced was that I had to perform validation for Date fields. In more detail, I had to force the bot to re-prompt the user if the check-out date was earlier than the check-in date. In order to do this I had to follow several steps:

  1. Identify the slots that require validation.
  2. Remove them from the current intent.
  3. Create separate intents for each slot that require validation.
  4. Enable webhook for those intents.
  5. In the webhook, if the validation fails, set the output context same as the input so as to trigger the same intent.
  6. Respond back with re-prompt response.

A code snippet can be found below:

// validation
const checkInDateString = conv.contexts.get('checkin_date').parameters[CHECK_IN_ARGUMENT];
const checkOutDateString = conv.parameters[CHECK_OUT_ARGUMENT];

if (!validation.isCheckOutDateValid(checkInDateString, checkOutDateString))
	{		
		// set the output context the same as the input
		conv.contexts.set('checkin_date',1);
		conv.ask('Please pick a check-out date that is later than the check-in date!');				
		console.error('The check-out date must be after the check-in date!');
	}

CONCLUSION

It's been an amazing experience where I've learnt lots of new technologies and tools.

For more information you can find the source code along with the DialogFlow intents at this github repo.












To view or add a comment, sign in

More articles by Andrei Petrut

Others also viewed

Explore content categories