# How to make a Telegram bot

{% hint style="warning" %}

#### **Telegram requirements & limits**

**1. Message limits**

* **Text-only message:** Maximum of **4,096 characters**.
* **Message with an image:** Maximum of **1,024 characters** (for a 1080x1080 px image).

**2. Image requirements**

* **Format:** Square images are preferred.
* **Optimal size:** 900x900 pixels, maximum **5 MB**.

**3. File requirements**

The Telegram API has specific requirements for uploaded files:

* Bots can send files up to **2 GB**.
* You can use **file\_id** to work with previously uploaded files. In this case, file limits follow the Telegram documentation.
* Files can be sent using a **URL** (the bot downloads and sends it):
  * **Photos:** ≤ 5 MB
  * **Other files:** ≤ 20 MB
* Different limits apply for posting:
  * **Photos:** 10 MB
  * **Other files:** 2 GB

[Read more in the original source](https://core.telegram.org/bots/api#sending-files)
{% endhint %}

## Telegram bot creation

A Telegram bot is created through **BotFather**, Telegram's official bot management system. This verified tool (indicated by a blue checkmark) allows you to create a bot without any programming knowledge and protects you from fraudulent imitators.

**Creation Steps:**

1. **Start a chat** with [BotFather](https://t.me/botfather).
2. Send the command: `/newbot`
3. **Choose a name** for your bot (this is the display name for users).
4. **Choose a username** for your bot. It **must** end with `bot` or `_bot` (e.g., `my_test_bot`).

If the username is available, BotFather will send you a confirmation message containing a **"token"**—a unique key for API access.

> **Important:** This token is a password for your bot. Save it securely and **never share it** with anyone.

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

Navigate to the **Messengers** section, select **Telegram**, and paste your bot's token into the provided field.

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

Click the **Done** button to complete the bot setup and activate the connection to your project.

### Working with Telegram groups/channels

**Useful information**

A Telegram group is a communication channel between participants: all participants can write in it.

The Telegram channel is a one-way means of communication. Only the owner or administrators can send messages, while the rest of the participants can only view them and leave comments.

#### How to add a bot to a Telegram group/channel

This feature for the bot is included in BotFather:

Step 1. Go to the bot settings:

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

Step 2. Click on **"Allow Groups?'**

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

Step 3. There should be an enabled status.

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

### Add a bot as an administrator in a group/channel

In order to automate work in chats and channels, you need to add your own bot as an Administrator.

How to do it?

Step 1. Go to Group/Channel Management and select the **Administrators** tab

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

Step 2. Click the **"Add Admin"** button.

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

Step 3. Enter your bot's username in the search box.

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

Step 4. For full functionality, ensure the bot has the rights to read and delete messages.

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

### Variables for working in chats

{% hint style="warning" %}
Please note!

Saving variables in group chats for events such as joining a chat, exiting a chat, new like, etc. is not available.

Variables will be available only inside the block that has worked. You can output these variables in the block to track the work.

This WILL NOT affect the operation of chatbots in any way, it will be impossible to track who entered/exited in the clients section.
{% endhint %}

* Variables with information about the author of the message

message\_from - the ID of the message author&#x20;

message\_from\_name - the name of the message author

message\_from\_username - the nickname of the message author in the Telegram

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

* Variables with information about the forwarded message

reply\_message\_id - the number of the message being forwarded&#x20;

reply\_from - who is the author of the forwarded message

reply\_from\_name - the name of the person whose message is being forwarded

reply\_from\_username - the nickname of the person whose message is being forwarded

reply\_from\_chat\_id - the number of the dialog from which the message was forwarded

* Adding and removing from a group

In this case, the new\_chat\_member and left\_chat\_member callbacks are triggered (variables are not saved in the client's card):

chat\_member\_name - username&#x20;

chat\_member\_username - user's nickname

chat\_member\_id - user's number

### Callbacks in Telegram

client\_unsubscribed - the client has unsubscribed, blocked the bot

client\_returned - the client has unblocked the bot

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

#### Callbacks in groups/channels

new\_chat\_member - a new user has been added

left\_chat\_member - the user left the channel&#x20;

kicked\_chat\_member - the user was deleted by the administrator

chat\_join\_request - a request has been received to add to the channel

edited\_channel\_post - the post on the channel has been edited (edited\_channel\_post + date and time of editing)

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

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

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

Callbacks are displayed in the **Clients** section

bot\_added\_to\_group - a bot has been added to the chat (it doesn't matter which one, it will respond to anyone, even if the connected bot was added to the group itself);

bot\_left\_group - a similar callback is removing the bot from the channel;

new\_like - liked the post

like\_deleted - deleted a like from the post

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

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

The number in the callback (new\_like; like\_deleted) is the ID of the message that was responded to or removed from.

{% hint style="warning" %}
Please note!

* Callbacks for reactions are not displayed in Telegram channels! Callbacks for reactions come only in groups.
* If one person has put several likes, and then deleted 1 of them, it does not show which one was deleted.
  {% endhint %}

When callbacks with reactions appear in groups, variables are available in the block:

reaction\_on\_message\_id - contains the ID of the message that was responded to

reaction\_from - id from whom there was a reaction

message\_from\_username - username from whom there was a reaction (if any)

reaction\_from\_name - name from whom was the reaction

<div data-with-frame="true"><figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfQptKK4YrlEATINQANRDaNEnpT95W_lgIGjMfOitIn387SG1GKI_n02rgWMZUrCP6hEGEnYAPiY99aZud2Ze4iOCYSlDCpzNsyHAMFdHd_mCxP5VfBpSx2iG7HzP1lgzDDly1Ziw?key=lL8rEUrFbZeHFjWugKFnxg" alt="" width="375"><figcaption></figcaption></figure></div>

Also, if Telegram responds to a message, the reply\_text variable in the card will contain the full text of the message that was answered.

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

If a message was sent as a reply (quoting a previous message), the system will also generate the `tg_quote` variable, which contains the quoted text.

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

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

#### Callbacks with boost

* chat\_boost\_from user #{id\_user} - gave a boost to the chat (or channel):

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

When this callback is triggered, variables are generated:

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

* remove\_boost\_from user #{id\_user} - they took the boost from the chat (or channel):

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

When this callback is triggered,, variables are generated:

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

* chat\_boost from giveaway - issued during the drawing of stars in the channel
* remove\_chat\_boost from giveaway - the boost period for drawing stars in the channel has ended

#### How to automate the removal of system notifications in groups

To automatically delete all system messages, it is enough to assign any value to the del\_tg\_system\_messages variable (the variable can be either a project constant or a transaction variable) and give the bot permission to delete messages.

The del\_tg\_system\_messages variable can only be used in groups. In channels, assigning any value to this variable will not lead to any result.

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

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

**Administrator rights in Telegram group settings**

The following types of system notifications are removed:

\- The name of the group has been changed

\- The group's photo has been changed

\- Group photo deleted

\- The message is pinned

\- The user joined the group

\- The user has left the group

If you want to delete only selected types of system notifications, then instead of the del\_tg\_system\_messages variable, create the del\_tg\_chosen\_messages variable and put in it an array with the types of notifications to be deleted, separated by commas.

{% hint style="warning" %}
Please note!

These variables will only work for Telegram groups, but not for channels.
{% endhint %}

System notification options:

* 'new\_chat\_member' – the user joined the group,
* 'left\_chat\_member' – the user left the group,
* 'pinned\_message' – the message is pinned,
* 'delete\_chat\_photo' – group photo deleted,
* 'new\_chat\_photo' –the group's photo has been changed,
* 'new\_chat\_title' – the name of the group has been changed

For example, you need to delete all kinds of system messages except joining a group; then you need to add all kinds of callbacks to the project variable (constant) except "new\_chat\_member".

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

{% hint style="info" %}
Please note!

Deleting system notifications will not affect callbacks. Only the system message from the Telegram dialog will be deleted.
{% endhint %}

### Forum in Telegram

A forum is a group where you can create separate topics for discussion. You can use standard functions in the forum: attach media files, post polls, and set up notifications. You can also pin messages and add individual bots to each chat.

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

The primary purpose of a forum is to **structure communication** within a large community.

In a standard group chat with many participants, following conversations and finding relevant messages becomes difficult. Forums solve this by organizing discussions into **dedicated, thematic threads**. This automatically segments the community by topic and interest, making communication more focused and manageable.

Only the group owner can create a topic if there are more than 100 members in the group. If the group is linked to a channel, then you will not be able to create a theme. Topics are enabled in the **Group settings**:

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

As an administrator, you can create a topic in the settings of the forum group:

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

After connecting the **Topics**, the avatar will change from round to square, which allows you to distinguish the forum from other Telegram chats:

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

### How to configure a Telegram-client bundle with a website?

Read more about how to link a telegram client and a client from the website after [a successful payment here](#how-to-configure-a-telegram-client-bundle-with-a-website).


---

# 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/chatbot.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.
