# Randomizing  message content

## Message roulette:  Crafting varied responses

Discover how introducing variability in message content can contribute to a more engaging and dynamic user experience, improving the overall effectiveness of your chatbot interactions.

:question:**Why a single well-crafted message might not be enough:**

* **User Engagement**: Varied and dynamic responses prevent conversations from becoming monotonous or predictable. Users are more likely to stay engaged and interested when the chatbot's responses are diverse and not repetitive.
* **Human-like Interaction**: A broader range of alternatives contributes to a more natural and human-like conversation. Mimicking the way humans express themselves makes interactions with the chatbot feel more authentic and relatable.
* **A/B Testing Opportunities**: Having multiple alternatives provides opportunities for A/B testing. This allows you to experiment with different messaging approaches and identify which ones resonate best with your audience, leading to continuous improvement in the chatbot's performance.

{% hint style="warning" %}
Currently, configuring alternatives for message content is not available as a user-friendly feature on our Flow editor GUI:cry:. Don't worry, this functionality is on our roadmap! While not as straightforward as a few clicks, here are detailed instructions on [method 1 ](#method-1-randomize-the-path-to-the-next-msg-node)or[ method 2](#method-2-set-the-message-content-with-variables) and how to achieve this with the use of our smart function and some clever flow design:sparkles:\
\
Thanks for your patience; we're crafting something amazing!
{% endhint %}

{% hint style="success" %}
**Tip:** However, you can effortlessly configure multiple outputs for your chatbot. See [MESSAGE node](/digital-agent/conversation-flow/nodes-explained/message-node.md).\
![](/files/9b5Q0mXqMWUuvosigHqg)\
Experiment with having multiple chat bubbles displayed in a sequence to enrich your chatbot interactions with dynamism and engagement.
{% endhint %}

***

## Method #1: Randomize the path to the next MSG NODE

This method involves creating a randomized decision tree where the chatbot dynamically selects its path based on random decisions. While it requires more clicks as you set up and maintain multiple nodes in the flow, the advantage lies in the visibility of the decision-making process.

<figure><img src="/files/QEO1cwkHwkVrSoYjLDAD" alt=""><figcaption><p>Here's how it looks like in flow.</p></figcaption></figure>

### Step 1: Set up messages

1. **Prepare multiple MSG nodes, each representing a potential message in the conversation.** \
   If you need to go through some MSG node basics first, check out [MESSAGE node](/digital-agent/conversation-flow/nodes-explained/message-node.md)

<figure><img src="/files/jG0KW7Z4uvKOgs6p4dlR" alt=""><figcaption></figcaption></figure>

### Step 2: Insert the point of decision

1. **Introduce a DEC node before the MSG nodes to serve as the decision point.**<br>

   <figure><img src="/files/UaOUH07c58Y3QPyntKwk" alt=""><figcaption></figcaption></figure>

2. **Within the DEC node, set up a new variable. Let's name it `random_number`. Use the smart function random\_int to generate a random number which will be saved in `random_number` variable.**

<figure><img src="/files/ELJET8G0rwolikEr0eLe" alt=""><figcaption><p>Setting random_int smart function.</p></figcaption></figure>

3. **Establish conditions in the DEC node to guide the subsequent path based on the randomly generated value.**\
   Don't forget to set one of the MSG nodes as a fallback target, in case none of the conditions are met.

<figure><img src="/files/CPbI5L1k7iNp83XaTfbz" alt=""><figcaption></figcaption></figure>

<details>

<summary>Quick copy conditions from example</summary>

```python
random_number == 1 
```

```python
random_number == 2
```

```python
random_number == 3
```

</details>

Within this step, the smart function random\_int generated a whole number from 1 to 3 (included). The value is saved into `random_number` variable. Based on its value, one of the conditions is fulfilled and the next node is selected accordingly. In case of error when all conditions fail, flow continues to set fallback target node (Other).

### Step 3: Tie the paths back together

1. **Set the next target from all MSG nodes.**

<figure><img src="/files/gRD403Mo65OIPHV840IQ" alt=""><figcaption></figcaption></figure>

### You're done!

<figure><img src="/files/mvunkR4toppcUDLau3jf" alt=""><figcaption><p>Fist message to be shown is chosen randomly.</p></figcaption></figure>

***

## Method #2: Set the message content with variables

This method involves configuring the content of MSG nodes as variables. Utilizing the `random_int` smart function, the variable is set based on the outcome of the randomization. The variable is then used as input for the MSG node, and the content is dynamically populated based on the variable value.

<figure><img src="/files/LwusFtX4e3YFQS8Yu6VT" alt=""><figcaption><p>Here's how it looks in the flow.</p></figcaption></figure>

While this method streamlines the process within a single node, reducing the complexity of the flow diagram, it requires more coding. \
Keep in mind that the intricacies of this method might not be immediately apparent when viewing the broader flow diagram. Working with string variables within this setup imposes restrictions on Markdown and formatting options for chatbot outputs.

### Step 1: Use `random_int` smart function

1. **In the MSG node, create a new variable**. Let's name it random\_number.
2. **Employ the `random_int` function** to determine the variable value randomly.

<figure><img src="/files/QkqvVjpoh39C2n6HamZ0" alt=""><figcaption></figcaption></figure>

### Step 2: Set a new variable

1. **Set a new variable for the content of your message**. Let's name it `message_content`.
2. **Set the value of the variable as a string, based on the results of randomization** which is stored in `random_number.`
3. Use `if... else..` format.

<figure><img src="/files/JGG23yWZovYth2TwGyNp" alt=""><figcaption></figcaption></figure>

<details>

<summary>Quick copy code from example</summary>

{% code title="message\_content" overflow="wrap" %}

```python
"Hello, I am your AI assistant." if random_number == 1 else "Hey, there! Wanna chat with AI?" if random_number == 2 else "Hi, let's have a chat." if random_number == 3 else "Hi, welcome to our chat!"
```

{% endcode %}

</details>

### Step 3: Assign variable as input for message

1. **Use the `message_content` variable as input for the MSG node**, allowing the content to be dynamically filled based on the variable value.

<figure><img src="/files/7XYidFsmxWThQsVn4Yxr" alt=""><figcaption></figcaption></figure>

### You're done!

<figure><img src="/files/4R74k831BmojTApQTDlx" alt=""><figcaption><p>Content of the first message is chosen randomly.</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.borndigital.ai/for-advanced-users/conversation-design-tips/randomizing-message-content.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
