Functions for sending and editing messages
How to send messages using a Telegram Business account
tg_send_message(platform_id, text,client_message_id, reply_markup, parse_mode, disable_web_page_preview, protect_content, disable_notification, message_thread_id, entities)
Parameters:
! platform_id
Telegram user ID to which a message should be sent *
! text
Message text
client_message_id
Message ID to be quoted
reply_markup
Button settings **
parse_mode
Bold and italic text formatting in the description ***. It can have values such as html, markdown, markdownV2.
disable_web_page_preview
Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".
protect_content
Content protection flag. Pass any value except 0, False, or '' to enable.
disable_notification
Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.
message_thread_id
Topic ID (available for supergroups with forum functionality enabled)
entities
This allows you to copy pre-formatted text along with all its styles and simply specify the character range where a particular font should be applied. An example can be found in the tg_request under the corresponding field. The parameter must be a dictionary. See the example tab for reference.
How to send a message specifying a particular Telegram bot
tg_send_message_1(token, platform_id, text, client_message_id, reply_markup, parse_mode, disable_web_page_preview, protect_content, disable_notification, message_thread_id, entities, business_connection_id)
! token
Telegram bot token obtained from BotFather
! platform_id
Telegram user ID to which a message should be sent *
! text
Message text
client_message_id
Message ID to be quoted
reply_markup
Button settings **
parse_mode
Bold and italic text formatting in the description ***. It can have values such as html, markdown, markdownV2.
disable_web_page_preview
Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".
protect_content
Content protection flag. Pass any value except 0, False, or '' to enable.
disable_notification
Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.
message_thread_id
Topic ID (available for supergroups with forum functionality enabled)
entities
This allows you to copy pre-formatted text along with all its styles and simply specify the character range where a particular font should be applied. An example can be found in the tg_request under the corresponding field. The parameter must be a dictionary.
business_connection_id
The Business ID value is used when connecting the bot and displayed in channels. It should be provided if a bot token is included in the parameters and the message needs to be sent through a user account linked to the bot.
How to edit text in Telegram message
Please note!
The message editing function is available only for new and recently sent messages.
The time window during which message editing is allowed is determined by the messenger itself and depends on the load/activity of your bot; it may be shortened for editing.
According to the messenger’s technical support, the optimal time frame for editing a message is 48 hours.
tg_edit_message_text(platform_id, message_id, text, reply_markup, parse_mode, disable_web_page_preview, entities)
! platform_id
Telegram user ID to which a message should be sent *
! message_id
Message ID to be edited. This ID must be saved beforehand when sending the message.
! text
Message text
reply_markup
Button settings **
parse_mode
Bold and italic text formatting in the description ***. It can have values such as html, markdown, markdownV2.
disable_web_page_preview
Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".
entities
This allows you to copy pre-formatted text along with all its styles and simply specify the character range where a particular font should be applied. An example can be found in the tg_request under the corresponding field. The parameter must be a dictionary.
How to send a reaction to a message
tg_set_reaction(platform_id, message_id, reaction)
! platform_id
Telegram chat ID
! message_id
Message ID
! reaction
The required reaction is passed as a string.
How to edit an attachment description
tg_edit_message_caption(platform_id, message_id, caption, reply_markup, parse_mode, entities, show_caption_above_media)
! platform_id
Telegram user ID to which a message should be sent *
! message_id
Message ID to be edited
! caption
Description text
reply_markup
Button settings **
parse_mode
Bold and italic text formatting in the description ***. It can have values such as html, markdown, markdownV2.
entities
This allows you to copy pre-formatted text along with all its styles and simply specify the character range where a particular font should be applied. An example can be found in the tg_request under the corresponding field. The parameter must be a dictionary.
Example of passing the parameter:
entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":"https://,mavibot.ai"},{"offset":11,"length":9,"type":"strikethrough"},{"offset":21,"length":6,"type":"spoiler"},{"offset":29,"length":12,"type":"code"}]
The example shows only the dictionary, while the message text itself is assigned to a separate variable.
show_caption_above_media
Takes the value True; if this parameter is specified, the message text will be displayed above the attachment.
How to edit media attachments in a message
! platform_id
Telegram user ID to which a message should be sent *
! message_id
Message ID to be edited. This ID must be saved beforehand when sending the message.
! media
A dictionary describing the media file:
Example of a JSON dictionary to replace a previously sent photo:
media = '{"type": "photo", "media": "<file_to_send>"}'
where <file_to_send> is recommended to be the file_id obtained via the full Telegram webhook.
For more details, the parameters for the dictionary are described in the official Telegram documentation.
reply_markup
Button settings **
How to edit an inline keyboard in a message
You can edit only an inline keyboard.
How to copy a message
tg_copy_message(platform_id, from_chat_id, message_id, reply_to_message_id, reply_markup, parse_mode, protect_content, disable_notification, caption, message_thread_id, entities, show_caption_above_media)
! platform_id
Telegram user ID TO which a message should be copied *
! from_chat_id
Telegram user ID FROM which a message should be copied *
! message_id
Message ID to be copied
reply_to_message_id
Original message ID if the copied message is a comment
reply_markup
Button settings **
parse_mode
Bold and italic text formatting in the description ***.
It can have values such as html, markdown, markdownV2.
protect_content
Content protection flag. Pass any value except 0, False, or '' to enable.
disable_notification
Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.
caption -
Description up to 1024 characters.
message_thread_id
Topic ID (available for supergroups with forum functionality enabled)
entities
This allows you to copy pre-formatted text along with all its styles and simply specify the character range where a particular font should be applied. An example can be found in the tg_request under the corresponding field. The parameter must be a dictionary.
Example of passing the parameter:
entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":"https://mavibot.ai"},{"offset":11,"length":9,"type":"strikethrough"},{"offset":21,"length":6,"type":"spoiler"},{"offset":29,"length":12,"type":"code"}]
The example shows only the dictionary, while the message text itself is assigned to a separate variable.
show_caption_above_media
Takes the value True; if this parameter is specified, the message text will be displayed above the attachment.
How to forward a message
tg_forward_message(platform_id, from_chat_id, message_id, protect_content, disable_notification, message_thread_id)
! platform_id
Telegram user ID TO which a message should be sent *
! from_chat_id
Telegram user ID FROM which a message should be sent *
! message_id
Forwarding message ID
protect_content
Content protection flag. Pass any value except 0, False, or '' to enable.
disable_notification
Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.
message_thread_id
Topic ID (available for supergroups with forum functionality enabled)
How to delete a message
tg_delete_message(platform_id, message_id)
! Use this method to delete a message, including service messages, with the following restrictions:
A message can only be deleted if it was sent less than 48 hours ago.
Messages with dice in a private chat can only be deleted if they were sent more than 24 hours ago.
Bots can delete outgoing messages in private chats, groups, and supergroups.
Bots can delete incoming messages in private chats.
Bots with the can_post_messages permission can delete outgoing messages in channels.
If a bot is an administrator of a group, it can delete any message there.
If a bot has the can_delete_messages permission in a supergroup or channel, it can delete any message there.
! platform_id
Telegram user ID *
! message_id
Message ID to be deleted
How to delete multiple messages
tg_delete_messages(platform_id, message_ids)
! Use this method to delete a message, including service messages, with the following restrictions:
A message can only be deleted if it was sent less than 48 hours ago.
Messages with dice in a private chat can only be deleted if they were sent more than 24 hours ago.
Bots can delete outgoing messages in private chats, groups, and supergroups.
Bots can delete incoming messages in private chats.
Bots with the can_post_messages permission can delete outgoing messages in channels.
If a bot is an administrator of a group, it can delete any message there.
If a bot has the can_delete_messages permission in a supergroup or channel, it can delete any message there.
! platform_id
Telegram user ID
! message_ids
An array of message IDs to be deleted. Maximum of 100 items.
Example: message sending with Telegram API
Example: message editing with Telegram API
Example: message copying with Telegram API
Last updated











