# A simple chatbot

Creating a chatbot on Mavibot platform is quite simple if you have completed the “Basics of Mavibot bot building” section, which explains the basics of working with the funnel constructor (editor), with types of blocks and arrows, with types of attachments, buttons, as well as a calculator, etc.

{% hint style="info" %}
Before you start creating a simple chatbot, we strongly recommend you to study the “Mavibot Bot Building Basics" section! ссылка “[Основы ботостроения Salebot](broken://pages/-M1GcGC3Set0iu6nGG-E)”!
{% endhint %}

## How to create a block

To create the first block in the funnel, double-click on the editor field with the left mouse button:

<figure><img src="/files/uFeKTm7dryJkIDcWKBWJ" alt="" width="563"><figcaption><p>How to create a block with a mouse click</p></figcaption></figure>

As you can see in the example above, the block can be moved throughout the field editor by selecting any convenient location.

You can also create a block by simply clicking on "Save" at the bottom of the screen and selecting its type:

<figure><img src="/files/k1Sny84vHFZ4PTp1jTg2" alt="" width="563"><figcaption><p>How to create a block with a choice of type</p></figcaption></figure>

You can select the following block types to start the chatbot: "Start a dialog" or "Primary condition check":

<figure><img src="/files/Zrs3EzCH2qVQVdzYuFeT" alt="" width="531"><figcaption><p>Pict. 1</p></figcaption></figure>

We know from the article "Creating blocks and their types" ссылка [Создание блоков и их типы](broken://pages/-LxaF6DgPjVFl2Gjvs6m)" that the "Primary Condition verification" block type has the highest priority: like the "Dialog Start" block type, the block diagram chain of your chatbot can be started from it&#x20;

Technically, the main difference is that if there is a block with the "Primary condition verification" type in the chatbot scheme and if the user enters a keyword (phrase) of this block during the dialogue, the conversation with the client will continue from this block.\
This allows you to provide additional flexibility in the structure of the dialogue, and the client can immediately get what they need (for example, to conclude a deal with you or register for your course).

In the block conditions, you need to specify a keyword (for example, the Tag of a mini landing page/website or another phrase necessary for the bot to work, "Hi; hello, separated by a semicolon), to which the bot will respond:

<figure><img src="/files/N59NnhjPFbLGvoPVqepO" alt="" width="523"><figcaption><p>Pic. 2 Example of filling block for a chatbot</p></figcaption></figure>

As can be seen in the example above (Pic. 2), in the block condition, we specified the tag of the mini landing page created on the Mavibot platform from which the subscription will take place, and in the "Match selection" field, we selected the "full match" type.

If necessary, you can specify keywords of a different type in the condition (for example, "Hi, Hello", etc.). In this case, select the matching type "Ignoring errors and inaccuracies", which will help the bot recognize keywords in your clients' messages written with typos or errors:

<figure><img src="/files/YOOasJ9dUSUwe1jxQkY6" alt="" width="563"><figcaption><p>Реакция блока на ключевые фразы с ошибками</p></figcaption></figure>

## How to create the following block in the diagram and specify the arrow conditions

Pull the arrow from the first block downwards. In this way, the designer automatically creates a new block and uses the arrow to connect the blocks into one scheme, which will allow the client to move further along the funnel:

<figure><img src="/files/0TmrazsH9dFs1lngIjrM" alt="" width="563"><figcaption><p>Creating a new block in the diagram</p></figcaption></figure>

In the arrow settings, we will specify such conditions so that the chatbot collects the data entered by the user and saves it to the variable we need.

To do this, go to the arrow settings, where you need to activate the "User enters data" switch, and also specify the variable to which the chatbot will save the client's data:

<figure><img src="/files/YHEUlmFSQXdau8PejWGl" alt="" width="563"><figcaption><p>Pic. 3</p></figcaption></figure>

After the user sends his name in the message, the bot will write it to the required variable:

<figure><img src="/files/spfONrH6kdvpC6kPr7e5" alt="" width="563"><figcaption><p>Pic. 4. The client's card with his data</p></figcaption></figure>

In the second block of the diagram, we will write a message that will request the age of your client. To do this, use regular expressions. ссылка[регулярными выражениями](broken://pages/-M0wjAtzg71YW7LB-2D8).&#x20;

> Regular expressions that are used in this article:
>
> 1. mobile number  -> ^((\\+7|7|8)+(\[0-9]){10})$
> 2. email -> ^\[-\w.]+@(\[A-z0-9]\[-A-z0-9]+\\.)+\[A-z]{2,4}$
> 3. entering numbers (for age) -> ^\[1-9]+\[0-9]\*$
>
> See the full list of regular expressions here. ссылка [здесь](broken://pages/-M0wjAtzg71YW7LB-2D8).&#x20;

In the message field of the second block of the Chatbot diagram, write down the necessary question: for example, "How old are you?":

<figure><img src="/files/4sG9IVdDdi1gJhSzHWEr" alt="" width="563"><figcaption><p>Pic. 5. Message to the user</p></figcaption></figure>

Then follow these steps:

Step 1. Pull the arrow from the second block to create the next block diagram in the same way as the previous one was created.

Step 2. In the arrow settings in the condition, write a regular expression like ^\[1-9]+\[0-9]\*$ and select the match type "Regular Expression"

<figure><img src="/files/dAmNE98n2DO2RWV1Pn0N" alt="" width="503"><figcaption><p>Pic. 6. Using a regular expression</p></figcaption></figure>

{% hint style="warning" %}
Remember, the matching choice during using regular expressions need to be "Regular Expression", otherwise the chatbot scheme will work with errors!
{% endhint %}

Step 3. In the arrow settings, activate the "User enters data" switch and enter the name of the variable where the chatbot will save the client's data:

<figure><img src="/files/wd57DnowROwWRV6GvykB" alt="" width="439"><figcaption><p>Рис. 7. </p></figcaption></figure>

The example (Pic. 8) shows that the chatbot writes the client's data to his card:

<figure><img src="/files/3hrBKLlUKPcUwxFNvV7d" alt="" width="563"><figcaption><p>Pic. 8. The client's card with his data</p></figcaption></figure>

## Customer data collection unit: phone number/email

During the dialogue with clients, there is often a need for subsequent communication with the client by phone, but the question arises: how can I set up a chatbot to automatically collect information about the client? Using regular expressions, of course.

To use the phone number (or email) collection feature, use the following regular expressions:

1. Mobile number (Russia): ^((\\+7|7|8)+(\[0-9]){10})$&#x20;
2. Mobile number (with any country code): ^(\\+)?((\d{2,3}) ?\d|\d)((\[ -]?\d)|( ?(\d{2,3}) ?)){5,12}\d$
3. Email: ^\[-\w.]+@(\[A-z0-9]\[-A-z0-9]+\\.)+\[A-z]{2,4}$

{% hint style="danger" %}
Make sure that there is no space before the regular expression in the arrow condition!

<img src="/files/PJ4ID9LZRcLlKLWolY1o" alt="" data-size="original">

Otherwise, the chatbot scheme will work with errors.
{% endhint %}

{% hint style="info" %}
In the scheme, we used a regular expression for phone numbers of any country.&#x20;
{% endhint %}

Just as the bot recorded the client's name and age, the user's phone number (or email address, if the appropriate regular expression is selected) will be added to the system.

Create a block where you will use the bot to send a message to the client asking them to send a phone number (or email) to the user:

<figure><img src="/files/weGdALyqK7hqyFwp1qQQ" alt="" width="563"><figcaption><p>Pic. 9. The block with the message for receiving the client's phone number</p></figcaption></figure>

Next, pull the arrow out of this block, where the corresponding regular expression need to be written in the arrow condition.

<figure><img src="/files/D568YF4Jpi9mst7poXv0" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="success" %}
As noted earlier, do not forget to set the matching option to "Regular expression" in order to avoid errors in the chatbot.
{% endhint %}

With the condition where regular expressions are prescribed, the chatbot will accept only the values of the mobile number in the form of numbers, and in the case of a postal address, only the established standardized types of postal addresses.

If the client has sent a message that does not match the value of the phone number (email), you can create a block that will inform the client about the incorrectly entered data:

<figure><img src="/files/FeajkcNKHoT5T3mM1Obi" alt="" width="563"><figcaption></figcaption></figure>

To do this, from the block where you entered the message for the client's phone number, swipe the second arrow and write the necessary message in the created block, for example, "This is not a phone number. Please enter the phone number!":

<figure><img src="/files/njrpEVOP4NGv6bDrqgOJ" alt=""><figcaption><p>Рic.11</p></figcaption></figure>

Select the "Out of condition" block type (Pic. 11). This block does not have a condition like in the "Dialog Status" block, but you cannot go to it.

In relation to our scheme, the "Not state" block will be very useful, because then the user will not switch from the last block, and to proceed further through the funnel, he will need to enter a phone number:

<figure><img src="/files/NvWGZauLIZBJMnjtqKwF" alt="" width="563"><figcaption><p>Pic. 12</p></figcaption></figure>

{% hint style="info" %}
You can find out about the various functions of the "Not state" block in the article of the same name. ссылка "[Не состояние](broken://pages/-M1G0tS64N7tDTadS8Ao)"&#x20;
{% endhint %}

## Blocks of the bot's next dialogue with the client

Let's start setting up blocks with buttons, during clicking by the client, the chatbot will respond in accordance with the conditions of the button (for example, consent to payment; direct payment or redirection to another third-party site, etc. functions).

To do this, from the block marked in red in Pic. 12, pull the arrow below, where you can set the timer in the settings:

<figure><img src="/files/ksURaxj56asmKP0Hy8aX" alt="" width="485"><figcaption><p>Pic. 13</p></figcaption></figure>

To set the timer, go to the arrow settings and set the required time interval, after which the chatbot will send a message to the client:

<figure><img src="/files/MlT3CJT983riqJQGiyhM" alt="" width="563"><figcaption><p>Pic. 14</p></figcaption></figure>

In the next block, add the "Call me back today" and "Call me back tomorrow" buttons.

{% hint style="info" %}
Read more about button settings in the chatbot scheme in this "article". ссылка [статье](broken://pages/xeepnRj969zW3xRimkdg).&#x20;

To learn how to connect and configure payment systems in order to do payments in buttons (links) in the bot, see the section "Integrations" -> "Payment systems". ссылка [Платежные системы](broken://pages/-M6-eHpkYrT0zS4HYG4r)".&#x20;
{% endhint %}

### How to add buttons

To add buttons that the chatbot will send to the client, click on the "Buttons" inside the block settings:

<figure><img src="/files/uM9R1r17c8XbnlUDSqPs" alt="" width="392"><figcaption><p>Pic. 15</p></figcaption></figure>

Next, click on the "Add button".

<figure><img src="/files/boauoQu0G2oCi6Gkrq05" alt="" width="386"><figcaption><p>Pic. 16</p></figcaption></figure>

Next, a window will open for adding a button, where you need to specify the name of the button and configure it according to your requirements:

<figure><img src="/files/5r20fiJxgqoekQm9O2UC" alt=""><figcaption></figcaption></figure>

Now this block will direct the buttons to your client, which will allow you to later identify the time (in relation to the scheme made in this article) when it would be better to contact him:

<figure><img src="/files/8f4ILN0Lsj5XAWCQ0lhJ" alt="" width="518"><figcaption><p>Pic. 17.The bot's dialog in the testing tab</p></figcaption></figure>

The dialogue with the client will be displayed in the Clients tab, where you can track all changes in the dialogues with clients:

<figure><img src="/files/sKPNBfAwgq2IvjqXKKMp" alt="" width="563"><figcaption><p>Pic. 18. Dialog view in the "Clients" tab</p></figcaption></figure>

After the client clicks on a certain button, a corresponding message will be sent to the dialog in the "Clients" tab: for example, "call me back today":

<figure><img src="/files/YK7S7jpkIwJAof7ynRF3" alt="" width="347"><figcaption><p>Pic. 19</p></figcaption></figure>

### End of dialogue with the client blocks

After adding the buttons, it is necessary to end the dialogue with the client in some way so as not to leave him in the dark after he clicks on the corresponding button.

Let's create two blocks with arrows coming from the block with the buttons for this:

<figure><img src="/files/Ba6ehnPA6EyY8wkGSzCH" alt="" width="416"><figcaption><p>Pic. 20. Dialog Completion Blocks</p></figcaption></figure>

Now we will write the name of each button in the conditions of each arrow:

<figure><img src="/files/eo9lAJmsJ8EG5JV8b4mD" alt="" width="533"><figcaption><p>Pic. 21</p></figcaption></figure>

In the conditions of the created blocks, write down the necessary messages that the chatbot will send when the client clicks the button:

<figure><img src="/files/2cztZKNd8UGuLEnarZ0K" alt=""><figcaption><p>Pic. 22. The chatbot block that ends the dialog</p></figcaption></figure>

Now the chatbot will notify the client that his request has been accepted.

<figure><img src="/files/35ZPZhdy4CO2s0qbWqWS" alt="" width="563"><figcaption></figcaption></figure>

In the "Clients" section, you can see the client's response and call them back at a convenient time, as well as continue the dialogue if necessary or clarify details.

To check the data that the client sent you, go to the "Clients" tab:

<figure><img src="/files/OreDcb9HETE0QsKZeBiT" alt="" width="563"><figcaption><p>Pic. 23. Where to check client's data</p></figcaption></figure>

The final scheme of the chatbot looks like this:

<figure><img src="/files/yVVYNbGpDSo55kwddikx" alt="" width="467"><figcaption><p>Pic. 24</p></figcaption></figure>

Thus, we have created a simple chatbot consisting of only eight blocks, which receives information about the client and records them in variables in the form of name, age and phone number, as well as when it is better for your manager to contact the user.


---

# 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.mavibot.ai/how-to-do.../a-simple-chatbot.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.
