# Telegram chat and messenger settings

**Working with platform IDs in MaviBot**

In MaviBot, all Telegram entities (users, groups, channels) are identified by a generic `platform_id` variable. This variable does not distinguish between entity types.

**Problem:** To use functions like `accept` or `reject` that require specific entity types, you need to know both the *chat* ID and the *user* ID separately.

**Solution:** When you receive a callback or message, immediately store the `platform_id` value in two distinct, purpose-named variables:

* **`chat_id`** – to store the ID of the group/channel.
* **`user_id`** – to store the ID of the individual user.

This allows you to reference the correct ID later in your application logic.

## How to change the chat name via Telegram bot

<details>

<summary>Description</summary>

**tg\_set\_group\_title(platform\_id, title)** -&#x20;

Parameters:

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>the chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a>  </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> title</strong></td><td>new chat name</td></tr></tbody></table>

</details>

## How to change chat description via Telegram bot

<details>

<summary>Description</summary>

**tg\_set\_chat\_description(platform\_id, description)**

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>the chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a>  </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> description</strong></td><td>new chat name</td></tr></tbody></table>

</details>

## How to set an avatar in a group/chat in Telegram

<details>

<summary>Description</summary>

**tg\_set\_chat\_photo(platform\_id, photo)**

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>,</strong> in which you want to set an avatar</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong>  photo</strong></td><td>link photo</td></tr></tbody></table>

</details>

## How to delete an avatar in a group/chat in Telegram

<details>

<summary>Description</summary>

**tg\_delete\_chat\_photo(platform\_id)**

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>,</strong> in which you need to set an avatar</td></tr></tbody></table>

</details>

## How to ban a Telegram group

<details>

<summary>Description</summary>

**tg\_ban\_chat\_sender\_chat(platform\_id, sender\_chat\_id)**&#x20;

Parameters:

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>, which you need to ban</strong></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> sender_chat_id</strong></td><td>chat ID which is going to ban</td></tr></tbody></table>

At the same time, the banned chat owner can't write on behalf of his /her other chats until he/ she is banned.

</details>

## How to unblock Telegram group

<details>

<summary>Description</summary>

**tg\_unban\_chat\_sender\_chat(platform\_id, sender\_chat\_id)**

Parameter:

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>,</strong> in which you unblock </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> sender_chat_id</strong></td><td>chat ID which you unblock </td></tr></tbody></table>

</details>

## How to create an invite link to join Telegram chat

<details>

<summary>Description</summary>

**tg\_create\_chat\_invite\_link(platform\_id, member\_limit, hours, request, name)**&#x20;

Parameter:

<table><thead><tr><th width="282.87109375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID in Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><strong>member_limit</strong></td><td>limit on the number of participants</td></tr><tr><td><strong>hours</strong></td><td>Link expiration time (in hours)</td></tr><tr><td><strong>request</strong></td><td>a parameter that after clicking on the link, a request to join the chat should be generated.</td></tr><tr><td><strong>name</strong> </td><td>link name</td></tr></tbody></table>

{% hint style="info" %}
When passing the **member\_limit** parameter, the value of the **request** parameter is automatically changed to **False**. If you need to accept applications for membership, then leave the **member\_limit** parameter empty.
{% endhint %}

**Creating chat invite link**

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

</details>

## How to delete chat invite link in Telegram

<details>

<summary>Description</summary>

**tg\_revoke\_chat\_invite\_link(platform\_id, invite\_link)**

Parameters:

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> invite_link</strong></td><td>link that you need to delete</td></tr></tbody></table>

</details>

## How to inactivate all existing links and replace them to one link&#x20;

<details>

<summary>Description</summary>

&#x20;**tg\_export\_chat\_link(platform\_id)**

Parameters:

<table><thead><tr><th width="294.828125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> invite_link</strong></td><td>link, that you need to delete</td></tr></tbody></table>

The result is - a link will be the only way to get into the group until additional links are created in other ways.

{% hint style="warning" %}
Use with caution. All existing login links to your group will become inactive.
{% endhint %}

</details>

## How to accept request and add user in Telegram channel/chat

<details>

<summary>Description</summary>

**tg\_approve\_chat\_join\_request(chat\_id, user\_id)**

Parameters:

<table><thead><tr><th width="279.9765625"></th><th></th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> chat_id</strong></td><td>group/channel ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>user ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr></tbody></table>

Request acceptance:

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

</details>

## How to decline request in Telegram channel/chat

<details>

<summary>Description</summary>

**tg\_decline\_chat\_join\_request(chat\_id, user\_id)**&#x20;

Parameters:

<table><thead><tr><th width="279.9765625"></th><th></th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> chat_id</strong></td><td>group/channel ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>user ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr></tbody></table>

Request declining

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

</details>

## How to block user in Telegram

<details>

<summary>Description</summary>

**tg\_ban\_chat\_member(chat\_id, user\_id, hours)**&#x20;

Parameters:

<table><thead><tr><th width="283.67578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> chat_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>user ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> for block</td></tr><tr><td><strong>hours</strong></td><td>Block duration in hours. By default, the block is permanent. If you specify a block duration of more than 366 days, the block will be set as permanent.</td></tr></tbody></table>

</details>

## How to unblock user in Telegram&#x20;

<details>

<summary>Description</summary>

**tg\_unban\_chat\_member(chat\_id, user\_id)** &#x20;

Parameters:

<table><thead><tr><th width="283.67578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> chat_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>user ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>,</strong>  who you need to unblock</td></tr></tbody></table>

</details>

## How to check subscription status in Telegram

<details>

<summary>Description</summary>

**tg\_get\_chat\_member(chat\_id, user\_id)**&#x20;

Parameters:

<table><thead><tr><th width="283.67578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> chat_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>user ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a><strong>,</strong> whose subscription we are checking</td></tr></tbody></table>

</details>

## How to determine the number of members in channel/chat&#x20;

<details>

<summary>Description</summary>

**tg\_get\_chat\_member\_count(platform\_id)**

Parameters:

<table><thead><tr><th width="283.67578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID in Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr></tbody></table>

</details>

## How to check if a chat member is in a specific list

<details>

<summary><strong>some_client_in_list(list_id, recepient)</strong></summary>

Parameters:

<table><thead><tr><th width="283.67578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> list_id</strong></td><td>list number</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> recepient</strong></td><td> user's ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a>. For chat clients, this value is in the chat_member_id variable.</td></tr></tbody></table>

</details>

## How to show bot's actions to the user (print/select a sticker and ect.)

<details>

<summary>Description</summary>

**tg\_send\_chat\_action(platform\_id, bot\_action,  message\_thread\_id)**

<mark style="background-color:green;">**! Work with Telegram business-account**</mark>

Parameters:

<table><thead><tr><th width="286.74609375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID in Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a>  </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> bot_action</strong></td><td>bot's action from the list</td></tr><tr><td><strong>message_thread_id</strong> </td><td>topic ID (available for supergroups if the forum functionality is available).</td></tr></tbody></table>

</details>

<details>

<summary><mark style="color:orange;">Available actions list <strong>bot_action</strong></mark></summary>

***typing*** for text messages, \
\&#xNAN;***upload\_photo*** for photos, \
\&#xNAN;***record\_video*** or ***upload\_video*** for videos , \
\&#xNAN;***record\_voice*** or ***upload\_voice*** for voice notes, \
\&#xNAN;***upload\_document*** for common documents, \
\&#xNAN;***choose\_sticker*** for stickers, \
\&#xNAN;***find\_location*** for location data, \
\&#xNAN;***record\_video\_note*** or ***upload\_video\_note*** for video note.&#x20;

</details>

{% hint style="info" %}
This notification will be displayed until any response is received from the bot, but no more than 5 seconds.
{% endhint %}

## How to show Alert-notification to the user

<details>

<summary>Description</summary>

**tg\_answer\_callback\_query(callback\_query\_id, text,show\_alert,cache\_time)**&#x20;

<table><thead><tr><th width="309.5234375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> callback_query_id</strong> <strong>(required)</strong></td><td>This ID allows you to identify the person who clicked the button and show him/her the Alert notification.</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> text (required)</strong> </td><td>Text of Alert-notification.</td></tr><tr><td><strong>show_alert</strong></td><td>Indication of disappearing notification (False — a fading tooltip-style notification, True — a persistent window notification)</td></tr><tr><td><strong>cache_time</strong></td><td>The maximum amount of time, in seconds, during which the result of a callback request can be cached on the client side. Telegram applications will support caching starting from version 3.14. The default value is 0</td></tr></tbody></table>

</details>

<details>

<summary>Example</summary>

Alert notifications are shown only as a result of clicking on the callback button in  Telegram.

\
For example, we use the following buttons:

\[{"line":0,"index\_in\_line":0,"text":"111","type":"inline","callback":"first"}, {"line":1,"index\_in\_line":0,"text":"222","type":"inline","callback":"second"}, {"line":2,"index\_in\_line":0,"text":"333","type":"inline","callback":"third"}]&#x20;

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

After clicking a button, a callback arrives with the text contained in the corresponding field. When you click on the “111” button, you will receive a callback with the text “first".

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

Let’s create a Start block and specify the desired text in the trigger. In our case: **"first**

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

If in the **Matches** field you select **Ignoring errors and inaccuracies**, this block can later be reused for all similar variants that differ by 1–2 characters. For example, to thank the user for providing a rating with such a button.

Next, in the calculator, use the **tg\_answer\_callback\_query** function and pass the following parameters:\
**callback\_query\_id** - this ID allows you to identify the user who pressed the button and display  Alert  - notification to them              \
**text** - text  Alert-notification.

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

Code example to copy:

`tg_answer_callback_query('#{callback_query_id}', "You pressed the button 111")`&#x20;

{% hint style="warning" %}
Pay attention! The callback\_query\_id  parameter should be passed exactly as shown in the example, i.e. inside  '#{}'
{% endhint %}

If everything is set up correctly, pressing the button will result in an Alert - notification with the specified text. In the mobile version, the bot’s name will appear as the header above the text.

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

If you want to show a simple **popup message** instead, pass **False** as the third parameter, as shown in the example below:\
tg\_answer\_callback\_query('#{callback\_query\_id}', "You passed the button 222", False)

<figure><img src="/files/dhuJihEDLUp6dvdGXv8B" alt="" width="563"><figcaption><p>When the button is pressed<br>with these parameters, a notification of this type<br>will appear for a few seconds.</p></figcaption></figure>

</details>

## Adding a bot redirect with a tag as a callback button responses

<details>

<summary>Description</summary>

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

Parameters:

<table><thead><tr><th width="309.5234375">Parameters</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> callback_query_id</strong></td><td>This ID allows you to identify the person who clicked the button and show him/her the Alert notification.</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> url</strong> </td><td>URL-pointing to the bot and a parameter (format: t.me/your_bot?start=XXXX, where your_bot - is bot's name)</td></tr><tr><td><strong>cache_time</strong></td><td>The maximum amount of time, in seconds, during which the result of a callback request can be cached on the client side. Telegram applications will support caching starting from version 3.14. The default value is 0</td></tr></tbody></table>

</details>

<details>

<summary>Example</summary>

ВIn the callback button response, you can add a transition to the bot using tag thetg\_callback\_url\_open('#{callback\_query\_id}', 't.me/bot\_name?start=XXXX')

For example, let’s use the following buttons:

\[{"line":0,"index\_in\_line":0,"text":"111","type":"inline","callback":"first"}, {"line":1,"index\_in\_line":0,"text":"222","type":"inline","callback":"second"}, {"line":2,"index\_in\_line":0,"text":"333","type":"inline","callback":"third"}]

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

After clicking a button, a callback arrives with the text contained in the corresponding field. When you click on the “111” button, you will receive a callback with the text “first".

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

Create a block with a primary condition check and specify the desired text in the condition. In our case: “first”:

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

If in the **Matching option** field you select **Ignore errors and inaccuracies**, this block can later be reused for all similar variants that differ by 1–2 characters. For example, to thank the user for providing a rating with such a button.

Next, in the block’s calculator, specify tg\_callback\_url\_open('#{callback\_query\_id}', 't.me/bot\_name?start=XXXX'):

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

</details>

## How to promote a user to administrator in a supergroup or channel

<details>

<summary>Description</summary>

**tg\_promote\_user(platform\_id, user\_id, promote\_options\_list)**

Parameters:

<table><thead><tr><th width="269.9765625">Parameter</th><th width="515.17578125">Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>the identifier of a supergroup or, if used in a channel, the channel username in the format @channelusername inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>the identifier of a user inside Telegram. <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> promote_options_list</strong></td><td>list of permissions to be enabled. </td></tr></tbody></table>

</details>

<details>

<summary><mark style="color:red;">Required parameter: <strong>promote_options_list</strong></mark></summary>

The following permissions can be specified in the **promote\_options\_list** :

1. **is\_anonymous** — пhides the administrator’s presence in the chat,&#x20;
2. **can\_manage\_chat** — the administrator can access the chat event log, chat statistics, message statistics in channels, view channel members, view anonymous administrators in supergroups, and bypass slow mode. This permission level is granted by default if any of the subsequent privileges are specified
3. **can\_post\_messages** — — the administrator can create channel posts <mark style="color:red;">(channels only)</mark>
4. **can\_edit\_messages** — the administrator can edit other users’ messages and pin messages <mark style="color:red;">(channels only)</mark>&#x20;
5. **can\_delete\_messages** — the administrator can delete other users’ messages
6. **can\_manage\_video\_chats** — he administrator can manage video chats,
7. **can\_restrict\_members** — the administrator can restrict members, ban/unban them in the chat,&#x20;
8. **can\_promote\_members** — the administrator can appoint new administrators with a subset of their own privileges, or demote administrators whom they have appointed directly or indirectly (e.g., administrators appointed by them)
9. **can\_change\_info** — the administrator can change the chat title, photo, and other settings
10. **can\_invite\_users** — the administrator can invite new users to the chat
11. **can\_pin\_messages** — the administrator can pin messages <mark style="color:red;">(supergroups only).</mark>

</details>

<details>

<summary>Example</summary>

Example: Promoting a user to administrator in a supergroup:

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

In this example, in addition to the specified permissions, the can\_manage\_chat permission will be granted by default.

<div data-with-frame="true"><figure><img src="/files/XDOd8cCBEoPHvbRs5lbm" alt="" width="563"><figcaption><p>Assigning permissions to a user</p></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/04xSDpIVmwmF5pRTuMCe" alt="" width="563"><figcaption><p>Setting a custom administrator title</p></figcaption></figure></div>

Code example to copy

<pre data-full-width="false"><code><strong>Example 1. 
</strong><strong>promote_options_list = ‘[“can_promote_members”,”can_change_info”,”can_invite_users”]’ 
</strong>tg_promote_user(platform_id, user_id, promote_options_list)

Example 2. 
promote_options_list = '["can_manage_chat","can_post_messages","can_edit_messages","can_delete_messages","can_manage_video_chats","can_promote_members","can_restrict_members","can_invite_users","can_pin_messages"]' 
result=tg_promote_user(platform_id, reply_from, promote_options_list)  
</code></pre>

</details>

## How to change an administrator title using a bot in Telegram

<details>

<summary>Description</summary>

**tg\_set\_administrator\_title(platform\_id, user\_id, title)** &#x20;

Parameters:&#x20;

<table><thead><tr><th width="303.94921875">Parameter</th><th>Descroption</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>identifier of the supergroup inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> user_id</strong></td><td>identifier of the user inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a>  </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> title</strong></td><td><p>administrator title</p><p>Restrictions for title:</p><p>Length: 0–16 characters, emojis are not allowed</p></td></tr></tbody></table>

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

This works only for users who were promoted to administrators in the supergroup by the bot
{% endhint %}

Code example to copy:

```
result=tg_set_administrator_title(platform_id, reply_from, "firetitle")
```

</details>

## General restrictions for regural chat members or specific Telegram users

<details>

<summary>Description</summary>

**tg\_chat\_permission(platform\_id, permission, media\_permissions)**

Parameters:

<table><thead><tr><th width="318.76171875">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>identifier of the chat inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> permission</strong></td><td><p>an array of values from the restriction list (see below).</p><p>1 = action is allowed</p><p>0 = action is forbidden</p><p>Array index corresponds to the position in the restriction lis</p></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> media_permissions</strong></td><td><p>an array of values defining media-related permissions (details below).</p><p>1 = action is allowed</p><p>0 = action is forbidden</p><p>Array index corresponds to the position in the media permission list</p></td></tr></tbody></table>

</details>

<details>

<summary><strong>List of restrictions for the required parameter </strong><mark style="color:red;"><strong>permission</strong></mark></summary>

**List of restrictions for** **permission:**\
1\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_messages** - permission to send text messages, contacts, locations, and venues.\
2\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_media\_messages** - permission to send audio, documents, photos, videos, video notes, and voice notes. It requires **can\_send\_messages**\
3\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_polls** - permission to send polls. It requires **can\_send\_messages**\
4\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_other\_messages** - permission to send animations, games, stickers, and to use inline bots. It requires **can\_send\_media\_messages**\
5\. <mark style="color:red;">**!**</mark>**&#x20;can\_add\_web\_page\_previews** - permission to add web-page previews to messages. It requires **can\_send\_media\_messages**\
6\. <mark style="color:red;">**!**</mark>**&#x20;can\_change\_info** - permission to change the chat title, photo, and other settings. This is ignored in public supergroups.\
7\. <mark style="color:red;">**!**</mark>**&#x20;can\_invite\_users** - permission to invite users\
8\. <mark style="color:red;">**!**</mark>**&#x20;can\_pin\_messages** - permission to pin messages. This is ignored in public supergroups.\
9\. **can\_manage\_topics** - permission to create topics in forum groups. If used in a group of the wrong type, the function will fail and return an error.

</details>

<details>

<summary><strong>List of values for the required parameter </strong><mark style="color:red;"><strong>media_permissions</strong></mark></summary>

#### Values for granting media-related permissions **media\_permissions:**&#x20;

1\. **can\_send\_audios** - permission to send audio files\
2\. **can\_send\_documents** -permission to send documents\
3\. **can\_send\_photos** - permission to send photos\
4\. **can\_send\_videos**  - permission to send videos\
5\. **can\_send\_video\_notes** - permission to send round video messages\
6\. **can\_send\_voice\_notes** - permission to send voice messagesя

</details>

## Telegram Personal restrictions for regular chat users or for specific Telegram users

<details>

<summary>Description</summary>

**tg\_restrict\_chat\_member(platform\_id, user\_id, minutes, permission, media\_permissions).**

Parameters:

| Parameter                                                   | Description                                                                                                                                                                                                   |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">**!**</mark>**&#x20;platform\_id** | chat ID in Telegram [**\***](#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii)                                                                                                                                |
| <mark style="color:red;">**!**</mark>**&#x20;user\_id**     | user ID in Telegram [**\***](#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii)                                                                                                                                |
| **minutes**                                                 | the number of minutes during which the restriction will stay active. If you do not set a value, the default is **3600**, which equals **60 hours**. If you set it to **0**, the restriction becomes permanent |
| **permission**                                              | an array of values from the [permission restriction list](#list-of-restrictions-for-the-required-parameter-permission).                                                                                       |
| **media\_permissions**                                      | a list of values for granting media-related permissions                                                                                                                                                       |

</details>

<details>

<summary><strong>List of restrictions for the required parameter </strong><mark style="color:red;"><strong>permission</strong></mark></summary>

**List of restrictions for** **permission:**\
1\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_messages** - permission to send text messages, contacts, locations, and venues.\
2\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_media\_messages** - permission to send audio, documents, photos, videos, video notes, and voice notes. It requires **can\_send\_messages**\
3\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_polls** - permission to send polls. It requires **can\_send\_messages**\
4\. <mark style="color:red;">**!**</mark>**&#x20;can\_send\_other\_messages** - permission to send animations, games, stickers, and to use inline bots. It requires **can\_send\_media\_messages**\
5\. <mark style="color:red;">**!**</mark>**&#x20;can\_add\_web\_page\_previews** - permission to add web-page previews to messages. It requires **can\_send\_media\_messages**\
6\. <mark style="color:red;">**!**</mark>**&#x20;can\_change\_info** - permission to change the chat title, photo, and other settings. This is ignored in public supergroups.\
7\. <mark style="color:red;">**!**</mark>**&#x20;can\_invite\_users** - permission to invite users\
8\. <mark style="color:red;">**!**</mark>**&#x20;can\_pin\_messages** - permission to pin messages. This is ignored in public supergroups.\
9\. **can\_manage\_topics** - permission to create topics in forum groups. If used in a group of the wrong type, the function will fail and return an error.&#x20;

</details>

<details>

<summary>List of values for the required parameter <mark style="color:red;"><strong>media_permissions</strong></mark></summary>

#### Values for granting media-related permissions **media\_permissions:**&#x20;

1\. **can\_send\_audios** - permission to send audio files\
2\. **can\_send\_documents** -permission to send documents\
3\. **can\_send\_photos** - permission to send photos\
4\. **can\_send\_videos**  - permission to send videos\
5\. **can\_send\_video\_notes** - permission to send round video messages\
6\. **can\_send\_voice\_notes** - permission to send voice messagesя

</details>

<details>

<summary>Example</summary>

Example of using the function, where the user is restricted from everything for 3 minutes:

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

When the user enters the chat, they will see a notification that they cannot send messages in the chat.\
If a time limit is set, they will also see the duration of this restriction.

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

Code example to copy:

```
permission = [0, 0, 0, 0, 0, 0, 0, 0] 
tg_restrict_chat_member(-1001607137668, 473737685, 3, permission)
```

</details>

## How to pin message

<details>

<summary>Description</summary>

**tg\_pin\_chat\_message(platform\_id, message\_id, disable\_notification)**&#x20;

Parameters:

<table><thead><tr><th width="311.3359375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram  <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><strong>message_id</strong></td><td>message ID that needs to pin</td></tr><tr><td><strong>disable_notification</strong></td><td>The parameter defines whether a notification should be sent to all chat members about a new pinned message (notifications are always disabled in channels and private chats).<br>If you do not want to send notifications, set the parameter <strong>disable_notification</strong> to <strong>1</strong>.<br>Otherwise, set it to <strong>0</strong>.</td></tr></tbody></table>

</details>

## How to unpin message

<details>

<summary>Description</summary>

**tg\_unpin\_chat\_message(platform\_id, message\_id)**&#x20;

Parameters:

<table><thead><tr><th width="311.3359375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><strong>message_id</strong></td><td>ID of the message that should be unpinned. If message_id is not provided, the most recent pinned message (by send date) will be unpinned</td></tr></tbody></table>

</details>

## How to unpin all pinned messages

<details>

<summary>Description</summary>

**tg\_unpin\_all(platform\_id)**

Parameters:

<table><thead><tr><th width="311.3359375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr></tbody></table>

{% hint style="warning" %}
ATTENTION!

Telegram has a limitation for the pin/unpin message functions.&#x20;

The time limits for using **tg\_pin\_chat\_message / tg\_unpin\_chat\_message / tg\_unpin\_all&#x20;**<mark style="color:red;">**are NOT set by the MaviBot system.**</mark>&#x20;

**If the allowed time for pinning a message has passed, the function will still return true, but Telegram will not apply the change.**

It is also important to note that pinned messages can remain in cache, so they may not disappear visually right away.
{% endhint %}

</details>

## How to create a poll in Telegram

<details>

<summary>Description</summary>

**tg\_send\_poll(platform\_id, question, options, is\_anonymous, allows\_multiple\_answers, reply\_markup, disable\_notification, protect\_content, token, reply\_to\_message\_id,  message\_thread\_id, business\_connection\_id)**

Parameters:

<table><thead><tr><th width="311.3359375">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID in Telegram  <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a> </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> question</strong> </td><td>question</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> options</strong></td><td>an array of answer options</td></tr><tr><td><strong>is_anonymous</strong></td><td>1 - anonymous survey , '' - not anonymous </td></tr><tr><td><strong>allows_multiple_answers</strong></td><td>1 - multiple answers are available, '' - one answer</td></tr><tr><td><strong>reply_markup</strong> </td><td>keyboard or '' - without keyboard </td></tr><tr><td><strong>disable_notification</strong></td><td>flag for sending with sound notification (default 0)<br>1 – disable notification on receipt, 0 – send with notification</td></tr><tr><td><strong>protect_content</strong></td><td>1 to protect from copying and screenshots, ''  no protection</td></tr><tr><td><strong>token</strong></td><td>bot token; if not provided, the current one is used</td></tr><tr><td>r<strong>eply_to_message_id</strong></td><td>ID of quoted message</td></tr><tr><td><strong>message_thread_id</strong></td><td>thread ID (available for supergroups if forum functionality exists)</td></tr><tr><td><strong>business_connection_id</strong></td><td>value when connecting a bot (Business ID). Shows in channels. Should be provided if the bot token is used and the message must be sent through a user account connected to the bot</td></tr></tbody></table>

</details>

<details>

<summary>Important to know!</summary>

Notes

1\. The function returns a response from Telegram with **message\_id**. It is better to save it. Using message\_id, you can stop the poll with **tg\_stop\_poll** (see description below) and get the result.

2\. If a user adds a poll in a messenger, a callback is sent to the chat:

**poll\_added** - неизменная часть \
YOUR QUESTION - текст вопроса из опроса

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

Пример колбека при добавлении опроса в канал

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

Пример колбека при добавлении опроса в чат

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

Второй колбек после poll\_added содержит цифры - это не что иное, как идентификатор  пользователя в Telegram, который добавил опрос.

{% hint style="warning" %}
**При создании опроса ботом колбек не приходит.**
{% endhint %}

&#x33;**.** В канале можно создавать только анонимные опросы

{% hint style="info" %}
**Внимание, рекомендуется отправлять в группу только анонимные опросы!**
{% endhint %}

4\. После создания опроса в переменную сохраните его идентификатор, чтобы понимать на какой опрос пришел колбек.

</details>

<details>

<summary>Example</summary>

Client feedback is key to our growth. Polls offer a straightforward method to capture this feedback and translate it into concrete business conclusions.

Code example for copying:

```
/* Example of creating a simple poll */
options = ["white", "red", "blue", "green"]
poll1 = tg_send_poll(platform_id, 'What is your favorite color?', options, 1, '', '', 1, '')
```

**Function for creating a poll in Telegram:**

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

**The poll we created in Telegram**

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

</details>

## How to create a quiz in Telegram

<details>

<summary>Description</summary>

**tg\_send\_quiz\_poll(platform\_id, question, options, explanation, correct\_option\_id, is\_anonymous, reply\_markup, parse\_mode, protect\_content, disable\_notification, token, reply\_to\_message\_id, message\_thread\_id )**

Parameters:&#x20;

<table><thead><tr><th width="311.25">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> question</strong> </td><td>question</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> options</strong></td><td>an array of answer options</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> explanation</strong></td><td>text displayed when a user selects a wrong answer or clicks the lamp icon in a quiz-style poll, 0–200 characters with no more than two line breaks after entity parsing.</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> correct_option_id</strong></td><td>номер правильного ответа, нумерация с 1</td></tr><tr><td><strong>is_anonymous</strong></td><td>1 - anonymous survey , '' - not anonymous </td></tr><tr><td><strong>reply_markup</strong></td><td>keyboard or '' - without keyboard </td></tr><tr><td><strong>parse_mode</strong></td><td>explanation format: <code>markdown</code>, <code>html</code>, or <code>''</code> (empty string for no formatting)</td></tr><tr><td><strong>protect_content</strong></td><td>1 to protect from copying and screenshots, ''  no protection</td></tr><tr><td><strong>disable_notification</strong></td><td>flag for sending with sound notification (default 0)<br>1 – disable notification on receipt, 0 – send with notification</td></tr><tr><td><strong>token</strong></td><td>bot token; if not provided, the current one is used</td></tr><tr><td><strong>reply_to_message_id</strong></td><td>quoted message ID</td></tr><tr><td><strong>message_thread_id</strong></td><td>topic ID (available in supergroups with active forum features)</td></tr></tbody></table>

</details>

<details>

<summary><mark style="color:orange;">Important to know!</mark></summary>

#### **Notes**

**1. Save the `message_id`**

The API function returns a Telegram response containing a **`message_id`**. Always save this ID, as it is required to:

* End the quiz using the `tg_stop_poll` function (see description below).
* Retrieve the final results.

**2. Callback `poll_added`**

If a user adds a poll to a **channel**, the bot receives a callback:

* **Format:** `poll_added` + **Poll question**
* **If added to a group chat:** the callback also includes the **Telegram User ID** of the person who added the poll.

{% hint style="warning" %}
**If created by the bot:** No `poll_added` callback is sent.
{% endhint %}

**3. Channel restriction**

Only **anonymous quizzes** can be created in channels.

**4. Callback `poll_answer` (User voting)**

When a user votes in a quiz sent to a **private chat** or **group**, a callback is sent to the bot's dialog with that client:

* **Format:** `poll_answer` + **Poll ID** + **\[Answer index]**
* **Example:** `poll_answer 5325838371359031648 [3]`
* **Note:** answer numbering starts from **0**. `[3]` means the user selected the fourth answer option.

**5. Webhook for non-anonymous group polls**

For **non-anonymous polls** in groups where the bot is an admin, a webhook is sent for *every vote*. Upon receiving it, the bot will forward the `poll_answer` callback (as in point 4) to its dialog with the corresponding client.

**6. Activation requirement & best practice**

* **Requirement:** a bot cannot initiate a conversation. If a client has never contacted the bot, you cannot send them a direct message in response to their vote until they **activate the bot first** (e.g., by sending a `/start` command).

{% hint style="info" %}
**Recommendation:** to avoid this limitation, it is **highly recommended to send only anonymous quizzes to groups.**
{% endhint %}

**7. Track your polls**

Immediately after creating a quiz, save its unique **Poll ID** to a variable. This allows you to identify which specific poll an incoming callback refers to.

</details>

<details>

<summary>Example</summary>

Code example for copying.

```
options = ["white", "red", "blue", "green"] 
r = tg_send_quiz_poll(platform_id, "What color is a crocodile?", options, "That is the explanation", 4, '', '', '', '', 1)
```

Example: quiz creation.

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

</details>

## How to end a poll

<details>

<summary>Description</summary>

**tg\_stop\_poll(platform\_id, message\_id)**

Parameters:

<table><thead><tr><th width="303.45703125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID in Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_id</strong></td><td>poll/quiz message ID. It can be obtained from the webhook</td></tr></tbody></table>

{% hint style="info" %}
Calling this function to end a poll/quiz returns a dictionary containing the final results.
{% endhint %}

</details>

## How to work with topics in Telegram

{% hint style="warning" %}
Important: the main group topic does not have an ID and requires separate functions to work with it.
{% endhint %}

### How to rename group's General Topic

<details>

<summary>Description</summary>

**tg\_edit\_general\_forum\_topic(platform\_id, topic\_name)**

Parameters:

<table><thead><tr><th width="303.1171875">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> topic_name</strong></td><td>new topic name</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Example</summary>

The groups' General Topic can be changed using the `tg_edit_general_forum_topic()` function. It requires two mandatory parameters: the chat ID and the new name for the Group Topic:

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

</details>

<details>

<summary>Code example for copying</summary>

*rename the General Topic chat*/\
`answer = tg_edit_general_forum_topic(-1001839380031, 'General')`

</details>

### How to close General Topic

<details>

<summary>Description</summary>

**tg\_close\_general\_forum\_topic(platform\_id)**

Parameters:

<table><thead><tr><th width="315.3203125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

/*close the General Topic chat*/\
`answer = tg_close_general_forum_topic(-1001839380031)`

</details>

### How to reopen a previously closed General Topic

<details>

<summary>Description</summary>

**tg\_reopen\_general\_forum\_topic(platform\_id)**&#x20;

Parameters:

<table><thead><tr><th width="315.3203125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code exmaple for copying</summary>

/*reopen the General Topic chat*/\
`answer = tg_reopen_general_forum_topic(-1001839380031)`

</details>

### How to hide General Topic

<details>

<summary>Description</summary>

**tg\_hide\_general\_forum\_topic(platform\_id)**&#x20;

Parameters:

<table><thead><tr><th width="315.3203125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

The General Topic chat can be closed for the Topic's participants (they can read but not write) and hidden from Telegram's general chat list for new users.

</details>

<details>

<summary>Code example for copying</summary>

/hide the General Topic chat/\
`answer = tg_hide_general_forum_topic(-1001839380031)`

</details>

### **How to display General Topic or restore its visibility**

<details>

<summary>Description</summary>

**tg\_unhide\_general\_forum\_topic(platform\_id)**&#x20;

Parameters:

<table><thead><tr><th width="315.3203125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>topic ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

{% hint style="warning" %} <mark style="color:red;">**Important!**</mark>&#x20;

This function does not reopen General Topic; it only makes it visible.
{% endhint %}

</details>

<details>

<summary>Code example for copying</summary>

/*display the General Topic chat*/\
`answer = tg_unhide_general_forum_topic(-1001839380031)`

</details>

### How to create a new topic in Telegram

<details>

<summary>Description</summary>

**tg\_create\_forum\_topic(platform\_id, name, icon, icon\_color)**&#x20;

Parameters:

<table><thead><tr><th width="312.953125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> name</strong></td><td>new topic name</td></tr><tr><td><strong>icon</strong></td><td>emoji ID to be set for the topic. Passed as a string. You can only use emojis from the list retrieved by the <code>tg_get_forum_icon</code> function.</td></tr><tr><td><strong>icon_color</strong></td><td>emoji color from the list: 7322096, 16766590, 13338331, 9367192, 16749490, 16478047. Not all emojis support color changes.</td></tr><tr><td>bot_name </td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

{% hint style="info" %}
The set color cannot be changed; color can only be assigned when creating the topic.
{% endhint %}

When executed, the function will return a response containing the parameters of the new topic, including the topic ID (required for various functions).

</details>

<details>

<summary>Code example for copying</summary>

To create an additional topic chat\
`answer = tg_create_forum_topic(-1001839380031, 'second_bot_topic', None, 7322096)`

To save the created additional topic chat ID\
`answer={"ok":true,"result":{"message_thread_id":254,"name":"second_bot_topic","icon_color":7322096}}/`\
`idtema1=answer['result']['message_thread_id']`

</details>

### How to edit a topic. How to rename and/or change the emoji for a topic

<details>

<summary>Description</summary>

**tg\_edit\_forum\_topic(platform\_id, message\_thread\_id, name, icon)**&#x20;

Parameters:

<table><thead><tr><th width="301.7578125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_thread_id</strong></td><td>additional topic chat ID</td></tr><tr><td><strong>name</strong></td><td>new topic name</td></tr><tr><td><strong>icon</strong></td><td>emoji ID to be set for the topic. Passed as a string. You can only use emojis from the list retrieved by the <code>tg_get_forum_icon</code> function.</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

`answer = tg_edit_forum_topic(-1001839380031, 254)`

</details>

### How to close a selected topic

<details>

<summary>Description</summary>

Closing a topic means making it read-only; writing in a closed topic is not allowed.

**tg\_close\_forum\_topic(platform\_id, message\_thread\_id)**&#x20;

Parameters:

<table><thead><tr><th width="300.9765625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_thread_id</strong></td><td>additional topic chat ID</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

`answer = tg_close_forum_topic(-1001839380031, 254)`

</details>

### How to reopen a previously closed topic

<details>

<summary>Description</summary>

**tg\_reopen\_forum\_topic(platform\_id, message\_thread\_id)**&#x20;

Parameters:

<table><thead><tr><th width="300.9765625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_thread_id</strong></td><td>additional topic chat ID</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

`answer = tg_reopen_forum_topic(-1001839380031, 254)`

</details>

### How to delete a topic and all its messages

<details>

<summary>Description</summary>

**tg\_delete\_forum\_topic(platform\_id, message\_thread\_id)**&#x20;

Parameters:

<table><thead><tr><th width="300.9765625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_thread_id</strong></td><td>additional topic chat ID</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

`answer = tg_delete_forum_topic(-1001839380031, 254)`

</details>

### How to unpin all messages in a topic

<details>

<summary>Description</summary>

**tg\_unpin\_topic\_messages(platform\_id, message\_thread\_id)**&#x20;

Parameters:

<table><thead><tr><th width="300.9765625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>chat ID inside Telegram <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> message_thread_id</strong></td><td>additional topic chat ID</td></tr><tr><td>bot_name</td><td><p>optional parameter: bot name.</p><p>When working with topics, you can specify which bot should execute the function. This is useful if your project uses multiple Telegram bots. Find the bot name in the "Channels" section, in the "Group ID" field.</p></td></tr></tbody></table>

</details>

<details>

<summary>Code example for copying</summary>

`answer = tg_unpin_topic_messages(-1001839380031, 254)`

</details>

### How to get the list of emojis for a Telegram Topic

<details>

<summary>Description</summary>

<mark style="background-color:blue;">**How to get the list of emojis**</mark>

`tg_get_forum_icon()` – this function returns a list of emojis available for use as forum topic icons. The result must be assigned to a variable, as it returns a dictionary where each key is an emoji and its corresponding value is the emoji's unique identifier (`id`).

Parameters: <mark style="color:green;">**none.**</mark>&#x20;

</details>

<details>

<summary>The content of the emoji list</summary>

To get the list of emojis for a Topic chat, send the command to the relevant chat.

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

The function will return the emoji list in its response. This means the variable `answer` will contain a dictionary as its value.

{'📰': '5434144690511290129', '💡': '5312536423851630001', '⚡️': '5312016608254762256', '🎙': '5377544228505134960', '🔝': '5418085807791545980', '🗣': '5368697802761185083', '🆒': '5420216386448270341', '❗️': '5379748062124056162', '📝': '5357193964787081133', '📆': '5433614043006903194', '📁': '5357315181649076022', '🔎': '5309965701241379366', '📣': '5309984423003823246', '🔥': '5312241539987020022', '❤️': '5312138559556164615', '❓': '5377316857231450742', '📈': '5350305691942788490', '📉': '5350713563512052787', '💎': '5309958691854754293', '💰': '5350452584119279096', '💸': '5309929258443874898', '\U0001fa99': '5377690785674175481', '💱': '5310107765874632305', '⁉️': '5377438129928020693', '🎮': '5309950797704865693', '💻': '5350554349074391003', '📱': '5409357944619802453', '🚗': '5312322066328853156', '🏠': '5312486108309757006', '💘': '5310029292527164639', '🎉': '5310228579009699834', '‼️': '5377498341074542641', '🏆': '5312315739842026755', '🏁': '5408906741125490282', '🎬': '5368653135101310687', '🎵': '5310045076531978942', '🔞': '5420331611830886484', '📚': '5350481781306958339', '👑': '5357107601584693888', '⚽️': '5375159220280762629', '🏀': '5384327463629233871', '📺': '5350513667144163474', '👀': '5357121491508928442', '\U0001fae6': '5357185426392096577', '🍓': '5310157398516703416', '💄': '5310262535021142850', '👠': '5368741306484925109', '✈️': '5348436127038579546', '\U0001f9f3': '5357120306097956843', '🏖': '5310303848311562896', '⛅️': '5350424168615649565', '🦄': '5413625003218313783', '🛍': '5350699789551935589', '👜': '5377478880577724584', '🛒': '5431492767249342908', '🚂': '5350497316203668441', '🛥': '5350422527938141909', '🏔': '5418196338774907917', '🏕': '5350648297189023928', '🤖': '5309832892262654231', '\U0001faa9': '5350751634102166060', '🎟': '5377624166436445368', '🏴\u200d☠️': '5386395194029515402', '🗳': '5350387571199319521', '🎓': '5357419403325481346', '🔭': '5368585403467048206', '🔬': '5377580546748588396', '🎶': '5377317729109811382', '🎤': '5382003830487523366', '🕺': '5357298525765902091', '💃': '5357370526597653193', '\U0001fa96': '5357188789351490453', '💼': '5348227245599105972', '\U0001f9ea': '5411138633765757782', '👨\u200d👩\u200d👧\u200d👦': '5386435923204382258', '👶': '5377675010259297233', '🤰': '5386609083400856174', '💅': '5368808634392257474', '🏛': '5350548830041415279', '\U0001f9ee': '5355127101970194557', '🖨': '5386379624773066504', '👮\u200d♂️': '5377494501373780436', '\U0001fa7a': '5350307998340226571', '💊': '5310094636159607472', '💉': '5310139157790596888', '\U0001f9fc': '5377468357907849200', '\U0001faaa': '5418115271267197333', '🛃': '5370947704199323325', '🍽': '5350344462612570293', '🐟': '5384574037701696503', '🎨': '5310039132297242441', '🎭': '5350658016700013471', '🎩': '5357504778685392027', '🔮': '5350367161514732241', '🍹': '5350520238444126134', '🎂': '5310132165583840589', '☕️': '5350392020785437399', '🍣': '5350406176997646350', '🍔': '5350403544182694064', '🍕': '5350444672789519765', '\U0001f9a0': '5312424913615723286', '💬': '5417915203100613993', '🎄': '5312054580060625569', '🎃': '5309744892677727325'}

</details>

<details>

<summary>Code example for copying</summary>

```
answer = tg_get_forum_icon()
```

</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/messengers/telegram/api/chat.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.
