Skip to main content

Greeting bot

warning

This documentation page is still being written.

In this quick guide, we will create a bot that greets the user and asks them how they feel - inspired by the RASA mood bot. We will look at performing basic branching and at some of the best practices in structuring a bot model.

Step 1: Hello

Let's start by modeling a simple greeting behavior. There are two elements that we must define:

  1. The greeting intent
  2. The flow for greeting
# Flows are defined using their name followed by ":"
# The elements of a flow must have a higher indentation level
hello:
user greeting
bot "Hello!"

# User intents are defined using a list of examples
define user greeting
"hi"
"hello"
"hey"

Check out using the playground.

Step 2: Basic Branching

Let's make our bot ask the user how they feel. To do this, we define two additional intents: mood_great and mood_unhappy. Also, we extend the initial flow with a branching based on the user's intent. Notice the use of when and else when to implement the branching.

# Greet user and ask mood
hello:
user greeting
bot "Hello!"
bot "How are you?"

when user mood_great
bot "Great, carry on!"

else when user mood_unhappy
bot "I'm sorry to hear that!"

define user greeting
"hi"
"hello"
"hey"
"hello there"
"good morning"

define user mood_great
"good"
"perfect"
"great"
"amazing"

define user mood_unhappy
"bad"
"sad"
"unhappy"
"very sad"

Check out using the playground.

Step 3: NLU Files

Before moving on, let's look at structuring the files for our bot model. Intent examples tend to grow a lot over time, so it's a good idea to keep them in separate files. You can have as many intent files as you want.

Hint

To have a file shown in the NLU category, prefix the file name with nlu/ when creating it.

Check out how we've split the bot files into intent (nlu/intents.co) and flows (flows.co) for the mood bot and how we've also added a few more examples to our intents to make the NLU more powerful.

Step 4: NLG Files

Another good practice when designing complex bot models is to create separate files for Natural Language Generation, and this has multiple advantages:

  1. We can define various bot messages with the same meaning. The bot will randomly choose one every time, which will make it sound more human as it will be less likely to repeat itself.
  2. When dealing with multi-lingual bots, you can have separate files for each language.
  3. Copywriting and creating a bot persona become more manageable with all messages in one place.

However, in the initial stages of the development of a bot, it is usually easier to write the bot messages directly into the flow and refactor them later into a separate file. Check out how we've added multiple variations for the hello and goodbye messages in utterances.co.

Hint

To have a file shown in the NLG category, prefix the file name with nlg/ when creating it.

Step 5: Context Variables a.k.a. Slots

When modeling conversations, you'll deal with dynamic data from the user (e.g., a name, a food type, a date) or data used internally to model the flow's logic.

Variable names always start with a $ (e.g., $name). You can assign them values coming from user intents, and you can use them in various expressions, including directly in NLG strings.

Check out how we've stored the user's name in flows.co and how we've used it in utterances, including in goodbye_with_name.

ask_name_if_in_good_mood:
user mood_great
bot "Great, carry on!"
bot "What is your name?"

# `text` is a special intent for when the user provides a general text
user text as $name

bot "It's great talking to you, $name!"

goodbye:
user goodbye

# This is a first example of using the conditional `if` statement
if $name
bot goodbye_with_name
else
bot goodbye

Check out using the playground.

Extending an existing flow

If you look closer at the flows in flows.co, you'll notice that the ask_name_if_in_good_mood flow will continue after the hello flow has finished. In other words, we've extended the behavior of an existing flow.

At any given time, all the flows are executed in parallel! The flow that decides the next step will always be the most specific one.

We'll cover this behavior in more detail later, including interruptions and recovery flows.

Step 6: Bot Skills

When developing complex bot models, a good practice is splitting the behavior into smaller models called skills. They can be composed to create more advanced skills and, ultimately, complex bots.

In this playground, you can think of any bot model as a skill that you can include in other bots.

We've moved the mood behavior we've created so far into the mood skill. Check out flows.co to see how we have included the behavior into this bot.

Also, notice another skill that we have included: chitchat. Try saying something like:

  • Are you a bot?
  • How are you?
  • You're smart

Wrapping up

In this quick guide, we've created a simple bot model for greeting the user and asking them how they feel. We've looked at the best practices for splitting a bot model into multiple files, using context variables, and putting everything into a mood model that we can reuse in other bot models.

Next, we will look at a more advanced bot, a conference bot.