A Wit.ai Tutorial (HTTP API)

What is Wit.ai?

Wit.ai is a natural language processing (NLP) interface that turns natural language (speech or text messages) into structured data. Developers use Wit because it simplifies the process of making applications and devices that people can converse with. Without it, developers would need to learn natural language processing algorithms. That would be too time-consuming if you just want to make a simple application.

What will this blog post cover?

In this blog post, I'll cover a simple tutorial on how to train your application to understand common company chatbot questions using the Wit.ai console. By the end of the tutorial, the bot will be able to understand basic questions such as "What is your business email address?". The communication with the bot will be done via the HTTP API provided by Facebook.

If you are not really interested in a chatbot, just follow along to learn the basics. You will be able to create other cool stuff on the Wit.ai community page.

Warning! Stories are now deprecated.

Before I forget, the reason why I'm creating a Wit.ai tutorial when there are already so many good ones is that there are several outdated tutorials out there using the now deprecated stories. You should not use them as Facebook will no longer support them by February 1, 2018.

First Wit.ai Application

First, create an application by clicking the plus icon at the top navigation bar. It will redirect you to the "Create a new App" page. Wit.ai First Project

Enter your application name, description, and privacy settings. Don't worry about the application name and visibility settings too much. It isn't permanent and you can change it again later on the settings page.

Training your Wit.ai application to greet

Once you made your application, you will be directed to the entities page. This is where you train your bot to understand expressions. For now, we will teach the bot to understand common greetings.Enter Wit Greetings

Enter the word "Hello" or any other greeting you like in the textbox as shown in the picture above. In the "Add a new entity" box, select wit/greetings and choose value as true. Your chatbot now understands that the expression "Hello" intent is a greeting.

Wit Entities

There will now be another entity called wit/greetings listed on the entities page. If you click on wit/greetings entity you will be directed to the greetings entity page.

Wit Entity Greetings Page

You can see that the expression we created is listed. In this page, you are able to view expressions you have taught the Wit.ai application. If you don't like any expressions you have made you can simply delete them by clicking the cross on the right-hand side of the text.

What is your email address?

Now, we will train our conversational bot to understand our intent to get the company email address. Add Email Address Wit Entities

Enter "What is your email address?" in the textbox and add a new entity called "intent". In the value textbox, input "getEmail" and validate the expression. That's it, you have successfully taught your bot to understand the intent of the expression "What is your email address?".

Communicating with the Wit.ai App through curl (HTTP API)

The next step requires you to have curl installed on your machine. If you don't have it and you don't want to download it, you can use a website called online curl.

Now go to the settings page.

Wit Curl Settings

As shown above, enter "What is your email address?". Once done, copy the text to the clipboard. This can be done easily by clicking on the button above learn more. Now curl the text.

Curl Wit Email Address

Congratulations! Your application is now 99% confident that your intent is to "getEmail". With this, you have the basics of creating a chatbot. You have learned to extract a value and create your own function.

Who's email address?

What about handling more complex questions such as asking for a boss' or manager's email address? It's actually very simple! First, give Wit.ai the example sentence "What is your boss' email's address?" Afterwards, create an entity called email_type and assign the word 'boss' to the entity.

Curl Wit Email Address Curl Wit Email Address

Well done! Wit.ai is now able to understand that the word boss in the sentence "What is your boss' email address?" is an email_type.

Adding more keywords

Wait! What if you wanted to add more keywords? In order to do that, just modify the entity email_type and change the lookup strategy to keywords! What this does is tell Wit.ai that you are looking for specific keywords and that those keywords are considered an email_type. Once that is done, proceed to add more keywords. In my case, I added one more keyword called 'manager'.

Curl Wit Email Address

Wit.ai is now able to determine that the entity email_type consists of only the keywords manager and boss. If you curl the sentence "What is your manager's email address"?" now, it will return an email_type with a value of 'manager'. This is useful to your application as it is able to get all the necessary entities to make sense of the sentence and execute the appropriate function for the user.

You have mastered the basics of Wit.ai

Congratulations! You now possess enough knowledge to explore and play around with Wit.ai on your own. Your journey doesn't end here and I hope you would create amazing things like Disney's Zootopia chatbot.

If you were to create one for your website and give your users a truly interactive experience. You should not neglect important web design features such as responsiveness, user experience and search engine optimization. These are essential to creating a truly engaging website.

Hopefully, this blog post has been useful to you. I appreciate any feedback both good and bad. I'm still learning Wit and have much to learn but please don't hesitate to contact me to discuss Wit.ai.

Additional resources

Posted on Apr 01, 2018

Leave a comment or suggestion below

About IT Wonders:

IT Wonders is a web agency based in Johor Bahru (JB), Malaysia and Singapore. We provide responsive and custom websites unique to your needs. If you have any inquiries about your website, do not hesitate to contact us.