This article is written in collaboration with tech writer Morgen Henderson.
As chatbot technology continues to gain momentum, interest in using chatbots for business grows exponentially. Fortunately, there are now many tools available that make it possible for even non-programmers to create functional chatbots, some of which are advanced enough to learn over time and provide unstructured interactions.
The keys to AI chatbots are NLP (Natural Language Processing) and NLU (Natural Language Understanding), subsets of AI that have to do with how machines parse and make sense of human inputs. Chatbots can be as simple as interfaces that offer a predetermined set of options and provide a limited range of responses or as complex as Mitsuku, a conversational chatbot that’s won the Loebner Prize four times and is based on AIML. More advanced chatbots include NLP and NLU functionality so they can both accurately respond to many variations of human input and provide variety in responses. Read our guide to chatbots to learn more about their nature and use cases.
The two main phases in building a chatbot are conversation design and the construction of the bot itself. In the first, you’ll use tools to map out all possible interactions your chatbot should be able to engage in. In the second, you’ll use one of the available platforms or frameworks to build the bot itself.
The first step to building an intelligent chatbot is conversation design. This encompasses both flow and scripting: what your bot will say and how your bot will say it. Start conversation design by getting clear on what you want your chatbot to do and what your audience will want from your chatbot. What content will it provide? What questions should it be able to answer? What actions can it take? What might a user ask it? When will it redirect to a live agent?
Once you have that outlined, map out the flow—all possible paths of a conversation. You can do this using a diagramming or mind mapping tool, like Lucidchart or XMind, or a visual tool included in the development platform you choose, if available. It’s important at this stage to consider all the possible user answers to each bot output and the overlap points between different flows. This flow map will serve as the foundation for scripting.
Context, entities, and intent
There are three components to understand when designing a conversation: context, entities, and user intent. A successful AI chatbot will interpret user statements by breaking them down into these categories.
- Context: Where is the user? What time of day is it? What user profile info is available?
- Entities: What objects are the topic of conversation?
- Intent: What does the user want to do?
Here’s an example. Let’s say the user input is “What year was Inception released?” The movie Inception is the entity. Discovering the release year is the intent. Context is more or less important depending on the company and user goals, but can be valuable for scripting (such as writing “good morning/evening” or using someone’s name once they’ve provided it). In the example above, an answer could include the user’s name, if available, or use demographic data to make a joke, if that fits with the chatbot’s personality.
NLP systems use these three variables to parse inputs and plan responses. So, when you’re thinking of possible flows, it helps to consider all the possible entities and intents that may come into play.
Once you have a mapped flow, get colleagues to look at it and brainstorm—maybe over drinks—all possible responses a user could give. Try to break the flow so you can identify the weak points now, before launch.
Scripting requires developing a chatbot personality and voice. A conversation flow tells you what your chatbot must be able to say, but not how to say it. Make no mistake: This is as important, if not more, as the conversation flow. Chatbots are meant for human interaction, after all.
Take advantage of your marketing information at this stage and gather as much as you have about your audience in front of you. Based on that information, decide how formal your chatbot should be if it should speak in sentences or short phrases, and what the bot will say when something goes wrong. Give your bot a persona. Think about what kind of personality they have and what kind of voice and tone would be natural for that personality.
This stage of chatbot development is more about the human element than the technological one, so we won’t spend a lot of time on it here.
Developing the Chatbot
There are many options for building chatbots for developers and non-developers alike. If you’re not a programmer but you want to create your own chatbot, you’ll find a number of platforms designed to help you do so. If you are a programmer, there are a handful of bot frameworks for building chatbots using various programming languages. You can start by building a bot on a platform and integrating with more advanced NLP functionality later; if you’re not a developer, this is the best approach. If you are, skip down to the section on frameworks.
Chatbot development platforms are intended for non-developers to easily create a chatbot. Note that these are not the same as publishing platforms—that’s where your bot will interact with users. Some platforms only allow for a simple rules-based chatbot—a conversational interface that may rely on buttons or have only a few canned responses—while others incorporate more NLP functionality.
Chatfuel is a popular development platform for bots that will live on Facebook. It can send many types of content and reply to keywords or questions entered by a user. You can also set it up to offer random responses to the same prompt, which makes for a more interesting bot. A bot built with this platform can collect and retain information from users, and use this information to choose a different conversation path. If you start with Chatfuel, you can later integrate with DialogFlow.
Botsify offers a simple drag-and-drop interface and is also used for Messenger bots. It offers intelligent query matching as well as entity extraction, which is helpful for personalizing chat and data analysis. This platform also provides a machine learning feature Chatfuel does not: It will record messages the bot could not answer so you can teach it over time.
Pandorabots can be considered a bridge, in terms of complexity and ease of use, between platforms and frameworks. It supports AIML (artificial intelligence markup language), which is an older open source language. It’s helpful to have some programming experience, but if you’re patient and willing to experiment, you don’t need much to build a relatively advanced chatbot on this platform (if you can set up a WordPress site, you can likely work in this platform). AIML files are available online; for instance, you can download the file used for the ALICE bot or find other options on Github.
Developers who want the most intelligent chatbot possible will take advantage of a bot framework. There’s no one programming language considered the go-to for chatbots, but common ones used are Python, Ruby, Java, PHP, and Lisp.
Just like providing machine learning cloud services, the major tech companies all have their own frameworks. Choosing which one to use is partly just a matter of which ecosystem you prefer. Using a framework doesn’t mean you have to write the code from scratch.
Dialogflow, owned by Google, takes advantage of the search engine’s vast wealth of data to handle context, entities, and intents quite well. This tool works for voice assistants as well as text-based chatbots, is compatible with all major devices, and supports multiple languages. The tool uses machine learning to train bots over time. Google provides solid documentation to help you figure the tool out.
The Microsoft Bot Framework allows you to build a bot on Azure (Microsoft’s cloud) and relies on Microsoft’s Language Understanding Intelligent Service (LUIS) for NLP and NLU. This framework supports translation into a few different languages and is open source. There’s a tradeoff in ease of use for natural language functionality with this platform, compared to Dialogflow.
Amazon Lex employs the automatic speech recognition and natural language understanding capabilities of Alexa and is compatible with other AWS services as well as Facebook and Slack. It supports only English, but is powerful in terms of support for entities and intents. Developers can also add their own intents to Lex.
IBM Watson Assistant can be used to build a range of chatbot types, from solution-focused ones to personal assistants. Watson integrates various AI technologies, from NLP to voice recognition to sentiment analysis, to provide a framework for answering questions and provide personalized experiences. Watson Assistant is one component of IBM’s AI business offerings.
Testing the Chatbot
As you’ve probably noticed reading the article, the technology behind building chatbots is easily available. Yet the majority of bots we’re presented with today can’t keep the conversation flow, give irrelevant answers, often don’t understand users, and are simply unusable. That’s why testing is just as important as the development stage.
Similar to bot building, you can use testing tools and ready-made solutions for automated regression or user testing.
Botium - or Selenium for chatbots - is a free, open source product that provides QA activities from ground-up: starting from the APIs, moving through UI, and finishing with actual conversations with a bot. Supporting Continuous Integration pipeline and tons of built-in datasets, this powerful solution can even train bots to understand human mistakes.
Zypnos is a popular tool for automated regression testing. Just like many regular automated QA solutions, it records test cases and then runs them repeatedly without any manual labor on your part. It’s a coding-free platform that sends your reports within minutes after testing sessions.
TestMyBot is a free and open source library that requires Docker and supports Node.js. The tool can be easily integrated into the CI/CD pipeline with CodeShip.
There are tons of services allowing you to test bots against potential users. For example, Amazon Mechanical Turk, Botsociety, Testbirds, or other crowdtesting platforms.
Before testing, remember to define your KPIs. The basic list of tracked metrics would include:
- Effectiveness of onboarding
- Consistency of personality
- Understanding complex requests and typos
- Percentage of irrelevant answers
- How good a bot is at remembering things
This range of options makes it possible for anyone, from the least tech-savvy small business owner to the most cutting-edge programmer, to build an AI chatbot. The key to creating a good chatbot is to put as much thought and effort into constructing the flow and considering business goals as put into working with the technology to construct it.
Morgen is a freelance writer from Salt Lake City. She writes about everything from artificial intelligence to business to health. In her free time, she enjoys baking and traveling.