# Functions (API) in the calculator

{% hint style="warning" %}
API functions are available only on "Business" and  "MaviBot AI"plans.
{% endhint %}

## API MaviBot

<mark style="color:red;">**LEGEND:**</mark>\ <mark style="color:red;">**!**</mark> -Required parameters

### How to send callback

#### **callback()**

{% hint style="danger" %}
You can sent callback only to ANOTHER client.

YOU CAN'T send a callback to YOURSELF!
{% endhint %}

<details>

<summary>Description</summary>

**callback(client\_id, callback\_message)**

Parameters:

<mark style="color:red;">**!**</mark>**&#x20;client\_id** - client identifier

<mark style="color:red;">**!**</mark>**&#x20;callback\_message** - callback message text

</details>

<details>

<summary>Example</summary>

A callback is a special system message that the bot recognizes as a command to trigger a specific action. This message is invisible to the user and is only logged within the client's profile for internal processing.

Let's send callback to client with client\_id=73704021

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

Next, we set the response to this callback in the block with the condition.

</details>

<details>

<summary>Code example to copy</summary>

```
callback('73704021', 'callback TEST123')

callback(client_id, 'callback TEST123')
```

</details>

### How to send callback in Telegram

#### **tg\_callback()**

<details>

<summary>Description</summary>

**tg\_callback(platform\_id , callback\_message,group\_id, business\_connection\_id)**

Parameteres:

<mark style="color:red;">**!**</mark>**&#x20;platform\_id** -  Telegram client identifier

<mark style="color:red;">**!**</mark>**&#x20;callback\_message** - callback message text

&#x20;**group\_id** -  Telegram bot identifier

**tg\_business -** for working with business clients, the value "1" is passed.

</details>

<details>

<summary>Example</summary>

This is example with the required parameters:

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

This is example with the optional parametrs

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

</details>

<details>

<summary>Code example to copy</summary>

```
tg_callback('73704021', 'callback TEST123')

tg_callback(platform_id, 'callback TEST123', None, 1)
```

</details>

### How to add a bot redirect with a tag in response to a callback button?

<details>

<summary>Description</summary>

**tg\_callback\_url\_open(callback\_query\_id, url)**

Parameteres: \ <mark style="color:red;">**!**</mark>**&#x20;callback\_query\_id** - this id allows you to identify the person who pressed the button and show them Alert -notification,\ <mark style="color:red;">**!**</mark>**&#x20;url** - URL- specifying the bot and the parameter (looks like: t.me/your\_bot?start=XXXX, instead of your\_bot - bot name)

</details>

### **How to send message to the client**

**message() | platform\_message() | whatsapp\_message()**

{% hint style="info" %}
To store text with line breaks in a variable, set the value as follows:

`text = "First line text" + "\n" + "Second line text" + "\n" +"Third line text"`
{% endhint %}

<details>

<summary>Description</summary>

**message(client\_id, text, message\_id, timeout)**

Parameteres:\ <mark style="color:red;">**!**</mark>**&#x20;client\_id** - client identifier\ <mark style="color:red;">**!**</mark>**&#x20;text** - message text\
**message\_id** - the block ID. If you leave the text field empty (") and fill in this parameter, the text from the specified block will be sent to the client.

*Note: If you pass the message\_id parameter to the message function, the block will still be fully executed, and the client specified in the client\_id parameter will be moved to the block you passed in message\_id.*

\
**timeout** - message delay or scheduled send time. You can use the timeout parameter to delay message sending:\
a) A delay in seconds (up to 3600 seconds). If the value exceeds 3600, the message will be sent in one hour. If the value is negative, the message will be sent immediately. Example: timeout = 50                                                                                                                 &#x20;

b) A specific date and time in the format dd.mm.yyyy hh:mm, example: timeout = '03.04.2022 15:00' . If a past date is specified, the message will be sent immediately.

**platform\_message(platform\_id, text, client\_type,  message\_id, timeout,group\_id)**

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;platform\_id** -  client identifier in messenger\ <mark style="color:red;">**!**</mark>**&#x20;text** - message text\
**client\_type -** messenger type, optional parameter. If it is not specified, the client will be searched in the same messenger from which the bot sends the message. If it is specified, the client will be found among the database of the specified messenger. You can find messenger types [here.](/chatbot/functions/variables.md#how-to-work-with-variables)\
**message\_id** - block ID. If it is specified, the client will receive the message from the specified block, not the value from the text parameter.\
**timeout** - sending time or delay. It is similar to the parameter of the message() function of the same name.\
**group\_id** - bot identifier

**whatsapp\_message(phone, text, message\_id)**

Parameters:\ <mark style="color:red;">**!**</mark>**&#x20;phone**- the customer's phone number where Whatsapp is registered\ <mark style="color:red;">**!**</mark>**&#x20;text** - message text\
**message\_id** -is the block ID. If the text field is left empty ('') and this parameter is set, the client will receive the message content from the specified block.

{% hint style="info" %}
Whatsapp bot need to be connected to the project.
{% endhint %}

</details>

<details>

<summary>Example</summary>

A simple example of sending a message by client\_id:

<div data-with-frame="true"><figure><img src="/files/qF9zmOuj7hDMSDEzomJr" alt="" width="563"><figcaption><p>Sending a message by client_id</p></figcaption></figure></div>

Different options for sending a message by client\_id:

<div data-with-frame="true"><figure><img src="/files/2v8T6btSFG3YgiBPVJu8" alt="" width="563"><figcaption><p>Different options for sending a message </p></figcaption></figure></div>

Example of sending a message via platform\_message():

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

</details>

<details>

<summary>Code example to copy</summary>

```
/*Sending a message by  client_id*/
message(73704021, 'Message text for client')
/*Sending a message by client_id with a delay of 30 seconds*/
message(73704021, 'Hi! Thanks for writing..','',30)
/*Sending a message from block 3190 by client_id 03.04.2022 at 3pm*/
message(73704021, '',3190, '03.04.2022 3pm')

/*Sending message in Whatsapp*/
whatsapp_message('79999999999', 'Message text for the client')
```

</details>

### Getting client\_id by platform\_id value

get\_client\_id\_by\_platform\_i&#x64;**()**

<details>

<summary>Description</summary>

**get\_client\_id\_by\_platform\_id(client\_type, platform\_id , group)**&#x20;

After executing, the function will return the client\_id if a client matching the specified conditions is found; otherwise, it will return None.

<mark style="color:red;">**!**</mark> **client\_type** - messenger.  For client\_type value read [this article](/chatbot/functions/variables.md).&#x20;

<mark style="color:red;">**!**</mark> **platform\_id** - client's ID in the specified messenger.

**group**  - is a required parameter if more than one messenger bot is connected.

{% hint style="warning" %}
If several messengers of the same type are connected in the project, then the search will be based on all connected messengers of this type.

In this case, we recommend passing the group parameter.
{% endhint %}

</details>

### Function for get-requests:  requests\_get(url, answer\_type, headers, params, auth, proxy)&#x20;

<details>

<summary>Description</summary>

<mark style="color:red;">**!**</mark>**&#x20;url** - is a link where the request is made

**answer\_type**  – is optional parameter that defines what should be returned from the server response: ('status' – returns the response status code; 'json' – returns the json body of the response; 'text' – returns the raw text of the response any other value (including the default) returns a response in the format: '{"status": status\_code, "data": data}')

**headers** - is optional parameter for passing request headers,&#x20;

**params** - is *get* request parameters (can also be included directly in the URL),

**auth** - is optional parameter useful for API authentication. If you don’t want to use any optional parameter but need the next one, pass 0 here.

**proxy** -  is optional parameter; accepts one value: "de", which routes the request through  European IP address.

</details>

### Functions for pos requests

<details>

<summary>Description</summary>

requests\_post(url, answer\_type, headers, data, json\_data, auth, proxy)

<mark style="color:red;">**!**</mark>**&#x20;url** - is a link where the request is made,

**answer\_type** - is optional parameter that defines what should be returned from the server response: ('status' – returns the response status code; 'json' – returns the json body of the response; 'text' – returns the raw text of the response any other value (including the default) returns a response in the format: '{"status": status\_code, "data": data}')

**headers** - is optional parameter for passing request headers

**data** - is optional parameter; represents the request body when the API does not work with json.

&#x20;**json\_data** - is optional parameter; also represents the request body. You should use only one of these parameters at a time.

{% hint style="warning" %}
Please note: certain header configurations may block the request from being sent with a specific type of body.
{% endhint %}

**auth** - is optional parameter useful for API authentication. If you don’t want to use any optional parameter but need the next one, pass 0 here

**proxy** - is optional parameter; accepts one value: "de", which routes the request through  European IP address.

</details>

### Functions for put-requests

<details>

<summary>Description</summary>

requests\_put(url, answer\_type, headers, data, auth, proxy)

<mark style="color:red;">**!**</mark>**&#x20;url** - is a link where the request is made

**answer\_type** - is optional parameter that defines what should be returned from the server response: ('status' – returns the response status code; 'json' – returns the json body of the response; 'text' – returns the raw text of the response any other value (including the default) returns a response in the format: '{"status": status\_code, "data": data}')

**headers** - is optional parameter for passing request headers

**data** - is optional parameter; represents the request body when the API does not work with json.

**auth** - is optional parameter useful for API authentication. If you don’t want to use any optional parameter but need the next one, pass 0 here

proxy - is optional parameter; accepts one value: "de", which routes the request through European IP address.

**data\_is\_json** is an optional parameter.\
If set, the data passed in `data` will be sent in JSON format.\
To enable it, pass `'1'`.

</details>

### Functions for patch-requests

requests\_patch(url, answer\_type, headers, data, auth, proxy)

<details>

<summary>Description</summary>

<mark style="color:red;">**!**</mark>**&#x20;url** - is a link where the request is made

**answer\_type** - is optional parameter that defines what should be returned from the server response: ('status' – returns the response status code; 'json' – returns the json body of the response; 'text' – returns the raw text of the response any other value (including the default) returns a response in the format: '{"status": status\_code, "data": data}')

**headers** - is optional parameter for passing request headers

**data** - is optional parameter; represents the request body when the API does not work with json.

**auth** - is optional parameter useful for API authentication. If you don’t want to use any optional parameter but need the next one, pass 0 here

proxy - is optional parameter; accepts one value: "de", which routes the request through  European IP address.

</details>

### Functions for delete requests

requests\_delete(url, answer\_type, headers, data, json\_data, auth, proxy)

<details>

<summary>Description</summary>

<mark style="color:red;">**!**</mark>**&#x20;url** - is a link where the request is made

**answer\_type** - is optional parameter that defines what should be returned from the server response: ('status' – returns the response status code; 'json' – returns the json body of the response; 'text' – returns the raw text of the response any other value (including the default) returns a response in the format: '{"status": status\_code, "data": data}')

**headers** - is optional parameter for passing request headers

data -  is optional parameter; represents the request body when the API does not work with json.

json\_data - is optional and may also be used as the request body. However, only one option should be used at a time

auth - is optional parameter useful for API authentication. If you don’t want to use any optional parameter but need the next one, pass 0 here

proxy - is optional parameter; accepts one value: "de", which routes the request through  European IP address.

</details>

### Function for getting block name by its ID

<details>

<summary>Description</summary>

get\_block\_name\_by\_id(block\_id)

<mark style="color:red;">**!**</mark>**&#x20;block\_id** — block identifier (id)&#x20;

</details>


---

# 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/functions/api.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.
