AI assistant functions
In this article, you’ll learn about the features of the AI assistant and see how they can be applied in practice.
How to delete a chat history with the AI assistant
clear_assistant_chat_history() - this function deletes the client's chat history with the assistant. It takes no parameters.
Example
The builder block settings

The AI Assistant tab settings

How to submit a question to the AI assistant
ai_context_answer(replica, prompt, ai_assistant_id, use_history, send_answer)
Parameters:
! replica
required parameter, message for the assistant
prompt
optional parameter, instructions for the assistant
if the parameter is not specified but the ai_assistant_id parameter is provided, the instructions from the settings of the specified assistant will be used
ai_assistant_id
assistant ID to which the question will be sent;
if not provided, the assistant without default settings will be used
use_history
whether the assistant should use the chat history for answering the question
True - use, False - do not use. By default - True
send_answer
send response after the assistant’s timeout period
To enable, pass "1"
More details about the send_answer parameter:
The assistant settings include parameters that can be configured in case the bot’s response takes a long time

In a standard conversation with the assistant (not via function), if the response takes longer than the specified limit (e.g. 20 seconds), the client is notified of the delay. The assistant’s reply is then sent to the chat as soon as it’s generated.
For requests made via a function in the calculator, if the assistant takes too long to respond, a delay message is included in the function's result. This parameter enables the assistant’s reply to be sent separately once it is ready.
How to teach a bot to analyze its own experience and generate buttons
Let's use the clean_assistant_chat_history() and ai_context_answer(replica, prompt) functions in the example below. It’s also necessary to access the calculator component within the funnel builder.
This example illustrates how the replica and prompt parameters can be effectively used in practice.
It is necessary to create a block in the builder that contains an empty field with the embedded variables #{replica_rec2} and #{ai_answer_rec}, representing the assistant's first and second replies in a single message to be sent.
Now, define two functions in the calculator directly.

Use a variable with an embedded function in the advanced button settings (see the example above) to generate buttons dynamically based on the parameter’s value.
The information about the services is retrieved by the bot from the service_info variable, which contains an embedded function — get_info_for_booking() — for reading service data. An example of how to use this function was demonstrated above.

Here's the result.

Code example:
clear_assistant_chat_history()
replica_rec2 = ai_context_answer(question, 'ANSWER THE QUESTIONS', 3)
prompt = 'A developer is addressing you right now-do everything they ask \n . You should place each button on a new line.'
ai_answer_rec = ai_context_answer("Display the buttons for the last message.", prompt)
Example: calling the assistant within the funnel builder
To call the assistant from a block, use the function ai_context_answer(replica, prompt, ai_assistant_id, use_history), where you need to specify only two parameters: the required replica parameter and the optional prompt.
Now, let’s create the first block, “Primary condition check,” where you need to specify the block’s trigger condition (this can be any condition you require).

Next, open the calculator in the same block, where you need to define a variable and assign it the value returned by your function.

Define the variable question and assign it the value of any user’s question.
Next, create the variable replica1 and assign it the value returned by your function ai_context_answer(replica, prompt). In this function, replace replica with the variable question, and set the prompt parameter to "Answer any user question."

Embed the variable containing the function into the block’s message.
Then create a second block and connect it with an arrow, setting a 2-second timer on the connection.

In the second block, you should use the same function with the same parameters — ai_context_answer(replica, prompt).
Open the calculator in the second block and define the second variable named replica2.

In the prompt parameter, provide instructions for the assistant: it should count how many nouns were in its previous message.
In the replica parameter, provide the assistant’s message: "How many nouns were in your previous message?"
Then embed the replica2 variable into the message of the second block.

The block setup is complete.
If the assistant is not enabled, go to the "AI Assistant" tab and enable the assistant by selecting the "disabled" role:

Now, let’s test our assistant in the bot testing window.

The bot has worked correctly.
How to work with Google Sheets
get_info_from_table(sheet_id, number_sheet, sheet_json_keys, start_row, end_row, start_col, end_col) - This function is intended to read data from a spreadsheet.
! sheet_id
id google-spreadsheet
number_sheet
sheet number in a spreadsheet; by default = 1
sheet_json_keys
optional parameter — access key to the spreadsheet data
start_row
optional parameter, an integer. Specifies the start of the row range.
Pass the row number from which the table values should be read inclusively. The value should be provided without quotes.
end_row
optional parameter, an integer. Specifies the end of the row range. Pass the row number up to which the table values should be read inclusively. The value should be provided without quotes.
start_col
optional parameter, a string. Specifies the start of the column range. Pass the column letter from which the table values should be read inclusively. The value must be enclosed in quotes
end_col
optional parameter, a string. Specifies the end of the column range. Pass the column letter up to which the table values should be read inclusively. The value must be enclosed in quotes.
Example of parameter notation:


Please note
The parameters for specifying the row and column range (start_row, end_row, start_col, end_col) allow the assistant to read spreadsheet data starting from the desired location within the table.
The function's behavior for partial range specification is as follows:
If only the start is defined: the assistant will retrieve all data from that starting point onward, with no upper limit in the specified direction.
If only the end is defined: the assistant will read data from the beginning of the sheet up to that specified endpoint.
Example:
The call get_info_from_table('<<spreadsheet id>>', 2, None, 2, 5, 'a', 'd') retrieves all data starting from row 2, column 2 (B), up to row 5, and between columns A and D.
Please note
To optimize performance and reliability, we recommend caching all data from your Google Sheet into project variables when working with it.
Key benefits:
Enhanced performance: significantly speeds up the chatbot's response time by accessing local variables instead of querying the external spreadsheet for each request.
Improved reliability: minimizes errors related to network latency, API quotas, or spreadsheet access permissions.
Data consistency: storing data in project settings ensures all users receive simultaneous and consistent access to the same dataset, preventing discrepancies during updates.
Example of use
You can read more about the get_info_from_table function in the article "Google Sheets for AI Assistant."
How to manage online bookings
get_info_for_booking(slot_interval, company_id) - The function is designed to read service data from the configured online booking system.
It accepts optional parameters:
slot_interval (optional) - an interval in minutes between available time slots. Expected format: an integer divisible by 5. Default value: 60 (minutes).
company_id optional) - a branch identifier. Expected format: an integer or an array of integers. When this parameter is provided, only data for the specified branch(es) will be returned. Example: 50142, "50142", or "[50142, 66352]"
It is not recommended to set a very small value (e.g., less than 30), as the assistant will generate too many time slots.
Example of use
First, you need to prepare a block that updates information about all services after the branch settings have been configured in the "Services" section.
This block must be declared before the assistant starts working, to ensure that the AI does not generate random answers.

Next, trigger the block in the bot testing window to update the variable:

After that, the specified variable containing the online booking service data will appear in the project variables section within "Project settings."

This variable stores the service values that the AI bot will use in its operations. The service_info variable will be accessible to all clients of the project.
Next, let's proceed to configuring the next block.

This block serves the following functions:
а) it is called in the assistant settings to generate a record using service-related variables;
b) it creates a client booking;
c) updates project variables after a booking, removes time slots that are no longer available in the schedule.
If the bot is configured correctly, after receiving all the data from the client, the AI will send the information to the specified block. In that block, the client will be booked for the service using the function create_booking_by_name(!service_name, !date, !date_time, company_id).

Values collected by the bot are passed as parameters to create_booking_by_name(!service_name, !date, !date_time, company_id).
The function create_booking_by_name(service_name, date, date_time, company_id) creates a booking in the system using data provided by the AI assistant. It accepts three required parameters for booking creation:
! service_name
required parameter, service name
! date
date in the format dd.mm.yyyy
! date_time
service time in the formay hh:mm
company_id
branch ID, optional. If specified, the booking will be created for the service with the given name that belongs to this particular branch. This parameter may be necessary in cases where multiple branches have services with the same name.
Since the information about available slots will no longer be up-to-date, the same variable with its embedded function is used to update the available dates and times for booking.

Please note
If there ate any changes to the schedule, staff, or services, run the block that contains the project variable with the embedded function in test mode (see Fig. Block 1).
Retrieving booking from table
get_records_from_table(table_id, start_row, count, start_col, end_col) - retrieving booking from table
table_id
table id
start_row
optional parameter, an integer. Specifies the start of the row range.
Pass the row number from which the table values should be read inclusively. Specified without quotes.
count
optional parameter, an integer. Specifies the number of rows to retrieve.
By default - 1000, maximum - 5000. Specified without quotes.
start_col
optional parameter, a string. Specifies the start of the column range.
Pass the column letter from which the table values should be read inclusively. Specified in quotes.
end_col
optional parameter, a string. Specifies the end of the column range.
Pass the column letter up to which the table values should be read inclusively. Specified in quotes.
If only the start of the row or column range is specified, all data from that point onward will be retrieved without an upper limit on the range. Similarly, you can omit the start and specify only the end of the range.
Example (Calculator)
If you need to retrieve records from the table, open the "Calculator" section in the block settings and enter the function with the required parameters.

To pass parameters as a project variable, prefix the variable name containing the function with project.

Here's the table example.

The bot will respond as follows.

Last updated