Conditions

A condition is a true/false check on the user’s question.

A condition is a TRUE or FALSE check on the user’s question. A rule has many conditions. The rule’s story is selected as the Passing Rule, and if all the conditions are met, it's Story is returned as the bot's response.

Types of User Context

The user context is the data that is specifically assigned to a Rule. It determines the context of the message that the users might ask.

  • Message - what a user sends directly to the bot

  • Memory - what a bot remembers previously about the current chat session

  • User attribute - what a bot remembers about a user

  • Natural language Processing (NLP) - what the bot’s NLP engines evaluate a message with.

Memory

At times, a rule does not respond to user's direct message, rather it responds from the interaction history.

Example: If we go to the "hey!" story, we can add an "action" response to make the bot remember this. Let's set the action as follows:

ACTION
type: memory
property: said-hey
funtion: set to
value: true

Now when the bot replies to a user with "hey!", the bot actually set a property called "said-hey" to true on chat's session memory.

CHAT
User: hello there
Bot: hey!
Bot: (secretly, without telling the user, sets *said-hey* to true in the session)

Add a NEW rule with a NEW condition:

CONDITION
type: memory
property: said-hey
function: equals
value: true

and let's assign this to a new story called "You Just Said Hello"

Now, the chat will go as follows:

CHAT
User: hello there
Bot: hey!
Bot: (secretly, without telling the user, sets *said-hey* to true in the session)
User: how are you?
Bot: (saw that the property said-hey equals true in the user's chat session)
Bot: you just said hello

Attribute

With every User Context chosen, there will be an attribute (text, image, video, etc.).

The first step to implementing a condition is to select an attribute. The next step is to select a condition that complements the attribute.

Functions complementing the attribute

Every attribute comes with complementing functions.

has keyword

"has keyword" is one of the most commonly used functions for the text attribute. It is extremely helpful in FAQs.

'has keyword' is the only function that supports multiple values. (more than 1 keyword)

"What is the cost of shipping" has keyword "shipping" // true
"What are the opening and closing hours of your shop" has keyword "opening,closing" // true
"I need help with my account" has keyword "help,account" // true
"Can I get a refund for my purchase?" has keyword "refund" // true
"Do you offer discounts on bulk orders?" has keyword "discounts,bulk" // true
"What is the cost of shipping" has keyword "payment" // false
"What are the opening and closing hours of your shop" has keyword "pricing" // false
"I need help with my account" has keyword "support" // false
"Can I get a refund for my purchase?" has keyword "exchange" // false
"Do you offer discounts on bulk orders?" has keyword "single" // false

does not have keyword

The opposite of the has keyword function. Checks if a property does not have a keyword from the list of declared keywords.

"What is the cost of shipping" does not have keyword "payment" // true
"What are the opening and closing hours of your shop" does not have keyword "pricing" // true
"I need help with my account" does not have keyword "support" // true
"Can I get a refund for my purchase?" does not have keyword "exchange" // true
"Do you offer discounts on bulk orders?" does not have keyword "single" // true
"What is the cost of shipping" does not have keyword "shipping" // false
"What are the opening and closing hours of your shop" does not have keyword "opening,closing" // false
"I need help with my account" does not have keyword "help,account" // false
"Can I get a refund for my purchase?" does not have keyword "refund" // false
"Do you offer discounts on bulk orders?" does not have keyword "discounts,bulk" // false

equals

Equals function prompts the chatbot to find the exact match of the word input. It checks an EXACT match. Used for direct checks.

"hello" equals "hello" // true
"12345" equals "12345" // true
"goodbye" equals "goodbye" // true
"openai" equals "openai" // true
"2024" equals "2024" // true
"hello" equals "HELLO" // false
"12345" equals "1234" // false
"goodbye" equals "hello" // false
"openai" equals "OpenAI" // false
"2024" equals "2023" // false

does not equal

The opposite of the equals function. Checks if a property does not equal a value

"hello" does not equal "HELLO" // true
"12345" does not equal "1234" // true
"goodbye" does not equal "hello" // true
"openai" does not equal "OpenAI" // true
"2024" does not equal "2023" // true
"hello" does not equal "hello" // false
"12345" does not equal "12345" // false
"goodbye" does not equal "goodbye" // false
"openai" does not equal "openai" // false
"2024" does not equal "2024" // false

matches regex

This is the most powerful check. Knowledge of regular expressions is required to use this function. Used for pattern-matching checks.

"hello world" matches regex hello(?=\sworld) // true
"hello everyone" matches regex hello(?=\sworld) // false
"hello everyone" matches regex hello(?!\sworld) // true
"hello world" matches regex hello(?!\sworld) // false
"world hello" matches regex (?<=world\s)hello // true
"everyone hello" matches regex (?<=world\s)hello // false
"everyone hello" matches regex (?<!world\s)hello // true
"world hello" matches regex (?<!world\s)hello // false
"I have 2 apples" matches regex \d // true
"I have apples" matches regex \d // false
"hello@world.com" matches regex \S+@\S+\.\S+ // true
"hello world" matches regex \S+@\S+\.\S+ // false
"hello world" matches regex \bworld\b // true
"helloworld" matches regex \bworld\b // false
"12345" matches regex ^\d{5}$ // true
"1234" matches regex ^\d{5}$ // false
"hello world" matches regex \s // true
"helloworld" matches regex \s // false

exists

Checks that a property exists. Does not require a value. Used for presence checks.

// If a user sends a text message
message[text] exists // true

// If a user clicks a button
message[postback] exists // true

// If a user sends an image
message[image] exists // true

// If a user sends an image with a caption
message[text] exists // true

// If a user sends a video
message[video] exists // true

// If a user sends an audio
message[audio] exists // true

// If a user sends a location
message[location] exists // true

// If a user sends a sticker
message[sticker] exists // true

// If a user has a last name
user[last_name] exists // true

// If a user has a language
user[language_code] exists // true

does not exist

Checks that a property does not exist. opposite of $exists. Does not require a value. Used for negation checks.

// If a user sends a text message
message[text] does not exist // false

// If a user clicks a button
message[postback] does not exist // false

// If a user sends an image
message[image] does not exist // false

// If a user sends an image with a caption
message[text] does not exist // false

// If a user sends a video
message[video] does not exist // false

// If a user sends an audio
message[audio] does not exist // false

// If a user sends a location
message[location] does not exist // false

// If a user sends a sticker
message[sticker] does not exist // false

// If a user has a last name
user[last_name] does not exist // false

// If a user has a language
user[language_code] does not exist // false

less than

Checks that a numeric property is less than the value. Used for number comparison checks.

"5" less than 10 // true
"3" less than 7 // true
"2" less than 5 // true
"15" less than 20 // true
"8" less than 9 // true
"5" less than 3 // false
"10" less than 5 // false
"7" less than 2 // false
"20" less than 15 // false
"9" less than 8 // false

greater than

Checks that a numeric property is greater than the value. Used for number comparison checks.

"10" greater than 5 // true
"7" greater than 3 // true
"5" greater than 2 // true
"20" greater than 15 // true
"9" greater than 8 // true
"3" greater than 5 // false
"5" greater than 10 // false
"2" greater than 7 // false
"15" greater than 20 // false
"8" greater than 9 // false

Last updated