# Google Sheets for AI assistant

Thanks to a feature developed by the Mavibot team, the AI chatbot accurately interprets the values entered into the sheet and then saves them to a system variable in the project settings.

For example, you may need this for an AI assistant who will advise your customers on the available range of products in your online store, as well as to advertise your capabilities with a smart bot.

Exactly how to use a bot to read a Google sheet is up to you, and we, in turn, will show you how to create a sheet and configure the bot to work with it.

## Preparing google sheet

### Creation and filling

Open the sheet editor:

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

You need to fill in the rows with the column categories:

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

Since the AI can read data, it will use the function to write values from the sheet to a variable in the project settings, so we recommend adding concise and understandable column category names for your convenience and understanding of the bot's logic.

Next, specify the necessary names in the columns:

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

Let’s look at the "Unit of measure" column category:

<figure><img src="/files/qm8QRgI1nSxwyNAoMENm" alt="" width="252"><figcaption></figcaption></figure>

The unit of measure can include:

1. A quantitative indicator in the form of pieces/units (one unit of goods, two units of goods, one piece, etc.):

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

2. Единицы измерения величин: литры, килограммы, граммы, метры:

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

{% hint style="success" %}
The bot will perfectly understand what you meant and use the values embedded in the slots.
{% endhint %}

The final step in filling out the Google Sheet will be entering the price per unit of measure.

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

At this stage, the google sheet is complete.

### Access Settings

In order for the AI bot can take values from the sheet, you need to open the access settings:

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

Click on settings, and the following window will open:

<figure><img src="/files/BfFo1VYHGZg1QjJvK1qM" alt="" width="375"><figcaption></figcaption></figure>

Here you need to change the setting from "Access is restricted" to "Everyone who has a link":

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

### ID sheet

To work with the get\_info\_from\_table(!sheet\_id, number\_sheet, sheet\_json\_keys) function, we will need the sheet ID, since the function takes sheet\_id as a required parameter.

To get ID, just click on the address bar:

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

You will see a line with the page address:

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

From which we will need a set of symbols and letters, which is just the ID of the sheet:

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

This completes the work with the sheet and its configuration.

## Working in the funnel constructor

### Using the function get\_info\_from\_table()

In order to use the get\_info\_from\_table() function, you will need one block in the funnel constructor.

Go to the appropriate tab in Mavibot and create a primary condition verification block:

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

Instead of #{none}, we will write in the message a notification for the test mode after launching this block and a embedded variable through the #{} construct:

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

{% hint style="warning" %}
Pay attention!&#x20;

The variable embedded in the message is necessary to verify that the bot is reading the function.&#x20;

When running the block in testing mode, the bot will show the values that will be nested in the variable.
{% endhint %}

{% hint style="success" %}
Pay attention!

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

You may need it: for example, if you have added any more values to the table, just run 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 suits you.
{% endhint %}

Next, we need get\_info\_from\_table(sheet\_id, number\_sheet, sheet\_json\_keys) function, - a function which is designed to read data from a table.

<table><thead><tr><th width="248">параметры</th><th>описание </th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> sheet_id</td><td>id google-таблицы</td></tr><tr><td>number_sheet</td><td>Номер листа в таблице; по умолчанию = 1</td></tr><tr><td>sheet_json_keys </td><td>Необязательный параметр, ключ доступа к данным таблицы</td></tr></tbody></table>

Open the calculator and enter the ID of the table, enclosing it in a variable (for example, sheet):

<figure><img src="/files/JqjNpyS3czCskSBJj1u7" alt="" width="537"><figcaption></figcaption></figure>

Next, assign the variable specified in the block message and assign it a value in the form of the get\_info\_from\_table() function with the required parameter sheet\_id (instead of which insert the variable sheet, where is the table ID):

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

<mark style="color:red;">**Attention!**</mark> Before the product\_pay\_info variable in the calculator, write project. This is necessary in order for the VARIABLE and the VALUES from the table to be entered into the project settings (cached):

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

Now write any word/numbers in the block condition:

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

### Data transmission block

Next, create a second Status block:

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

This Status block will be needed to transfer variables to the client's card.

You can also send a final message from the bot in this block, for example, "Thank you for ordering! I'm sending the data to the communications manager!":

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

Next, copy the block ID - you will need it to configure AI assistant in the command "start\_block\_from\_ai 31241050", where instead of the ID from the example, you need to insert your block ID.

### Sheet reading

Now launch the block in the test version so that the chatbot reads the values from the sheet and puts them in your variable in the project settings:

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

Thus, the block worked out correctly: you see the values that you read and which are in the variable in the project settings.

You can verify this by going to the appropriate section:

<figure><img src="/files/7H7kdWsrNtA4kd4kh9uF" alt="" width="287"><figcaption></figcaption></figure>

Next, you will see your variable with the values embedded in it from the table:

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

So now, inside your project, there is a variable with goods, cost, and everything that you specified in the sheet.

## Working as AI assistant

Go to the "AI assistant" section and start configuring artificial intelligence.

Assistant role: salesperson

<figure><img src="/files/207vuX0w87aBYQBLwOQq" alt="" width="512"><figcaption></figcaption></figure>

We will also set the "Buttons" and "Step-by-step data entry" options:

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

We will need buttons for visually designed responses from the bot, as well as for the convenience of the client (then your user does not need to manually enter words in the dialog); step-by-step data entry is for the bot to survey the order being generated.

### AI Assistant Settings

In the settings of the bot we write the following data:

1. The position and instructions for the bot.

Example:

\<You're a store seller. "All the little things.\
Your task is to ask the client which product he wants to choose, how many units of the product, and then calculate the total cost of the product, equal to one unit of the product multiplied by the cost.

After you have interviewed the customer about his purchase, duplicate the order for him and ask "Is the order correct?">.

**Pay attention** on the line "Calculate the total cost of the product, equal to the unit of the product multiplied by the cost" - this line will display the final result of the cost of all selected categories by the client:

Example:

The client selected three kg of one product. The bot, in turn, calculates the total cost:

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

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

\<If the customer wrote "The order is correct" or "Correct", then write "start\_block\_from\_ai N">, where instead of N, the block ID is written with the final message: the Status block transmits data to the customer's card:

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

The commands in the AI assistant settings look like this:

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

### Bot knowledge

In the "Bot Knowledge" field, pass the variable that was previously cached by the condition's Primary Verification block:

<figure><img src="/files/4EyPBz9gX27tfRdvdzDm" alt=""><figcaption></figcaption></figure>

Bot Knowledge:

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

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:

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

#### Explanation

Line 1: "The format of the transmitted data: product with the product key, unit of measure with the thing key, price with the count key, the total cost of all selected products with the result key" - makes it clear to the bot what data and with what value needs to be transmitted to the system.

These variables will be displayed in the client's card:

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

2. If you need each product selected by the customer to be displayed separately, add a second line:

"If the customer has selected several products, then add the first product with the product1 key, the second product with the product2 key, the third product with the product3 key, and so on".

This completes the setup of the AI assistant.

The remaining parameters can be set at your discretion:

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

## Testing bot&#x20;

Use the condition constructor to add the bot's operation in the test window:

Step 1. Click on the condition constructor

<figure><img src="/files/3lJ3NP2s6ElbeDFbWHEB" alt=""><figcaption></figcaption></figure>

Step 2. Select the tab with the text box and click "Add":

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

Now, in the startup condition, you see the following value:

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

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

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

Now let's test bot:

1. Let's ask a security question to the bot about the product range:

<figure><img src="/files/jPUbuBWjFviUWGDDQq2c" alt="" width="375"><figcaption></figcaption></figure>

The bot showed an variety of products that were entered in the google sheet, capturing values from a variable contained in the project settings.

2. Next, we will select the product and talk to the smart bot:

<div><figure><img src="/files/nODW40qAi74MIciECMUL" alt="" width="375"><figcaption></figcaption></figure> <figure><img src="/files/TwmZyFaFJexxzwBD5ZF2" alt="" width="375"><figcaption></figcaption></figure></div>

3. Let's choose another product:

<figure><img src="/files/a23iAGSSs2HPa6nZgWGj" alt="" width="375"><figcaption></figcaption></figure>

The bot also displays correctly, showing the customer the product categories for later selection.

4. The customer selected several products and selected their quantity:

<div><figure><img src="/files/qB8zM4RbcwjOXbwtFPJ9" alt=""><figcaption></figcaption></figure> <figure><img src="/files/tPnCFtGCPYIu01vvWp5M" alt=""><figcaption></figcaption></figure></div>

The bot calculated the cost of the selected items and calculated the total cost.

5. Sending the data to the system:

<figure><img src="/files/04YVtAtwtlceuoVKA0Et" alt="" width="375"><figcaption></figcaption></figure>

Result: after the bot duplicated the order and the client replied that the order was correct, the chatbot, based on the settings, called the "Dialog status" block:

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

After that, the data generated by the bot in the dialogue with the client was sent to the client's card:

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

The bot worked everything out correctly.

{% hint style="success" %}
This way you can create an online store of any kind and use any necessary values inside the table.

The main limitation - is only your imagination!
{% endhint %}

## Video Guide

{% embed url="<https://youtu.be/LTEmRgbRp8M>" %}


---

# 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/google-sheets-for-ai-assistant.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.
