Building a personal bot in 5 mins with zero coding

Valentino Ugbala
CodebagNG
Published in
5 min readOct 17, 2017

--

Chat bots are super cool. I’ve always dreamt about having something similar to Iron Man’s J.A.R.V.I.S 😎😎, who wouldn’t?

I thought it would be very hard building a simple chat bot and kept on procrastinating until I was given a task to build one under a week. After much research, I realized it was pretty easy to build basic bots and decided to write about it. I’ll talk about building a basic Profile bot with Api.ai(now called DialogFlow) and adding it to your web page with zero coding.

First the Basics,

The major problem with building bots is understanding the intent of the user.

In the pseudo code above, the bot replies the user based on the text the user enters. This seems to work well but a problem evolves when a user writes a different word that has the same intent(meaning).

Imagine a user asks “where is your location?” or “how can I find you?” instead of the “where are you?” the bot was expecting, the bot won’t be able to reply that. A common solution will be to do this

You might feel happy that your bot is ready, but what happens when your bot has to reply more questions and each question can be asked in more than 6 different ways? Does that mean you’ll have to write 30+ “if user entered …?”, assuming your bot just answers 5 questions? and if you do that what happens if your bot has to answer more questions?

Well like you thought, It’ll be insane to write a series of “if’s ”. It makes your bot very rigid. For your bot to be flexible, it needs some form of Natural Language Processing(NLP) to be able to understand the intent of the user when he asks a question.

First a bunch of if statements and now NLP!!!…. There’s no need to get agitated at this point. Thankfully there are lots of applications around that help take care of the Natural Language Processing part in chat bots and it’s super easy to set them up. One of such is Api.ai(now called DialogFlow).

Enough talk, let’s build our Profile Bot.

Setup Api.ai account

  • Fill in the details about the agent(bot) and save

Create Intents

Intent is the intention(..lol) of the end user when asking a question. A user can ask the bot “where is your location?” or “how can I find you?” or “where are you?”. These questions when looked at closely have the same intent => “location”. The end user can also send “hi”, “hello” or “hey” and the intent in this case is “Greeting”. Intents need to be created for the bot to work with. Let’s go ahead doing that!

  • Click on CREATE INTENT
  • Name the intent “Greeting” then add “hi” and “hey” as user expressions
  • Fill in “Hi there” in the Text response panel. This response is given anytime your bot is asked a question that matches the “Greeting” intent. Click on the Save button.

Test Bot

Head over to the test panel and enter “Hi” or “Hey”. You will realize that the bot responds with “Hi there”. Things get interesting when you enter “Hello”; You’ll still get a response of “Hi there”, despite the fact that we didn’t put that as a user expression. The bot takes in the end user’s text and compares it with the various intents we have saved and their sample expressions. It checks for the intent which best describes the user’s input and prints out the text response for that input. That is why “hello” has the same text response as “hi” and “hey”.

Although, trying out words like “what are you?”, “who are you?”, you realize that the bot gives responses that show it does not understand what we have asked. This is because, every agent(bot) on Dialogflow comes with a “Default Fallback Intent”, which has a list of responses that can be sent when a user asks a question whose intent has not been saved. You can decide to disable it, but it’s better to leave it enabled.

Following similar steps, you can create the following intents for your bot.

Remember to save once you have completed filling the details for an intent. You can continue testing on the test panel.

Add to website

We have a working bot but it will be better off on a website and not just Dialogflow’s console.

  • Go to Integrations on the side bar and enable web demo
  • Click on settings , a modal will popup containing the link for the bot’s default webpage and an iframe you can embed in your html code.
  • If you decide to go with the iframe, all you need to do is copy it and paste in your html code like I did below. You can view the codepen here.

Conclusion

Lest I forget, Dialog flow also offers speech recognition (try using the microphone) 😎.
Voila!!!! You have your personal profile bot!…. I am afraid it’s not in the same league with J.A.R.V.I.S 😞, not there yet, but pretty close! You can build upon this and add more intents to make your bot more fun…...Enjoy!!!!!

--

--