Build Smarter Chatbots with Google's Dialogflow
NLP  -  Sep 03, 2020

Before you read this post, make sure you check out Part I. Hybrid Bots: How to Best Leverage + Optimize AI Quickly

Quick Recap

The Challenge:
The challenge we set for ourselves was this: take one version of a bot and integrate the bot using the following AI systems-

a.)    Dialogflow (formerly API.AI), owned by Google

b.)    Wit.AI, owned by Facebook

c.)     Lex, owned by Amazon

To make this exercise simple, we will:

  • Use the same decision tree in each bot scenario;
  • Only integrate NLP for one node in our conversation;
  • Use NLP for only one skill set: to answer questions about pricing

We will then A/B test the bots on our website over a period of a month. We will review the results of which bot performed best, as noted by the amount of times it correctly identified the intent of the user and gave an appropriate response.

Training Data:
In a hybrid bot model, training data isn’t nearly so voluminous and we will often rely on the AI systems in place to fill in those gaps of data. Prior to this test, we had run a bot on our website that allows the user to ask an open-ended question, “Ask me anything!”

From the user responses, we collected 100 responses asking about pricing for our product, Instabot. We then pulled them into a pivot table to extract all the unique ways people had asked about price. We will use this as our input for all three platforms.

See the table below:

Table I. Unique Statements Asking About Price

Table I. Unique Statements Asking About Price


In order to give my chatbots a skill of being able to answer questions about pricing, I will first need to create an “Intent”, which is a specific goal the user is inquiring about or needs assistance to fulfill. In this particular example, I am going to create an intent of the user needing pricing information. After the intents are saved, I will write an appropriate response the bot should provide if the user has such an intent.

Creating Intent
With Dialogflow, it’s easy to create a free account with a Gmail address. After your account is created, simply add a new intent, which I named “Pricing” and then tap “Save”.  


Then in Contexts, under “User says”, simply type in the words or phrases for a specific intent. I type in 50 of the unique phrases that we have collected from our initial bot. (See phrases in Table I.)


Creating Responses
You’ll need 2 responses: the first response is for when Dialogflow concludes that the users language has the goal of  finding out about pricing. For the intent of pricing, I write a response for the bot.


One of the most important parts of an effective chatbot is that it builds trust with the user by giving an appropriate answer. Under the ‘Intents’ tab, you can create a response if the bot know it is talking about pricing. If it does not know about pricing, it should have an equally appropriate response.

In Dialogflow, you can create a “fallback intent”, or a response if the bot is unsure what the user wants to do and it doesn’t match any “intent” in the system.

To create a fallback intent, you can click on “Intents” in the left navigation panel, and in the right hand-corner, click on the 3 dots to the right of the “Create Intent” button and tap, “Create Fallback Intent”.

I then type in a default answer of, This would be better answered by my teammate. Let me connect you. Just need some quick information.

This should be a response for all people who ask a question but are not looking for pricing information.


Using Webhooks to Access DialogFlow
It’s that simple. Now, I just have to connect DialogFlow's AI with our bot. I can connect this to a chatbot by using the Webhooks feature. (If you’re not sure what webhooks are, check out this post. Webhooks are a way to easily link to external data and services.) You can use webhooks in many types of bots. We’ll be leveraging webhooks within our own chatbot, Instabot.

In your Application Settings, click on integrations and tap Add/Edit Webhooks, and click “Add New Webhook”.


Once in webhooks, use the Method: Get and type in your API Endpoint. Each API Endpoint will be unique to each account. This is unique to each API provider and will tell our bot to use this data.  We will use the following: (for more information, see this)


We will then tell the webhook how we want the data to be displayed. Under “Request Parameters”, click “Add New”, you can name it “q”. (NOTE: You name it this way because Dialogflow tells you to do so.)

In this case, select “String”. This will tell the webhook that you are expecting an unbroken, unstructured string of letters, numbers, etc. (This could be an e-mail, a word, a phone number, etc.)

Now you need to test your webhook to make sure it works. Click the words, “Test Request” and type in one of your Intent phrases (I typed, “What is the cost?”)  and then hit “Send”.


You’ll receive back a JSON file, which essentially gives you the information pulled from the API in a structured text format. From this file, select what response you would like from your API should the user type in your intent. We want the response named, “Fullfillment”, “Speech” which displays the text we set up earlier.


Next, under Output Parameters, we’ll tap, “Add New” and then we’ll name it “Response” and select, “Result.fullfillment.speech” from the list.


Now save your webhook. Next step: we just have to connect our webhook to the chatbot.

Connecting Your Webhook to Your Bot

Now, we’ll go into our pre-built conversation. I have created a part of the decision tree that allows users to “Ask a Question” and numbered each node of my conversation. Statement 2 is where users can “Ask a Question”. In Statement 3 the chatbot says “Sure! Ask me anything!” and allows the user to put in a free-text response.


As my user types into the free-text box, the bot will send the user input to Dialogflow, which will decide whether it matches our created intent. I want the bot to respond with my pricing response when the intent is pricing; otherwise I want it to use my default response. I’ll open up the conversation node just after Statement 3, which should provide a response to the question, “Sure! Ask me anything!”


In the conversation node following my question, where Dialogflow will provide a response, I use the following line of text:


Let me break down how this works:

·         “[=” denotes that it is a webhook

·         “Dialog.AI.Request” is the name of my webhook

·         “(query:@Statement_3)” tells my chatbot to use the webhook in response to the free text the user has inserted  

·         “Statement 3” is the name of my conversation node

·         “Response” is what I named my output


Now hit “Save”, and you’re all done! Now when people type in free text, if they ask a word or phrase that is part of my intent, the response will be pricing language. If not, the user will receive a default or the fallback response.

You can test it out here when you click on "I Have a Question". Boundary test away, and feel free to send us your feedback at [email protected].

Part One

Part Three

Part Four

Latest from Instabot
Why Chatbots are the Hottest Trend in SMS Marketing

Why use chatbots with your SMS marketing? SMS marketing brings branded messaging directly to consumers’ pockets, letting shoppers opt in to receive notifications and offers wherever they are. 

Learn More
5 Marketing Ideas to Capture and Convert Customers via Text

When it comes to gaining leads and guiding them toward conversion, there’s more to text messaging that you might expect. With the help of a powerful text messaging chatbot, you can automatically capture, qualify and educate hundreds of prospects at once.

Read on for five actionable ideas for capturing and converting leads via text.

Learn More
Harness the Power of OpenAI with Instabot

Power up your marketing game via OpenAI-powered chatbots. With Instabot’s fully customizable script node, you can fully integrate with OpenAI’s robust API playground. Create bots that can answer general knowledgebase FAQs, correct grammar or passages of grammar, create summaries of longer bodies of text, and more. 

Learn More