Direct Request to the Model
answer = ai_request('request', question)
Example:
answer = ai_request('You are a polite flower shop consultant.', question)
The first argument is the instruction for the model: who it is and how it should respond.
question is a system variable that always contains the text of the customer’s latest message.

Please Note
In expressions, variables are written using their names only, without
#{}.The response is returned as plain text, so it can be sent directly to the customer or stored in a variable.
The method waits patiently for the model’s response, so even long-running requests, such as large schemas or lengthy texts, will be completed without interruption.
When you need structured data instead of free-form text, such as a category, a yes/no answer, or extracted fields, pass a response schema as the third argument.
You do not need to create schemas from scratch. Use a ready-made template and rename the fields as needed.
For classifying customer requests, determining sentiment, and similar tasks.
local result = ai_request('Determine the category of the request.', question, {
"type": "object",
"properties": {
"category": {
"type": "string",
"enum": ["complaint", "question", "order"]
}
},
"required": ["category"]
})
category = get(result, 'category')
The model will return exactly one of the values listed in enum and nothing else.


The example to copy:
local result = ai_request('Has the customer agreed to make the purchase?', question, {
"type": "object",
"properties": {
"agree": {
"type": "boolean"
}
},
"required": ["agree"]
})
agree = get(result, 'agree')

The example to copy:
local result = ai_request('Extract the name and phone number from the message.', question, {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
},
"required": ["name", "phone"]
})
client_name = get(result, 'name')
client_phone = get(result, 'phone')
-
"string"— text -
"number"— a number -
"boolean"—trueorfalse -
enum— a list of allowed values; the model cannot return anything outside this list -
required— a list of mandatory fields - Field names such as
category,name, andphonecan be chosen freely
The schema-based response is returned as a JSON string. Individual fields can be retrieved using the standard get() method.
Please Note
In the examples,
resultis declared usinglocal. This means the raw AI response will not be saved to the record; only the required fields will be stored there.
Reasoning Mode
Reasoning mode can be enabled using the fourth argument. In this mode, the model first thinks through the task and then provides an answer.
It is useful for complex requests involving analysis, calculations, or multi-step logic. The response will take noticeably longer, so reasoning mode is disabled by default.
answer = ai_request(
'Solve the customer’s problem and explain the solution.',
question,
'',
true
)
When no response schema is required, pass an empty string '' as the third argument, as shown in the example.
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:
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.
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:
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).
Read how to configure an AI bot for online booking was explained in the article of the same name.
Retrieving booking from table
get_records_from_table(table_id, start_row, count, start_col, end_col) - retrieving booking from table
| Parameter | Description | Note |
|---|---|---|
| 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.
