Apply rules

Expected completion 15 minutes.

Now that you’ve told your bot what to say, you need to tell your bot when to say it! In this session you’ll learn how to do this by creating rules.

Branching logic

To begin with, we need to understand that conversations aren’t always linear. In a normal conversation, you might respond one way if they told you one thing, and another way if they told you another. In exactly the same way, a Josef conversation might follow one direction if the user gives a certain response, and in another direction if the user gives a different response. We refer to this idea as a branching conversation, or sometimes as conditional logic.

Previously we’ve only made messages that connect to a single subsequent message. Now we want to start thinking about what happens when a message has multiple subsequent messages connected to it. In these situations, rules will tell the bot which message to go to next.

Start by watching the video below to learn how to connect multiple subsequent messages to one previous message.

Applying rules

Rules are the laws that govern how conversations proceed. We apply rules to connections to tell a bot when to follow one connection as opposed to another. The way rules work is that if the rule applied to a connection is satisfied, the bot will follow that connection to the next message.

Variables

To understand rules, we first need to understand variables. In Josef, a variable refers to a message that a user has already responded to, and the different ways that they could have responded to it. 

For example, in the next video we’re going to create another message that asks the user “What do you need help with today?” We will make the response type ‘single choice – text’ and create the following possible options: ‘Prepare a contract’ or ‘Speak to the legal team’.

The way the user responds to this question becomes what we call a “variable”. The name of the variable is the message name ‘4.0 Help‘ and once the user responds to this message, the variable will be set to be either ‘Prepare a contract’ or ‘Speak to the legal team’.

Rules

To put everything together, we have rules, which use variables, and we apply rules to connections.

A rule has 3 elements:

  1. Variable: the name of the message the rule is dependent on
  2. Operation: How the rule depends on the response to the message
  3. Response: The response to the message that makes the rule true

When the all elements of the rule are true, the bot will follow the connection with that rule applied.

So, we can use rules to decide when the bot should follow one connection as opposed to another to decide what message to show to a user next, depending on how the user responds to a message.

Watch the video below to learn how to apply rules to connections.

As mentioned in the video, you can also think of the way a rule operates on a connection in the form of a statement:

‘4.0 Help’ connects to ‘5.0 Type’ if ‘4.0 Help’ is ‘Prepare a contract’.

You may notice that this statement also appears at the top of the rules editor to help guide you as you create rules.

Practice your skills

Once you start building, making rules will become second nature to you. So, start now and try applying some rules to your bot! If you find it challenging at first don’t worry – you’re certainly not alone.

Before you move on to the next session, complete the following tasks:

  1. Create at least 2 connections coming from the same message.
  2. Apply a rule to at least 2 connections.
  3. Test your bot to make sure it works the way you planned.

Once you’re done with these tasks, head to the next section to learn how to automate documents.

Go to the next session →