Chatfuel offers a great and easy to understand environment to build simple bots, really fast. Since the bot’s actions are triggered with button clicks, it’s incredibly easy to mockup a conversation flow and deploy it to Messenger.
Yet, experienced bot builders will tell you: the actual user inputs your bot will get are impossible to predict exhaustively, sometimes absurd and quite often senseless. A pure input-output logic will sadly not get you very far.
This is precisely the reason why NLP is essential for a chatbot to be able to react to unpredictable inputs. Hence, if you ever have shipped an application to Facebook, you know that this will happen very, very often:
Some people just won’t click the buttons and type weird questions instead. To give you some perspective, one of the most triggered intent on one of customer support chatbot for a bank is @ask-joke. You would think people have better things to ask to their digital bank clerks – the reality is that most users want both: the facts and the fluff.
Knowing this reality is one thing, handling it is another. If you fail to handle fluff in a satisfying manner, you’ll leave your users deeply frustrated. The good news is that integrating Natural Language Processing with Recast.AI to your existing Chatfuel bots only takes minutes, and I’ll guide you along the path.
WHAT ARE WE BUILDING TODAY?
By the end of this tutorial, your existing bot will be able to understand more than 15 different topics of small talk and answer it cleverly, and you’ll have everything you need to add much more – all that in less than 10 minutes. So, without further notice, here’s what on the menu today:
- Setting up a Recast.AI account
- Training your bot to understand and respond to small talk
- Interfacing Recast.AI and Chatfuel
- Setting up a fallback on Chatfuel
Find a comfortable spot, and get the stopwatch ready. Now it is the time to plug a Recast.AI brain into your Chatfuel’s bot!
SETTING UP YOUR RECAST.AI ACCOUNT
- To begin, create an account on Recast.AI! It’s free 🙂
- It’s now time to log in and create your first bot. Click on the button “Start with a template”, or just on
+ NEW BOTin the header section
- Choose “Create a complete chatbot”
- You can choose one or many pre-defined skills to generate a boilerplate for you bot. Pick Greetings and Small Talks
- Choose your bot name
- You can add an optionnal description
- Set English as the default language
- You can keep your bot public as there is no private info, but you can change this setting later
Step 1/4 – Set up a Recast.AI account
TRAIN YOUR BOT
The train tab is the default view on your bot, and it displays its intents. An intent is a “box” of sentences that all carry the same meaning, even though they can be very different to one another. When a user sends some text to your bot, our algorithm compares it to the phrases in your intents. Then it checks if it’s close enough to one of them and decides what the intention of the message is.
Because we started with a boilerplate you will already see a lot of intents:
This means that your bot already knows how to recognize 16 different meanings in hand typed messages. If you want to learn how to create new intents or improve the existing ones, I invite you to give a look at this tutorial.
The Build tab is where you find Bot Builder. It helps you construct the conversation flow of your bot using Skills. Each Skill represents one thing that your bot know to do, and they can interact with each other.
You can already see the two default skills, greetings and small-talk picked during the creation of the bot.
WHAT’S A SKILL?
A skill has four parts:
- Readme: Where you explain the purpose of your skill
- Triggers: Where you define why this skill should be activated after a user message
- Requirements: Describes what information this skill has to collect, and what questions need to be asked to fulfill the requirements.
- Actions: What to do once the requirements are fulfilled
The two premade skills are very simple: they are triggered if the user message contains a certain intent and answer with a message depending on the intent. The skill greetings takes care of the intents greetings and goodbye, and the skill small-talk handles the 14 others.
By default there is no fallback message, meaning that if no intent was assigned to the message, nothing will happen.
Fix this by clicking on
+ ADD A NEW SKILL the left, and choose skill type
FALLBACK. Give it a name of your choice.Once it’s created click it to view its settings and go to the Actions tab. Click
ADD A NEW MESSAGE GROUP, choose
SEND MESSAGE action type and create a default message of your preference.
If you want to edit the default skills, go to their Actions tab and click the pen to change the content of the message.
The setup part on Recast is now done, you can test your bot by clicking the blue
Test bubble on the right of the screen. The
Converse tab shows you what answer is configured for a message and
Analyse tab which intent was matched.
Step 2/4 – Train your bot
INTERFACING RECAST.AI AND CHATFUEL WITH A NODE.JS PROXY
Unfortunately, Recast.AI and Chatfuel don’t speak the exact same language. The JSON output from Recast’s Bot Builder is not formatted exactly as Chatfuel API expects.
Let’s code a simple NodeJS proxy to solve this issue. We’ll set up a simple HTTP server that receives events from Chatfuel, calls Recast’s Bot Builder API with the message sent by Chatfuel and returns the messages configured in your Skills.
Start by installing dependencies:
Then copy the following script to a .js file.
Now you should host this code on a public server so that Chatfuel send requests to your API.You can try Ngrok if you want to expose publicly a port of your local computer.
Step 3/4 – Interfacing Recast.AI and Chatfuel
CONFIGURING CHATFUEL FALLBACK
Finally, we need to configure Chatfuel to send a request to the proxy when the bot receives a free-typed message.
Default answer and reproduce this setup:
This will save the user message to a variable named
user_message, and send a request using
JSON API block to the proxy we created with two parameters: the message and a user id, to keep track of conversation states on Recast.
Your bot now understands small talk! Go test it on messenger:
Step 4/4 – Setting up the fallback
Even if you have a functional Smalltalk module as is, you may want to personalize the texts of your bot, create new intents or improve the detection of your bot.
Everything you need to know about Intents and Skills is explained in this tutorial.
Take your time to improve the quality of your bot’s Smalltalk, it’s a very important part of its identity, and you will notice a much stronger engagement. The personality of a chatbot is a determining factor of its user retention rate.
Thank you very much for following along! We would be very happy to have your feedback on how small talks impacted your existing bots.
🤖 Happy bot building 🤖
Have an issue with your bot? Is something unclear in this tutorial? Feel free to comment or join our Slack to discuss it.