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

tg_set_group_title(platform_id, title) -

Parameters:

How to change chat description via Telegram bot

tg_set_chat_description(platform_id, description)

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

tg_set_chat_photo(platform_id, photo)

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

tg_delete_chat_photo(platform_id)

How to ban a Telegram group

tg_ban_chat_sender_chat(platform_id, sender_chat_id)

Parameters:

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

How to unblock Telegram group

tg_unban_chat_sender_chat(platform_id, sender_chat_id)

Parameter:

tg_create_chat_invite_link(platform_id, member_limit, hours, request, name)

Parameter:

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.

Creating chat invite link

tg_revoke_chat_invite_link(platform_id, invite_link)

Parameters:

tg_export_chat_link(platform_id)

Parameters:

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

Use with caution. All existing login links to your group will become inactive.

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

tg_approve_chat_join_request(chat_id, user_id)

Parameters:

Request acceptance:

How to decline request in Telegram channel/chat

tg_decline_chat_join_request(chat_id, user_id)

Parameters:

Request declining

How to block user in Telegram

tg_ban_chat_member(chat_id, user_id, hours)

Parameters:

How to unblock user in Telegram

tg_unban_chat_member(chat_id, user_id)

Parameters:

How to check subscription status in Telegram

tg_get_chat_member(chat_id, user_id)

Parameters:

How to determine the number of members in channel/chat

tg_get_chat_member_count(platform_id)

Parameters:

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

Parameters:

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

tg_send_chat_action(platform_id, bot_action, message_thread_id)

! Work with Telegram business-account

Parameters:

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.

This notification will be displayed until any response is received from the bot, but no more than 5 seconds.

How to show Alert-notification to the user

tg_answer_callback_query(callback_query_id, text,show_alert,cache_time)

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"}]

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".

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

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.

Code example to copy:

tg_answer_callback_query('#{callback_query_id}', "You pressed the button 111")

Pay attention! The callback_query_id parameter should be passed exactly as shown in the example, i.e. inside '#{}'

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.

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)

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

tg_callback_url_open(callback_query_id, url, cache_time)

Parameters:

В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"}]

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".

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

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'):

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

tg_promote_user(platform_id, user_id, promote_options_list)

Parameters:

The following permissions can be specified in the promote_options_list :

  1. is_anonymous — пhides the administrator’s presence in the chat,
  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 (channels only)
  4. can_edit_messages — the administrator can edit other users’ messages and pin messages (channels only)
  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,
  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 (supergroups only).

Example: Promoting a user to administrator in a supergroup:

In this example, in addition to the specified permissions, the can_manage_chat permission will be granted by default.

Code example to copy

How to change an administrator title using a bot in Telegram

tg_set_administrator_title(platform_id, user_id, title)

Parameters:

IMPORTANT!

This works only for users who were promoted to administrators in the supergroup by the bot

Code example to copy:

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

General restrictions for regural chat members or specific Telegram users

tg_chat_permission(platform_id, permission, media_permissions)

Parameters:

List of restrictions for permission:
1. ! can_send_messages - permission to send text messages, contacts, locations, and venues.
2. ! can_send_media_messages - permission to send audio, documents, photos, videos, video notes, and voice notes. It requires can_send_messages
3. ! can_send_polls - permission to send polls. It requires can_send_messages
4. ! can_send_other_messages - permission to send animations, games, stickers, and to use inline bots. It requires can_send_media_messages
5. ! can_add_web_page_previews - permission to add web-page previews to messages. It requires can_send_media_messages
6. ! can_change_info - permission to change the chat title, photo, and other settings. This is ignored in public supergroups.
7. ! can_invite_users - permission to invite users
8. ! 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.

Values for granting media-related permissions media_permissions:

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я

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

tg_restrict_chat_member(platform_id, user_id, minutes, permission, media_permissions).

Parameters:

Parameter Description
! platform_id chat ID in Telegram *
! user_id user ID in Telegram *
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.
media_permissions a list of values for granting media-related permissions

List of restrictions for permission:
1. ! can_send_messages - permission to send text messages, contacts, locations, and venues.
2. ! can_send_media_messages - permission to send audio, documents, photos, videos, video notes, and voice notes. It requires can_send_messages
3. ! can_send_polls - permission to send polls. It requires can_send_messages
4. ! can_send_other_messages - permission to send animations, games, stickers, and to use inline bots. It requires can_send_media_messages
5. ! can_add_web_page_previews - permission to add web-page previews to messages. It requires can_send_media_messages
6. ! can_change_info - permission to change the chat title, photo, and other settings. This is ignored in public supergroups.
7. ! can_invite_users - permission to invite users
8. ! 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.

Values for granting media-related permissions media_permissions:

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я

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

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.

Code example to copy:

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

How to pin message

tg_pin_chat_message(platform_id, message_id, disable_notification)

Parameters:

How to unpin message

tg_unpin_chat_message(platform_id, message_id)

Parameters:

How to unpin all pinned messages

tg_unpin_all(platform_id)

Parameters:

ATTENTION!

Telegram has a limitation for the pin/unpin message functions.

The time limits for using **tg_pin_chat_message / tg_unpin_chat_message / tg_unpin_all **are NOT set by the MaviBot system.

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.

How to create a poll in Telegram

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:

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 - текст вопроса из опроса

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

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

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

При создании опроса ботом колбек не приходит.

3. В канале можно создавать только анонимные опросы

Внимание, рекомендуется отправлять в группу только анонимные опросы!

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

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:

The poll we created in Telegram

How to create a quiz in Telegram

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:

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.

If created by the bot: No poll_added callback is sent.

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).

Recommendation: to avoid this limitation, it is highly recommended to send only anonymous quizzes to groups.

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.

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.

How to end a poll

tg_stop_poll(platform_id, message_id)

Parameters:

Calling this function to end a poll/quiz returns a dictionary containing the final results.

How to work with topics in Telegram

Important: the main group topic does not have an ID and requires separate functions to work with it.

How to rename group's General Topic

tg_edit_general_forum_topic(platform_id, topic_name)

Parameters:

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:

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

How to close General Topic

tg_close_general_forum_topic(platform_id)

Parameters:

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

How to reopen a previously closed General Topic

tg_reopen_general_forum_topic(platform_id)

Parameters:

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

How to hide General Topic

tg_hide_general_forum_topic(platform_id)

Parameters:

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.

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

How to display General Topic or restore its visibility

tg_unhide_general_forum_topic(platform_id)

Parameters:

Important!

This function does not reopen General Topic; it only makes it visible.

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

How to create a new topic in Telegram

tg_create_forum_topic(platform_id, name, icon, icon_color)

Parameters:

The set color cannot be changed; color can only be assigned when creating the topic.

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

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']

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

tg_edit_forum_topic(platform_id, message_thread_id, name, icon)

Parameters:

answer = tg_edit_forum_topic(-1001839380031, 254)

How to close a selected topic

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)

Parameters:

answer = tg_close_forum_topic(-1001839380031, 254)

How to reopen a previously closed topic

tg_reopen_forum_topic(platform_id, message_thread_id)

Parameters:

answer = tg_reopen_forum_topic(-1001839380031, 254)

How to delete a topic and all its messages

tg_delete_forum_topic(platform_id, message_thread_id)

Parameters:

answer = tg_delete_forum_topic(-1001839380031, 254)

How to unpin all messages in a topic

tg_unpin_topic_messages(platform_id, message_thread_id)

Parameters:

answer = tg_unpin_topic_messages(-1001839380031, 254)

How to get the list of emojis for a Telegram Topic

How to get the list of emojis

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: none.

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

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'}

answer = tg_get_forum_icon()