# AI assistant with MaviBot tables

Using a dedicated function developed by the MaviBot team, your AI chatbot can intelligently read values from a Google Sheet and store them in a **system variable within your project settings**. This creates a synchronized, dynamic data source for your assistant.

#### **Practical applications**

This capability is essential for scenarios such as:

* **Product catalog assistant:** an AI that advises clients on your **current product range, prices, and availability** in real time.
* **Smart promotion bot:** a bot that **promotes your offerings** by dynamically highlighting features, specs, or deals pulled directly from your sheet.

### **How to prepare your table for integration**

To get started, go to the sheets section:

<div data-with-frame="true"><figure><img src="/files/xcnX0LEWAdRUoEYuU403" alt=""><figcaption></figcaption></figure></div>

Next, you will see the "Add sheet" button, which opens a modal window in which you need to enter the name of the sheet:

<div data-with-frame="true"><figure><img src="/files/Ag8W7utNkhBMjMlmfY6x" alt=""><figcaption></figcaption></figure></div>

Enter the name for the sheet and click on the "Done" button. Then a new sheet will be created in the project and will appear in the "Sheets" section:

<div data-with-frame="true"><figure><img src="/files/tPzpfiFvFHqsYvczZxzt" alt=""><figcaption></figcaption></figure></div>

### Sheet settings

After creating the sheet, you need to add rows and columns. To do this, find the "Go to" button on the card of the desired sheet and click on it.

You see next settings:

<div data-with-frame="true"><figure><img src="/files/ROKc0xxvDQHxHoYZDmHx" alt="" width="563"><figcaption></figcaption></figure></div>

To add column with a name, click the "+" button:

<div data-with-frame="true"><figure><img src="/files/G26ikN7Cqh8KJl3JhENa" alt=""><figcaption></figcaption></figure></div>

When you click the button, a modal window will open where you can enter a name for the new column.

Afte entering the column name, click on the "Done" button, then the new column will be added to the sheet. Add the required number of columns and then rows.

<div data-with-frame="true"><figure><img src="/files/GGqJdRsnueHOoptS5hX7" alt="" width="563"><figcaption></figcaption></figure></div>

&#x20;Now, you sheet looks like this.

<div data-with-frame="true"><figure><img src="/files/kbln5XZonNaOpCeWri6N" alt="" width="563"><figcaption></figcaption></figure></div>

Copy (remember) the sheet ID: to do this, click on the address bar:

<div data-with-frame="true"><figure><img src="/files/DQvSixpIgV4BPVrP5vvn" alt="" width="563"><figcaption></figcaption></figure></div>

Next, let's go to configuring the blocks in the builder.

## Working in the Chatbot builder

### Function get\_records\_from\_table()

To use the get\_info\_from\_table() function, you need one block in the chatbot builder.&#x20;

Go to the appropriate tab in Mavibot and create a block with a trigger (Start block or Trigger block):

<div data-with-frame="true"><figure><img src="/files/OGFJjnX7uByraYvPXfuj" alt=""><figcaption></figcaption></figure></div>

Define a variable (it will be used for the AI assistant's knowledge): in this example, the variable is 'record'.

Example of code from the Calculator

<mark style="color:green;">`project.`</mark><mark style="color:red;">`record`</mark>` ``=`` `<mark style="color:orange;">`get_records_from_table`</mark>`(1)`

1. <mark style="color:green;">`project. - is a constructor for setting a variable in the project configuration;`</mark>
2. <mark style="color:red;">`record - name variable;`</mark>
3. <mark style="color:orange;">`get_records_from_table`</mark>`(1) - function, where the parameter is passed as table ID.`&#x20;

<details>

<summary>Read more about the get_record_from_table() function</summary>

`get_records_from_table(table_id, start_row, count, start_col, end_col)` – to get records from a table

| Parameter       | Description                                                            | Note                                                                                                                      |
| --------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **!** table\_id | table ID (required parameter)                                          |                                                                                                                           |
| start\_row      | optional parameter, integer. Specifies the starting row of the range   | accepts the row number from which to start reading the table values, inclusive. Must be specified without quotation marks |
| count           | optional parameter, integer. Specifies the number of rows to retrieve  | default value: 1000. Maximum: 5000. Must be specified without quotation marks                                             |
| start\_col      | optional parameter, string. Specifies the starting column of the range | accepts the column name from which to start reading the table values, inclusive. Must be specified in quotation marks     |
| end\_col        | optional parameter, string. Specifies the end column of the range      | accepts the column name up to which to read the table values, inclusive. Must be specified in quotation marks             |

**To read all data from a certain point:** Specify only the **start** of the range. **To read all data up to a certain point:** Specify only the **end** of the range.

</details>

Instead of #{none}, we will write our variable in the message using the #{} construct to visually see what data has been written to the project variable.

<div data-with-frame="true"><figure><img src="/files/H136OlQaXvAFblbl8bEV" alt=""><figcaption></figcaption></figure></div>

{% hint style="warning" %}

## Attention

The variable embedded in the message is needed to check whether the bot reads the function correctly.                                                                                                                                                            When you run the block in test mode, the bot will display the values that will be assigned to the variable.
{% endhint %}

{% hint style="success" %}

## Please note

After configuring the block call in test mode and saving the variable in the project settings, do not delete this block.&#x20;

You may need it: for example, if you have added any more values to the table, just launch the block in test mode. Then the data in the project variable will be updated.
{% endhint %}

{% hint style="info" %}
The variable name can be any name that you like.
{% endhint %}

### Data transfer block&#x20;

Next, we will create "Chat" block for transferring data to the client's card.

<div data-with-frame="true"><figure><img src="/files/gCD5WWQhF9fYWLAXJFnp" alt=""><figcaption></figcaption></figure></div>

"This block can also transmit a closing message from the bot, such as: 'I’m passing the information to the manager! The manager will connect within 10 minutes.'"

Next, copy the block ID. You will need it to configure the AI assistant in the "start\_block\_from\_ai 11956" command and the test "Block call 11956" command, where instead of the <mark style="color:red;">block ID</mark> from the example, you need to insert your block ID.

{% hint style="success" %}

## Please note

After testing, replace "Block call <mark style="color:red;">31241050</mark>" with the command "start\_block\_from\_ai <mark style="color:red;">31241050"</mark>.

The command "Block call <mark style="color:red;">31241050</mark>" is debugging and helps to understand what data the bot is recording (see the section "Testing").

To launch the bot for clients, specify the command "start\_block\_from\_ai <mark style="color:red;">31241050</mark>".
{% endhint %}

### Reading a table

1. Navigate to **bot testing** mode.
2. Launch the block that contains the trigger for reading the table data.

<div data-with-frame="true"><figure><img src="/files/zxe5isLKvMpfEfp58ACt" alt="" width="563"><figcaption></figcaption></figure></div>

The block has worked correctly. You can see this confirmed by the values now stored in the corresponding variable within your project settings.

**To verify manually:**

1. Go to the **Project settings** section.
2. Locate the variable to view its current data.

<div data-with-frame="true"><figure><img src="/files/5WanV6jPiSz3yKgsoADs" alt="" width="563"><figcaption></figcaption></figure></div>

In the "Variables" tab in the project settings, you will see your variable with the values added in it from the table. So now, inside your project, there is a variable with goods, cost, and everything that you specified in the table.

## Working in AI assistant

Go to the "AI assistant" section and start chatbot with AI settings.

You need to choose the "Sales assistant" role:

<div data-with-frame="true"><figure><img src="/files/tRwOLH1M7goNEuSsTc9v" alt=""><figcaption></figcaption></figure></div>

We will also set additional settings:

<div data-with-frame="true"><figure><img src="/files/axPLKHlXSRqJRTp2G8pz" alt="" width="563"><figcaption></figcaption></figure></div>

### &#x20;AI assistant settings

In the bot settings write the following data:

1. The position and instructions for the bot.

<div data-with-frame="true"><figure><img src="/files/DSdS3s5Ot7oXJa3DIya5" alt="" width="563"><figcaption></figcaption></figure></div>

2. The command to call the block and transfer variables to the system is written as follows:

`"If everything is correct, execute the command "start_block_from_ai 11956"`, where instead of N the block ID is written with the final message: the Chat block transmits data to the customer's card:

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

### Bot knowledge

In the "Bot Knowledge" field, pass the variable that was previously cached as a block with the trigger.

<div data-with-frame="true"><figure><img src="/files/ZsPkVQ0CRMqX0RmAgT1n" alt="" width="563"><figcaption></figcaption></figure></div>

Bot knowledge.

<div data-with-frame="true"><figure><img src="/files/61haxSfXpVOYGq0CQwss" alt=""><figcaption></figcaption></figure></div>

This way, the bot will take information from a variable in the project settings and advise your clients on the available product range.

### Data format

In the format of the transmitted data, you specify the data you are collecting yourself (for example, a product), then enter the phrase with the "key" and assign a value to the key.

`the client name with key client_name, the client phone number with key phone_number, the city and the address with key city_address, the chosen product with key product, the quantity of product with key quantity, the total order amount with key total_amount.`

<div data-with-frame="true"><figure><img src="/files/0tDAwbo0FfwOb3LD8dS7" alt=""><figcaption></figcaption></figure></div>

This way, when calling the block, variables will be passed to the client's card: then you can work with variables, for example, in the chatbot builder:

<div data-with-frame="true"><figure><img src="/files/YE5f4ryNZDxlALx2TLG1" alt="" width="563"><figcaption></figcaption></figure></div>

At this stage, the AI assistant setup is complete.&#x20;

The remaining parameters can be set at your discretion:

<div data-with-frame="true"><figure><img src="/files/SkHGBnLkE1XNkO4liMik" alt="" width="563"><figcaption></figcaption></figure></div>

## Testing a bot

"If you already have bots running, specify in the AI assistant's launch condition to start only in the testing window."

Step 1. Click on the trigger builder

<div data-with-frame="true"><figure><img src="/files/eEls8iWxdU9yDJvIWjCL" alt=""><figcaption></figcaption></figure></div>

Step 2. Select the tab with the test window and click "Add trigger":

<div data-with-frame="true"><figure><img src="/files/9p82NOFeidmypVOqAQeO" alt=""><figcaption></figcaption></figure></div>

Now, in the trigger condition, you will see the following value:

<div data-with-frame="true"><figure><img src="/files/Ev2Q41lUr0vaSlspvM4c" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
This way, the bot will run only in the test window and nowhere else.

After debugging the bot, remove this condition.
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/Xd3RxcUXTVj6j5AI9b7I" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/861twyzqg8Z5oi3LSAZg" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/R1hTVr4sk1tBSRbEYD6g" alt="" width="375"><figcaption></figcaption></figure></div>

This message is being sent in t[est mode due to the command "Block call <mark style="color:red;">**3124105**</mark>](/chatbot/ai/assistant.md#data-transfer-format)

<div data-with-frame="true"><figure><img src="/files/tmUjbX1JbAj9LlNz0iWK" alt="" width="375"><figcaption></figcaption></figure></div>

After testing and debugging the bot, write the command in the settings of the bot "start\_block\_from\_ai <mark style="color:red;">**31241050**</mark>".

{% hint style="success" %}
This approach empowers you to build **any type of online store** and leverage **any data values** stored within your table.

The only true limit is your imagination.
{% endhint %}


---

# 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/chatbot/ai/tables.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.
