Build your first bot with Bot Builder
Note: This article is deprecated. It uses Recast.AI API version 1. You can find an updated tutorial here: Build your first bot with Recast.AI.
The 4 phase approach
By the end of this tutorial, you will have built a fully functional food ordering bot using our new feature: the Bot Builder. Bot Builder helps you design complex flows for your bots quickly and easily. There are 4 phases in your bot life on our platform:
- Learn: Fill the entire brain of your bot, what it needs to understand.
- Build: Construct your conversational flow with BotBuilder.
- Run: Connect your bot to a channel.
- Train: Train your bot regularly to keep it up to date.
So, let’s get started!
Learn — fill your bot’s brain
1) Create your bot
- Login to your Recast.AI account or create a new account.
- Go on your profile section by clicking on the ‘BOT’ tab.
- Click the blue button “+ NEW BOT”.
- Choose your bot’s name: ‘RestoBot’
- Add a description: ‘Order food easily with RestoBot‘
- Set English as the default language.
- You can keep it public as there is nothing to hide in this bot.
- Hit the “CREATE A BOT” button to achieve the creation.
2) Create your intents
After that, you are redirected to the main page of your bot, where everything it knows is gathered, divided in intents. Intents are boxes including expressions that mean the same thing but are constructed differently. Each intent corresponds to one action your user wants to perform.
There are common intents that you should create in each of your bots. Your bot has to understand basic things such as ‘greetings’ , ‘agree’, ‘disagree’, and when a user asks for help. Luckily, our platform is collaborative, and you can ‘fork’ an intent someone already created to clone it right into your bot. It’s very useful for these basics functions. To fork these intents:
- Write ‘greetings’ in the search bar
- Click on ‘SEARCH’
- Choose an intent you like.
- Click on the ‘FORK’ button on the right
- Repeat for ‘help’, ‘agree’ and ‘disagree’
Create intents from scratch
This is how to create intents you cannot find in the community. We need the bot to understand when someone is ordering food, and if they want it to be delivered or take-away. To create these intents:
- Write ‘order’ in the search bar
- Click on ‘CREATE’.
- Repeat with ‘delivery’ and ‘takeaway’
3) Add expressions
Now that intents have been created, we have to fill them with various expressions that mean the same thing. Just click on your intent then on the ‘Add an expression’ field and write your expressions. Let me give you some:
- I would like to order.
- Can i get pasta please?
- I want to order tacos.
- Is it possible to order some sushi?
- I would like to have some nachos
- I want to order something.
- Do you have noodles?
- I would like sushi.
- I would like to order some lasagna.
- deliver at 163 avenue de Clichy Paris
- I’d like the order delivered
- I want a delivery
- at home, 123 food street, Paris
- I want to order a take out
- I want to take away in the name Hugo
- I would like some food to take-away
- take away
- take out for Bruno Gantelmi
Here is one of our articles giving you tips about how to optimize your intents, with lots of tips and good practices.
4) Tag your entities
In some expressions, you need to extract important data. That’s why we have entities. They’re keywords detected in expressions. Some of them are automatically detected, like location and name: we call them gold entities and they’re marked with a little star. You can see them by clicking on an expression.
You can also create your own custom entities. We’ll use them here to get the type of food the user orders.
- Click on the order intent, then click on an expression to reveal entities.
- Select the word(s) you want to tag as ‘food’ in your expression
- type ‘food’ in the search bar.
- An entity ‘food’ has already been created by the community! tap enter to select it. If the entity would not have been created yet, you would have hit the ‘CREATE’ button on the right ;)
- repeat for each expression of ‘order’ intent with food to tag.
5) Test your bot
Now that we’ve created everything your bot is supposed to know, let’s test it:
- Click on the chat icon on the right of the screen
- This is the console. Type a message, like ‘I want some sushi’
- A JSON is printed with core information about your message
- You can see the intent ‘order’ has been matched, and food entity found. Everything is in place :)
Build — manage your conversation flow
Now that your bot is considered smart and effective, we can start building the conversation. Click on the ‘Build’ tab and then on ‘Launch the builder’ to discover the magic of Bot Builder. Read the guide that pops on the screen and you’ll enter into the Bot Builder playground.
1) Define your actions
Let’s take some time now to think of what the flow will look like:
- user say hello
- user chooses either delivery or take out
- user expresses what he wants to order
- user confirms the order or not.
Here is the drawing of the bot flow. Each step on this chart is an action. An action, as we call it in Bot Builder, is one step in your conversation flow that is associated with an intent. (You can have several actions for the same intent). To put an action on your playground:
- Click on the ‘+’ in the left side toolbar.
- Click on the right intent
- A module appears, you can move it anytime and anywhere.
Reproduce this in the BotBuilder, without taking care of the connections for now.
2) Link the actions
There are two types of links:
- Green links create an action flow where the user is guided in one direction, but remains free to start at any other step of the conversation.
- Red links create an action flow where the user has to follow a defined path.
To connect actions:
- Click on the right end of the action you want to link.
- Click on the extremity of the other action you want to connect it to.
- Change the color of your link by clicking on it then on the right color in the toolbar.
Since ‘order’ action need the user to choose between delivery and take away, the only red links we have to make are:
- delivery -> order
- takeaway -> order
About ‘OR’ and ‘AND’:
- When two red links are connected to the same action on the right, a small red block appears: it can be an ‘AND’ or an ‘OR’ block.
- To switch, click on the reverse arrows below its name.
- ‘OR’ means that only one of the action have to be done.
- ‘AND’ means that both of them are required.
- Here, the user chooses between ‘delivery’ or ‘takeaway’: so we have to set an ‘OR’ block.
3) Define notions
Now that we’ve set the flow, some of our actions need specific informations (entities) to be complete: we call them notions.
- Click on the small pen that appears on the ‘order’ action
- Click on the ‘Add notion’ button
- Search the ‘food’ custom entity we created earlier and set the alias as ‘food’
- The alias let you set 2 notions with the same entity: for example for a GPS bot you can set a location as a ‘departure’ and a location as an ‘arrival’.
As we need a name for take away and an address for delivery, set these 2 notions the same way you did for the first one.
4) Set the bot replies
At this point, the hardest part is done. Let’s now give some spirit to our bot! There are 3 different replies you can set:
- A reply when the action is done
- A reply when a notion is missing in the sentence
- A reply when you need a previous action to be done before (red linked)
To set them:
- Go on the overview of any action card (small pen again)
- Click on ‘Add bot replies’.
- You can inject notions in the reply by setting it between double curly brackets.
Don’t forget to also set a reply when the bot doesn’t understand the input. You can do this by using the module ‘default reply’ located on the bottom-left of the playground.
5) Test your flow
Now that the flow is complete and the replies set, we can finally test the bot!
- Use the console as you did earlier in the project.
- The console in Bot Builder is different. You can have a conversation with your bot.
- On the top-right, you can choose if your bot will use a single reply or all the replies it can. Depending on the bot, it could be better to use the ‘ONE’ option. For this bot, print ‘ALL’ the replies.
- Try to say “Hello”, and see what happens!
- Have fun testing your bot before diving into the code.
Run, Make your bot live.
We’re now done with setting the bot. The last thing you have to do is to connect it to a channel to allow users to use it! This part is taking place in the ‘Run’ tab of your bot. Here you can find all the tools we provide you with to connect your bot easily. The easiest way today is to use our starter-kits. Each of them has its own complete Documentation. That’s why i’d recommend.
Train, Keep your bot up-to-date.
When your bot is launched and starts to have some users, go to the ‘Train’ tab, and manage your logs:
- Archive messages if they match the right intent
- Redirect messages to the right intent if mismatched.
- Try to keep an eye on this tab to continuously improve your bot.
Hope this tutorial will help you launch plenty of wonderful bots. Don’t hesitate to ask if you need help in your bot building
Hugo CHERCHI — Recast.AI