Working with MaviBot tables
Create a new record in the table with the specified values
Create a new record in a table with the specified values.
new_record(table_id, data)
table_id
table ID
data
a dictionary with the data to be recorded. Example: {"column_name1": "value1", "column_name2": "value2"}. If the column does not exist, it is created.
Response: new record ID
Example

Edit an existing record in the table
edit_record(table_id, record_id, data)
table_id
table ID
record_id
edited record ID
data
a dictionary with the data to be edited. Example: {"column_name1": "value3", "column_name2": "value4"}. If the column does not exist, it is NOT created.
Response:
Returns the full data of the edited record in the format: {"column_name1": "value3", "column_name2": "value4"}.
Example

Delete a record from the table by its ID
delete_record(table_id, record_id)
table_id
table ID
record_id
deleted record ID
Response:
{'message': 'Deleted records: 1'}
Find a record in the table by the specified value
find_record(table_id, value, find_in, return_from)
table_id
table ID
value
the value to match
find_in -
optional parameter. The name of the column to search by. If not specified, the search will be performed across all columns.
return_from
optional parameter. The name of the column from which to return the value.
Response:
If return_from is specified, the value from the specified column (if it exists in the table) will be returned. If return_from is not specified or the column does not exist, the full data of the found record will be returned in the response, for example: {"column_name1": "value3", "column_name2": "value4"}.
Example

Retrieving a value from the specified record
get_record_data(table_id, record_id)
table_id
table ID
record_id
record ID from which the values are retrieved
return_column
optional parameter. The name of the column from which the value should be returned.
Response: If a record is found, a dictionary like {"column_name1": "value1", "column_name2": "value2"} is returned. If the return_column parameter is provided and such a column exists, only the value from that column will be returned.
Where can I find a table ID?

To work with chatbot functions, you'll need the table ID. Find the desired table in the list and click on it.

Next, click the address bar.
In the address bar, you will see a URL like https://salebot.pro/projects/11111/table/2, where you can find the ID of the desired table:

Retrieving a record from the table
get_records_from_table(table_id, start_row, count, start_col, end_col) - retrieving a record from the table.
table_id
table ID
start_row
Optional parameter, an integer. Specifies the start of the row range.
The row number to start reading from (inclusive). Write it without quotation marks.
count
Optional parameter, an integer. Specifies the number of rows to retrieve.
By default, the value is 1000, with a maximum of 5000. Specify without quotation marks.
start_col
Optional parameter, a string. Specifies the start of the column range.
The name of the column to start reading from (inclusive). Write it in quotation marks.
end_col
Optional parameter, a string. Specifies the end of the column range.
The name of the column to read up table values to (inclusive). Write it in quotation marks.
If you specify only the start of the row or column range, all data from that point on will be returned. You can also leave out the start and specify only the end to get data up to that point.
Example
In the block where you need to retrieve records from the table, go to the "Calculator" section in the block settings and enter the function with the required parameters.
Let's see how the data is displayed in the table.


Now, execute the "Start" block in test mode.

We can see the data that was written to the variable from the table in the message sent by the bot. Because we referenced the variable in the message using the #{} syntax, the data stored in it was displayed in the bot chat.

Retrieve data from the table within a specified range
table_read_cells(table_id, cell_data) - allows retrieving data from the table by specifying ranges.
! table_id
required parameter, table ID
! cell_data
required parameter, a dictionary with ranges.
cell_data example: '{"a1":"a1", "a3": "b4", "c1": "c3"}'
If no issues occurred during the request, the response will be a dictionary containing the status and all cells with their values:
{"status": true, "A1": "value", "A3": "value", "B3": "value", "A4": "value", "B4": "value", "C1": "", "C2": "value", "C3": "ddddddd"or, in case of an error: {"status": false, "err": "Error message or description"}
Example in the Calculator
For example, the table cells contain the following specified values:

To retrieve data from the table via the bot, pass the required ranges to the functions in the Calculator.

In the example, the construct #{res}, which holds a variable, helps display in the message the data retrieved using the function and the specified range:

If the column names are different (e.g., "Product", "Number", "Amount"), you must specify the range using the format {"Product1":"Amount3"}, where:
• Product is the name of the first column • 1 indicates it's column number 1 • Amount is the name of the third column • 3 indicates it's column number 3



Last updated