Psst… Time To Jack Up Your Dumb Chat Bot Brain Using

30 min is all it takes for your chat bot to know cute and not cute!

Facebook Messenger is a platform that reaches over a billion people world wide. Now that Facebook has opened up access to sending and receiving messages many new opportunities open up.

You can jack up your chat bot’s smarts with two tech buzzwords: natural language processing (NLP) and natural language understanding (NLU). Those two things can make your chat bot not awkwardly ask you again and again what someone just said.

🤔 But wait… what’s the difference between NLP and NLU?

NLP helps you break down a sentence into things called entities. It’s like primary school for your bot. For example, NLP can read the sentence “Sally sold seashells by the seashore” and figure out there’s an entity Sally, that there’s another entity sold, that there are entities seashells and seashore.

Sometimes just having words in a sentence is enough. You can extract category or keywords and from there you can hack your chat bot to do something. But for more smarts you need to take your bot to the equivalent of university.

NLU helps you figure out what that sentence meant. Sally did something with something. And because of that the chat bot can then react and respond based on what Sally did do and with what. In other words, with NLU your chat bot can figure out human concepts like intent or sentiment.

😒 That sounds like a lot of extra work!

Lucky for you that’s exactly what Facebook spent millions of dollars to acquire to help you do! It’s called and it’s the super smart upgrade you can add to your Facebook Messenger chat bot.

After understanding what the user wants you can also mix up other internet services via API with Messenger to make your chat bot not only super smart but super useful.

By popular demand, today we will continue to build out a chat bot on Facebook Messenger and jack it up with to be super smart. After, your chat bot can converse about the weather and photo bomb cute corgi butts.

Sounds so future, right? Strap on your jetpack and let’s go!

IMPORTANT: Make a bot, first!

Go here if you have never built a chat bot before.

Go here if you don’t even know what I’m talking about.

Those are the best place to learn all about chat bots. And lucky you, it’s free!

Then come back to tackle this tutorial. Or, pfftt… just keep going.

Already know how to bot?

  1. Sign up for a account here:
  2. Go clone my weather app:
  3. Find the app token in your weather app so we can test everything is working. In your app go to the Settings page then find the “Server Access Token” in API Details.

Let’s test first that the token works by running this command in your Terminal:

curl -H 'Authorization: Bearer <YOUR TOKEN HERE>' ''

You should get back a response like:

"msg_id" : "14735f29-daa9-4553-a259-24cfa8c4ba42",
"_text" : "what is the weather in New York",
"outcomes" : [ {
"_text" : "what is the weather in New York",
"confidence" : null,
"intent" : "default_intent",
"entities" : {
"location" : [ {
"type" : "value",
"value" : "New York",
"suggested" : true
} ]
} ]

Great success! ✨

Deploy the chat bot to the clouds

  1. Git clone my bot here:
  2. I have organized my chat bot into four major components: the server, the Facebook Messenger connector, the bot app, and the NLP service. It’s a good idea to make chat bots modular. You can progressively add more more components to make the bot understand language or locations but you should also be able to remove components and until only a web server is left.
  3. Deploy the bot to Heroku by running these command in Terminal inside the cloned git repo directory. A page should pop up meaning your app is ready. Be sure to remember the URL of your Heroku app.
heroku apps:create
git push heroku master
heroku open
If you haven’t yet, install the Heroku Toolbelt on your computer. You can learn how to do so here:

Setup Facebook to talk to your chat bot

  1. Go to and create a new app, be sure to add Facebook Messenger as a product to the app. You can also use an existing an app.
  2. Go to the settings page of the app you’ve made then go to the Messenger settings page. Here you will generate a token of the Facebook Page to link to with Messenger. Remember to save this token key somewhere.

3. Set up Webhooks to your FB app. Remember to use the link to your own Heroku app.

Click Verify and Save. You should see the Complete sign!

4. Now we’ll set up the server again. Set the keys required as environment variables to make the bot work by running these commands in Terminal:

heroku config:set WIT_TOKEN='your_token_here'
heroku config:set FB_PAGE_TOKEN='your_token_here'

When that’s done you should be able to at least say hi to your chat bot and have it echo back hi! 🤖

📖 Next we’re going to create stories does the hard work for you by creating a simple to use interface to manage what are called “stories” — these are ways to extract meaning from a keyword or sentence.

For now you might have to write a lot of stories for your chat bot to understand language but soon has a vision that we can share hundreds of stories with each other. And with more stories the more skills your chat bot will have.

Time to teach your bot!

What is the weather? AKA extracting location

  1. Create a new story in the Wit dashboard. The first type of story we’ll write is extracting location from conversations. This way we can build a weather bot! Go here to see the recipe I’ve created. Remember, you can fork this to use for yourself.

2. Find the Read function in the bot.js file. Here the bot can recognize messages. The first message can be hello, the chat bot can send back an introduction. Otherwise, we can pass the message on to for processing.

3. Let’s test and see if the weather shows up!

Sunny in London! ☀️

Cute or nah? AKA extract category and sentiment

  1. Create yet another Wit app in the dashboard. This new app will have three stories to extract the category and sentiment entities out of a conversation so your chat bot can reply with some cute pics! Go here to see the recipe

2. Create a new story to look for the user response then trigger the bot to execute the action and respond.

When you double click a word it will be highlighted as blue, after assigning the word as an entity the highlight turns purple to indicate has learned.

Have the bot execute a merge function to extract the entity and save it to the context object. Then execute the fetch-pics action to return the actual pic itself. Thereafter you can trigger two replies by, one saying what the category is and the other the image link itself.

3. Add and create two more stories based on my template. Each will help train on what to look for and how to respond to a sentiment and to an acknowledgement.

4. Now we can test. Be sure to update your Heroku server with the new Wit app’s token by running this command:

heroku config:set WIT_TOKEN='your_new_token_here'

Let’s go back and chat it up. Ask to see some corgis. Then ask to see some racoons!

Here’s the corgi butt I promised

Congratulations you’ve made a chat bot that’s smart enough to know what you’re talking about, what you mean, and reply back accordingly!

Tell Your Chat Bot What’s What

NLP and NLU are not magical! They are merely defining rules for your bot. Your chat bot will break sometimes and maybe even often when being told new and interesting conversations it’s never heard before.

It is now up to you to help keep training and testing your bot until it’s the very best. You have two tools in to do so. Go to the console and let’s learn about the Inbox and the Understanding page.

Training your chat bot has an inbox that shows you all the messages it has received. From here you can pick and choose which one to validate and contribute to the training data of your chat bot.

For example, if you have an entity of location you can assign more values to help train your chat bot to know that “San Francisco” and “Timbuktu” are both locations. If you have categories for “corgis” then you can also validate that “dogs” can mean the same thing.

The more people that talk to your chat bot and the more complex your bot is the more you will spend time in this page. And the work you do here will help make your bot even smarter. To be the very best! 🙌

Testing your chat bot

The other page you will be spending time at will be in the Understanding page. Here you can try out sentences yourself to test whether your chat bot can understand and to troubleshoot when a sentence doesn’t trigger the right response.

Now send your smart chat bot out to take over the world!

Learn how to get your bot approved for public use here.

Remember, your chat bot has to be approved by Facebook so that anyone can talk to it. Otherwise, you have to go to the Roles page in your Facebook app and add testers.

Add a chat button to your webpage

Go here to learn how to add a chat button your page.

Create a shortlink

You can use<PAGE_USER_NAME> for sharing purposes.

What’s next?

So, you made a bot. Now what? Don’t worry! The fun is only just beginning.

Don’t forget to hit Like to recommend this story. Help share knowledge with others!

✨Follow me for more tutorials and stories in the future.

📬 Comment if you have suggestions for what I should write next!

⚡️The short link for this tutorial is

Enjoyed the article? Click the ❤ below to recommend it to other interested readers!
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.