Skip to main content

Conditional Bot Steps

A conditional step means that the defined bot step (with asserters, logichooks) will only be executed if a certain condition is met.

The condition can be defined in a special logichook, which ref must be started with ‘CONDITIONAL_STEP’.

Example: ‘CONDITIONAL_STEP_CAPABILITY_VALUE_BASED’

Conditional logichooks integrated into Botium

There are some basic conditional logic hooks integrated into Botium:

Configuration

In the Botium UI this icon represents a conditional logic hook. If we add a conditional logic hook to a bot step, the parameters must be configured to be able to evaluate the conditional logic.

Let’s imagine that we have a chatbot, which can answer the question ‘Are you open?’, based on the current time:

  • 8:00-16:30 - The shop is open

  • 16:31-7:59 - The shop is closed

So we have to add a Time Based Conditional Logic Hook to our bot step with the following configuration:

Note: With this configuration, if the condition is true (i.e., the time is between 8:00 AM and 4:30 PM), the bot will respond with, "The shop is open."
Notice the small indicator to the left of the bot step, this is indicating that it's a conditional step. Currently, this is the only step in this group (more on groups later).

Tip: If the time is, for example, 17:01 PM or 6:38 AM, the condition is false, so the bot step (and the message) will be skipped. To handle these other times, you can add another bot step with the opposite condition.

Now we have a group of conditional bot steps with two steps. This means that each bot step in the group, where the condition is true (not skipped), will be asserted on the same bot message.
Tip: In the example above, only one of the bot steps will be evaluated because there is no overlap between the conditions. However, if the conditions were 8:00 AM - 16:30 PM and 15:00 PM - 7:59 AM, there would be an overlap. While this isn't the typical way of using it, it is possible.

Handling multiple conditional groups

Now we would like to validate multiple bot messages. So let’s change the chatbot to have two bot messages with the question ‘Are you open?’:

  1. Time Frame: 8:00-16:30:
    • Message 1: The shop is open.
    • Message 2: What can I do for you?
  2. Time Frame: 16:31-7:59:

    • Message 1: The shop is closed.
    • Message 2: Please come back later.

Each conditional step requires a Condition Group ID. Steps with the same ID are grouped together.

  • Group G1: For the time frame 8:00-16:30
  • Group G2: For the time frame 16:31-7:59


You can easily identify which steps belong to the same group in the Convo Editor by looking at the icons on the left of each step. One conditional group asserts one bot message.

Developing your own Conditional Logic Hook

If you can't find the conditional logic hook you need, you can create your own using the information in the Developing Custom Logic Hooks article. You'll need to implement the onBotPrepare function like this:

onBotPrepare ({ convo, convoStep, args }) {
 const conditionGroupId = args[1]
 let params
 try {
 params = JSON.parse(args[0])
 } catch (e) {
 throw new Error(`ConditionalCustomLogicHook: No parsable JSON object found in params: ${e}`)
 }
 convoStep.conditional = {
 conditionGroupId
 }
 convoStep.conditional.skip = this.evaluateParams(params)
}
Note: When you add it to the botium.json or to the Components in Botium Tools & Settings > Settings > COMPONENTS, don’t forget to define the component ref code with the “CONDITIONAL_STEP” prefix:

"ref": "MY-LOGICHOOK-NAME"

Was this article helpful?

0 out of 0 found this helpful