# Conditions

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.

![](https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LirAdLo22OkAW9w3tvY%2F-LjF0E5-yn9IZifvFkbP%2F-LjFBwGL2jbdqSL9RYb9%2FScreenshot%202019-07-08%2014.09.01.png?alt=media\&token=102e22c3-969a-4758-aec8-3fa8a651abcd)

### **Types of User Context**

![User Context options](https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LirAdLo22OkAW9w3tvY%2F-LjFIMPW-BOQH0vvwmQq%2F-LjFISl1GeolTtDrkBhi%2FScreenshot%202019-07-08%2014.38.06.png?alt=media\&token=e0f167f5-10b6-490d-aff8-c93481f198ee)

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.).&#x20;

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

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FKOtag8JAMQQKew9sXnjj%2Fchrome-capture-2024-11-26%20(1).gif?alt=media&#x26;token=fe722faf-fefe-4773-af2a-23dcdd19997d" alt=""><figcaption></figcaption></figure>

### Functions complementing the attribute

Every attribute comes with complementing functions.&#x20;

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FXcyrCEgjA8KYtFxahWq8%2Fchrome-capture-2024-11-26%20(2).gif?alt=media&#x26;token=2ad695da-587b-4708-89a4-8ed26da072f2" alt=""><figcaption></figcaption></figure>

Below will be a list of the the functions that are available as well as examples of the complementing functions that is available when setting conditions.

<table><thead><tr><th width="237">Function</th><th>Description</th></tr></thead><tbody><tr><td><strong>has keyword</strong></td><td>This function checks if the message contains a specific keyword or phrase.</td></tr><tr><td><strong>does not have keyword</strong></td><td>This checks if a specific keyword or phrase is not present in the message.</td></tr><tr><td><strong>equals</strong></td><td>This checks if the message exactly matches a specific value or keyword.</td></tr><tr><td><strong>does not equal</strong></td><td>This checks if the message does not match a specific value or keyword.</td></tr><tr><td><strong>matches regex</strong></td><td>This checks if the message matches a regular expression pattern.</td></tr><tr><td><strong>exists</strong></td><td>This checks if a specific property or value exists in the user’s data.</td></tr><tr><td><strong>does not exist</strong></td><td>This checks if a property or value does not exist in the user’s data.</td></tr><tr><td><strong>less than</strong></td><td>This checks if a number is less than another value.</td></tr><tr><td><strong>greater than</strong></td><td>This checks if a number is greater than another value.</td></tr><tr><td><strong>has tags</strong></td><td>This checks if the user's message has tagged entities.</td></tr><tr><td><strong>does not have tags</strong></td><td>This checks if the user's message does not have tagged entities.</td></tr><tr><td><strong>is exactly</strong></td><td>This checks if the message exactly matches a specific keyword, as opposed to containing it.</td></tr><tr><td><strong>is not exactly</strong></td><td>This checks if the user's message does not exactly match a given keyword or phrase.</td></tr><tr><td><strong>has exact tag</strong></td><td>This checks if the user's message "is exactly" a tagged entity.</td></tr><tr><td><strong>does not have exact tag</strong></td><td>This checks if the user's message is not "is exactly" a tagged entity.</td></tr><tr><td><strong>is emoji</strong></td><td>This checks if the user's message is exactly an emoji.</td></tr></tbody></table>

{% hint style="info" %}
For **has tags, does not have tags, has exact tag,** and **does not have exact tag** it is dependant on the tags created under the **Tags Dashboard**. You may visit [**Tags**](https://docs.botdistrikt.com/features/settings/tags) to learn more about the properties of tagging.
{% endhint %}

### Examples

#### ***has keyword***

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

{% hint style="info" %}
'has keyword' is the only function that supports multiple values. (more than 1 keyword)&#x20;
{% endhint %}

```
"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](https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285) 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
```

#### ***has tags***

This checks if the user's message has tagged entities. For a deeper understanding of how tags work, including examples and their use cases, refer to the [**Tags**](https://docs.botdistrikt.com/features/settings/tags) section.

#### ***does not have tags***

This checks if the user's message does not have tagged entities. For a deeper understanding of how tags work, including examples and their use cases, refer to the [**Tags**](https://docs.botdistrikt.com/features/settings/tags) section.

#### ***is exactly***

This checks if the message exactly matches a specific keyword, as opposed to containing it.

```
"cancel my order" is exactly "cancel my order" // true
"cancel subscription" is exactly "cancel subscription" // true
"update my account" is exactly "update my account" // true
"track my order" is exactly "track my order" // true
"order status" is exactly "order status" // true
"cancel my order" is exactly "cancel subscription" // false
"cancel subscription" is exactly "update my account" // false
"update my account" is exactly "track my order" // false
"track my order" is exactly "order status" // false
"order status" is exactly "cancel my order" // false
```

#### ***is not exactly***

This checks if the user's message does not exactly match a given keyword or phrase.

```
"cancel my order" is not exactly "cancel subscription" // true
"cancel subscription" is not exactly "update my account" // true
"update my account" is not exactly "track my order" // true
"track my order" is not exactly "order status" // true
"order status" is not exactly "cancel my order" // true
"cancel my order" is not exactly "cancel my order" // false
"cancel subscription" is not exactly "cancel subscription" // false
"update my account" is not exactly "update my account" // false
"track my order" is not exactly "track my order" // false
"order status" is not exactly "order status" // false
```

#### ***has exact tag***

This checks if the user's message is exactly a tagged entity. For a deeper understanding of how tags work, including examples and their use cases, refer to the [**Tags**](https://docs.botdistrikt.com/features/settings/tags) section.

#### ***does not have exact tag***

This checks if the user's message is not exactly a tagged entity. For a deeper understanding of how tags work, including examples and their use cases, refer to the [**Tags**](https://docs.botdistrikt.com/features/settings/tags) section.

#### ***is emoji***

This checks if the user's message is exactly an emoji (no text, just an emoji).

```
"🙂" is emoji // true
"😄" is emoji // true
"😊" is emoji // true
"💬" is emoji // true
"👍" is emoji // true
"Hello" is emoji // false
"Order status" is emoji // false
"Can you help me?" is emoji // false
"What time is it?" is emoji // false
"Cancel my order" is emoji // false
```
