What does it take to build a Chatbot for your application?

Leverage Kore.ai bot platform to build smart chatbots that can work at scale.

Vishnu Kumar Nekkanti
Towards Data Science

--

You might have spent hours on end to build your application that has the best in-app user experience, but you fall short when it comes to building the latest and hottest feature in the market — A conversational interface that you can integrate with messaging apps, emails, voice assistants, IVR and many other channels.

What now ?, Should you start research on building the conversational agent? What should you think about ? …..

A lot actually. You have to think about a lot, to name a few — Let’s consider that your application can Order a Pizza for ‘take away’ and check the status of the order.

  1. (Intent Detection) How to figure out what the user says to the bot. i.e how to understand if user meant to place an order, check order status or something else entirely (this might sound simple in this toy example but it gets complicated when your application can perform tens of actions)
  2. (Entity Detection) How to extract information required to perform an action on your application. i.e in the user utterance “i want to order a pizza with chicken, onion toppings and 2 coke on the side” what is the crust? , what are the toppings?, what are the sides? etc
  3. (Entity Validation) How to validate information provided by the user. Ex: Date, Currency, number, items etc
  4. How to handle interruption from the user while performing an action. i.e before completing the conversation to “Place an order” if the user asks “What is the status of my order with Id ABCD”
  5. (Channel Integration) How do I integrate this bot with Facebook or Alexa or Google Assistant etc?
  6. How do you analyze failed conversation with the users ?
  7. How do you authenticate the user ?
  8. How can you conditionally control the conversation ?. i.e if the user provides an invalid number of toppings, how to inform him and ask for a different preferred toppings ?
  9. How do I make it work for multiple languages ?

so on….

Before we go any further, You might want to stop me and point out at some platforms like Luis, Dialog Flow, IBM Watson etc… sure they can help you with #1, a little of #2, limited of #3 and few in #5, but remember the list of requirements to have a good Chatbot goes on further. You can have a great team that can build the rest of the bot, at what cost ?… At the cost of a great amount of time. You would Ideally want the ‘go to market’ time to be as short as possible without compromising the quality and functionality. This calls for a tool that already solved all the problems — Kore.ai bots platform, the conversational platform that enables you to build and manage conversational bots for hundreds of use cases.

How is it different from other platforms?

Well, Like any other platform out there Kore.ai also solves #1, #2, #3. And also every point mentioned above and then a lot more. The platform provides a complete Development toolkit required to build and manage a bot without having to build a separate back-end service for the bot. It’s easier to show you, Let’s jump into the platform and build toy bot. If you need more information or help at any point refer to the documentation at https://developer.kore.ai/docs/bots/chatbot-overview/chatbot-overview/

Pizzeria Bot

Lets say you have a Pizzeria where people can order take outs for one pizza with choice of Crust, up to 3 toppings and some sides. You built an application (just assume that you have it) where people can order online. Now let’s build a bot for this Pizzeria where one can Order one Pizza for take-out with the choice of crust, toppings and sides, it should also be able to check status of the order when asked.

First Sign up/login at https://bots.kore.ai . Click on create a bot and give it a name, select language (let’s go with English for now) and let the bot type be Standard (check out what each type means in the documentation later). Now, you will land on bot details a page like this

Bot details page

Explore this page and then head to bot tasks in the menu on the left. In the bot tasks page you will see several bot task types that you can create

Types of Bot Tasks

For our Toy Bot we will focus on Dialog Task, these tasks represent a full conversational flow between a user and a Bot as a directed graph. This helps you design complex conversations that involve conditional actions, i.e lets say in the “Order pizza” task the maximum number of toppings allowed on a pizza is 3, you can check this and inform the user to choose again without having your back-end application involved.

Now lets create two dialog task :

  1. “Order a pizza”, which allows user to order a pizza with the choice of crust, toppings and sides.
  2. “Check order status”, which can check the status of the order placed.

Lets look at the finished “Order Pizza” dialog first and then see how it was built (I will be providing links to detailed documentation which can be ignored for the toy example, but do check them out later)

Order Pizza Dialog

On seeing this the your first thought should be “what are the nodes in the graph?”. Well, These are called Dialog components and Kore.ai platform provides several types of dialog components, Let’s briefly see what they are :

  • Intent Node (User Intent ) — The node associated with a user intent i.e “ordering a pizza” is an intent. When an intent is recognized by the Kore NLP engine, it corresponding intent Node is triggered (Usually the root node of a Dialog task, I say “usually” because it can also exist as a non-root node which we will look at in a later post). So if the user intent is to “Order a pizza” then “Order a Pizza” intent node in “Order a Pizza” Dialog task is triggered. You may read more at https://developer.kore.ai/docs/bots/bot-builder-tool/dialog-task/working-with-the-user-intent-dialog-node/
Intent Node
  • Entity Node — The node that requests the user for an entity (If not already provided by the user) Ex : date, time, number, phone number etc. Apart from the system entity types that the system validates automatically, you also have the option of having some very useful custom entity types like string, custom/RegEx, Composite, “List of values Enumerated” and “List of values Look up”. You can read more about this at https://developer.kore.ai/docs/bots/bot-builder-tool/dialog-task/working-with-the-entity-node/
Entity Node
Entity Node Properties
Message node
  • Script Node — This node allows the user to write JavaScript to work with the data received until now and update bot context (contextual memory). For example in our toy bot we use this node to check if the user asked for more than 3 toppings and decide whether or not we ask for toppings again.
Links between toppings and Validate Toppings count script
Script node Properties

One other thing you might be wondering about is “How are the connections defined?” — Each node has connection properties where one can define a default transition and if/else conditions as per requirement. For example : Transitions from ValidateToppingCount script node in “Order a Pizza” dialog task.

Example Transitions

And Wait! what about the information gathered from the conversation, “How can I access the data ?” — All the data that is gleaned from the dialog and responses of “service node calls” is available in “context” JSON,Ex entities are at Json path context.entities.<entity name> i.e for the choice of crust (crust entity value) is at context.entities.crust

Sample context json

Now, Coming back to our Toy bot with “Order a Pizza” dialog task, you might have figured out the flow by now

  • On recognizing the intent as “order a pizza”, trigger “Order a Pizza” intent node in “Order a Pizza” Dialog task.
  • Transition to “crust” entity node and ask the user for choice of crust if not already mentioned. This is a single item “List of values (enumerated)” entity, which requests for an enumerated list item defined by the developer (you)
  • Transition to “topping” entity node and ask the user for “choice of Toppings” if not already mentioned. This is a Multi-Item “List of values (Enumerated)” entity, which looks for more multiple items from list.
  • Transition to ValidateToppingCount script node where the number of topping asked by the user is verified.
  • If the toppings count is greater than 3, forget selected toppings and transition to “topping” entity.
  • If the toppings count is less than or equal to 3 then transition to , “sides” entity node, where the bot asks for sides.
  • With all the details now collected, send the data to you application server using the service node and confirm the order. Although for this toy example I am hitting dummy endpoint (will remove this node before sharing it with you, as it is useless) that always return status 200.
  • Respond with message in “order placed” message node and you are done.

Here’s a video walk through

Order a Pizza Dialog Run

Order pizza dialog is complete… Or not, what about the Natural Language training ? All Chatbot platforms ask for training data right, what about kore — Yes Kore does that too, the topic of Kore.ai’s NLP is for another day’s post. As of now the bot is working with its knowledge of English language grammar and just the task name.

I will remove the service node since its useless and attach the Bot export at the end, which you can import into your account and check it out. Also, I left a few things out so you can try out

  1. [EASY] Make the bot show a different message when too many toppings are provided. Do this without adding any more nodes
  2. [HARD] The “sides” entity will only take <count + item> and not just the item without number, i.e saying “2 coke” will work but won’t work when I just say “coke”. Make it work (Hint in the video)
  3. [EASY] Again, in the sides entity, the bot won’t take no for an answer. i.e it will keep asking the user to provide at least one choice of side. Make it optional. (Hint : check out the instance properties)
  4. [MEDIUM]A more complex dialog to order multiple Pizza by adding at most 3 nodes (2 is best) Hint : collect and confirm.

Whats coming in the future post?

  1. Add “Check Order status” dialog.
  2. Enabling Channels.
  3. A Look at Kore.ai NLP engines.

Data

Bot Export = Pizza Store.zip at https://github.com/vishnukumarnekkanti/BotsData

--

--