Bot Development

Building Bots with Wit.ai

Wit.ai is an open source chatbot framework with advanced natural language processing, or NLP, capabilities. Owned by Facebook, Wit.ai is a popular choice for Facebook Messenger bots powered by NLP. Use Wit.ai to build intelligent chatbots for social channels, mobile apps, websites, and IoT devices.

July 16, 2019
tools building chatbot on wit.ai framework

There’s no shortage of options for building Facebook Messenger chatbots. With plentiful graphical user interface (GUI) editors to choose from, even non-coders can make functional chatbots and deploy them to the platform with ease.

But, for developers looking to build a more sophisticated Facebook Messenger bot, a complete chatbot framework is essential. That’s especially true when you’re building a bot for Messenger, IoT, your own website, and other channels.

If you’re on that path, you’d be smart to consider Wit.ai. As Facebook’s very own bot-building framework, Wit.ai can accelerate the process of building a bot for Facebook Messenger and deploying it to the platform. However, as a full-fledged framework with natural language processing (NLP), Wit.ai offers possibilities that extend beyond Facebook and even beyond social platforms.

What is Wit.ai?

Wit.ai is an open source chatbot framework that began as a Y Combinator startup. Its name is a testament to its greatest strength—parsing nuanced user utterances and returning valuable, well-informed responses. To do that, a framework needs highly capable NLP, which has always been (and still is) Wit.ai’s biggest advantage.

Facebook acquired the company in 2015, but Wit.ai remains an open source project. Developers building bots with Wit.ai do so with open source code and even open apps. That way, other developers can fork any app and don’t need to start from scratch when building their bot.

For example, you won’t have to painstakingly teach your bot the basics of human conversation. If a developer has already used Wit.ai to teach their bot to respond to hello (and someone definitely has), Wit.ai lets you immediately inject your bot with that intelligence.

Interestingly, in its own product literature, Wit.ai doesn’t refer to itself as a “chatbot framework.” Instead, it bills itself as a toolkit for “building applications and devices that you can text or talk to.” The emphasis is on the natural language engine powering the conversations—not on Wit.ai as a framework for building bots.

Needless to say, nearly any app you build that responds to text or spoken language using text or spoken language fits the definition of chatbot. Wit.ai helps you build bots, plain and simple.

Wit.ai chatbot examples

It shouldn’t come as a surprise that many developers use Wit.ai to build bots intended for Facebook Messenger. However, others use Wit.ai to build bots for different platforms. Some, as we explore here, even use the framework to build conversational applications that respond to voice commands.

Virtual concierge bots

Used by real estate professionals and homebuyers, the Structurely Aisa Holmes chatbot asks users various questions to help them find a house with qualities and features that meet their specified preferences. In essence, Aisa qualifies leads for real estate agents.

Aisa is just one example of a sophisticated virtual concierge that uses the Wit.ai NLP engine to understand user intent and deliver valuable information. As Structurely puts it, Aisa is “artificial intelligence that handles lead qualification [...] with the same empathy and respect as a human.”

Another example is Doktersiaga, a virtual health assistant that can help users find nearby health facilities based on their location. The bot also takes into account what kind of insurance users have so that it can direct them to care providers who are covered by their policy. Doktersiaga is a Facebook Messenger chatbot and currently serves users in Indonesia.

Community enhancement chatbots

Other developers are enlisting chatbots to help prevent homelessness, and they’re using Wit.ai to help achieve that goal. Home++ is a chatbot-via-SMS service that was made available to homeless residents in California. These individuals received a smartphone as part of a local initiative and were prompted to provide their number to the Home++ bot.

Users activate the bot to request information or assistance. For example, they can text the word food, and Home++ responds with information about local food pantry events and food bank resources in the user’s area.

Society Goals (still in beta, at the time of this writing) is another bot aimed at improving communities. The bot, which lives on Facebook Messenger and uses the Wit.ai NLP engine, encourages users to set small community engagement goals and to track their progress by conversing with the bot.

One example that developers cite in the Society Goals product literature is the act of plogging, which refers to picking up trash while jogging. Users commit to a certain frequency of plogging and then report their progress to the bot.

Medical chatbots

Others are using Wit.ai to build medical chatbots for all levels of the healthcare value chain. For starters, there’s Meno BOT, a voice-activated bot that helps doctors update patient medical records just by speaking. Developers used Wit.ai to train the bot to recognize the types of commands that physicians would use.

If you’re a patient, however, you might need a medical bot for another reason entirely, such as getting a diagnosis for a non-serious ailment. Doctor’s Virtual Office allows patients to do just that. The bot, which uses Wit.ai’s NLP, ushers users through the check-in process and then connects them with a doctor via a virtual appointment video call.

Why use Wit.ai? The pros and cons

Every chatbot framework has advantages and drawbacks. Before looking at why you might not want to use Wit.ai, let’s consider some of the framework’s biggest strengths.

Wit.ai pros

Deploying a Wit.ai bot to Facebook Messenger is very straightforward. Developers building bots for the platform benefit from using a framework that is essentially a Facebook product. Since Wit.ai is an open source (and open app) framework, they also benefit from a large developer community. Developers can see the work others have already done, learn from it, and draw from it for their own bots.

However, the framework’s NLP engine is arguably its most compelling benefit. The Wit.ai machine learning model (which we examine in this post) mostly holds its own against other bot-building tools offered by big companies, such as Amazon Lex, Microsoft Bot Framework, and Google Dialogflow.

Wit.ai cons

Some critics contend that training the NLP engine in Wit.ai is rather laborious. The developers behind Meno BOT actually listed NLP training as one of the biggest challenges they encountered while building their bot (although, to be fair, training a language model might be the biggest challenge when building any chatbot).

Another observer points out that Wit.ai lacks the required slot/parameter feature, which forces you to use business logic to glean unstated information following every interaction that gathers slot/parameter info from users. The consequence? You might find it harder to retrieve missing parameters in Wit.ai, as compared to alternatives like Dialogflow and the Microsoft LUIS NLP engine.

Wit.ai features and integrations

We’ve already noted how Wit.ai plays nicely with Facebook Messenger. Thankfully, Wit.ai also integrates with apps and websites. For app integration, you should use one of the official clients or visit GitHub to find an unofficial client in your preferred programming language. For website integration, use JSONP, as described in the Wit.ai HTTP API Reference.

Of course, deploying your bot to your own website is always a good idea, even when you’re primarily building the bot for a messaging channel or an app. A dedicated domain name ending in .BOT is an excellent “always” home for your bot, and users can find it there without having to use a messaging app.

Other Wit.ai features include a well-designed developer UI with a conversation flow tree that’s easy to visually edit. Built-in entities in Wit.ai give you a good head start on bot development, as does the open source nature of the framework in general. Wit.ai also includes roles for entities, which allow you to train your bot to distinguish two otherwise similar entities within a given dialog.

Wit.ai pricing model

Wit.ai is free to use, but that doesn’t mean your bot will operate free of charge. Even if you use Wit.ai for NLP, you still have to host your bot somewhere. Ultimately, you may end up paying for the number of requests received—the more use your bot gets, the more you pay.

Regardless, a free, open source framework with a robust NLP engine is a great place to cut your teeth on bot building. And, if you’re already building bots with other tools, it doesn’t cost you anything to try Wit.ai and see if there’s a place for it in your stack.

Supported programming languages

Wit.ai comes with official clients for the following languages:

These SDKs are probably sufficient for most developers looking to integrate Wit.ai into their apps, but unofficial clients do exist. For instance, there’s this PHP SDK for Wit.ai and this Java library.

How machine learning works in Wit.ai

To get started with machine learning, you can use the Wit.ai provided intents and entities, which get your bot up to speed with the basics.

Essentially, machine learning in Wit.ai works like this:

  • Create your own intents, and incorporate existing intents from the community. This might be time consuming, if your bot needs to understand many intents.
  • Extract entities from the intents. You can use the built-in entities for those that are common (date, time, and location entities, for instance) and to match them to
    user intents.
  • Assign roles to entities. This process helps you further differentiate among entities. As the Wit.ai roles documentation explains roles, Atlanta and New Orleans are both
    locations, but, for your travel app, which is the origin and which is the destination? By assigning roles, your bot can understand which is which.
  • Start training your bot to associate the right intents with the right entities. You scour your bot’s interactions and validate the correct associations or modify the
    incorrect ones by creating a new intent or associating a different entity with the existing intent.

How to get started with Wit.ai

With zero cost and ample documentation to guide you, the best way to get started is to dig right in. If you don’t yet have a bot of your own, the Wit.ai Quickstart guide can walk you through the process. This helps you get the hang of specifying intents, adding entities, and matching them.

If you get stuck, review the Wit.ai recipes, which are solutions to common issues that developers encounter when they start building bots with Wit.ai. As you begin working on your bot, be sure to make the most of the Wit.ai community. Remember, Wit.ai is open source. There are lots of other developers out there building bots with the framework, and many will be eager to help you. Not only that, there’s a good chance you’ll find a similar bot to use as the baseline for your own.