# 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)**&#x20;

Parameters:

<table><thead><tr><th width="324.87890625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>Telegram user ID to which a message should be sent <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> text</strong></td><td>Message text</td></tr><tr><td><strong>client_message_id</strong> </td><td>Message ID to be quoted</td></tr><tr><td><strong>reply_markup</strong></td><td>Button settings  <a href="/pages/Hnbda5NTFjVq0C62bPTZ#how-to-delete-reply-buttons"><strong>**</strong></a></td></tr><tr><td><strong>parse_mode</strong></td><td>Bold and italic text formatting in the description<a href="/pages/wMXXeZgtnAnTVGr1tWVF#markdown-markup"> <strong>***</strong></a><strong>.</strong> It can have values such as html, markdown, markdownV2.</td></tr><tr><td><strong>disable_web_page_preview</strong></td><td>Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".</td></tr><tr><td><strong>protect_content</strong></td><td>Content protection flag. Pass any value except 0, False, or '' to enable.</td></tr><tr><td><strong>disable_notification</strong></td><td>Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.</td></tr><tr><td><strong>message_thread_id</strong></td><td>Topic ID (available for supergroups with forum functionality enabled)</td></tr><tr><td><strong>entities</strong></td><td>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.</td></tr></tbody></table>

<details>

<summary><mark style="color:orange;"><strong>Detailed example</strong></mark></summary>

Let’s consider a simple example with a set of required parameters:

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

The platform\_id specifies the identifier of a specific client.

See the same example, but using variables:

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

In this example, the variable `soob` will contain the server’s response after sending a message.

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

If you save the `message_id` from the received response, it will allow you to later work with this message (edit, delete, forward, comment).

Difficulties often arise when using all the parameters. Let’s consider the following example:

* First, declare all the parameters used in the function. Remember, parameters can be passed not only as values but also as variables, which is often more convenient and clearer. Variables such as platform\_id and client\_message\_id can be obtained from the client’s profile card. \
  &#x20;**platform\_id** — Telegram client ID to which the message should be sent [**\***](#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii)\ <mark style="color:green;">>We will reply in the same chat where the client writes</mark>

  **text** - message text. \ <mark style="color:green;">>We use text formatting - for example, bold highlighting.</mark>

  **client\_message\_id** - Message ID to be quoted\ <mark style="color:green;">>In chats, this variable is assigned its value automatically.</mark>\
  **reply\_markup** — button settings [**\*\***](#kak-propisyvat-knopki-v-parametre-reply_markup)**.** \ <mark style="color:green;">>Let’s assign it to the variable opts.</mark>\
  **parse\_mode** — Bold and italic text formatting in the description [**\*\*\***](#kak-ispolzovat-razmetku-teksta-markdown-v-parametre-parse_mode)**.** It can have values such as html, markdown, markdownV2. The characters used for formatting message text are described[ here](/chatbot/builder/telegram_messages.md). \ <mark style="color:green;">>Let's use markdown.</mark> \
  **disable\_web\_page\_preview -** Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".\ <mark style="color:green;">>We can pass any value since the message text does not contain a link.</mark>\
  **protect\_content** — Content protection flag. Pass any value except 0, False, or '' to enable.\ <mark style="color:green;">>We don’t need content protection, so we’ll pass an empty string</mark> <mark style="color:green;">''.</mark>\
  **disable\_notification** —  Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.\ <mark style="color:green;">>A notification is a pop-up window displaying the message text. Let’s enable it.</mark>
* Next, we assemble the function. Remember to assign the function to a variable — this will allow you to track the message sending status.

<div data-with-frame="true"><figure><img src="/files/FQsbXlAoqIVbc4YtF80e" alt="" width="563"><figcaption><p>The "Calculator" field</p></figcaption></figure></div>

Here’s what we got:\
After the client sends us the keyword test, we reply by quoting his message.

In `ok` we see the sending status; next comes information about the message itself — its ID, sender data, and content.

Example with the **entities** parameter\
You can store the original string in a variable, as shown below:

`text = "qwert asdfg zxcvb poiuy lkjhg 12345"`\
\
You should write the parameter as a dictionary with the data and specify the desired formatting by indicating the fonts:

`entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":"``    `<mark style="color:red;">**`https://mavibot.ai"}`**</mark>`,{"offset":11,"length":9,"type":"strikethrough"},{"offset":21,"length":6,"type":"spoiler"},{"offset":29,"length":12,"type":"code"}]`

Pass the parameter last in the function you use. The parameter can be passed to both the tg\_send\_message and tg\_send\_message\_1 functions:

`x = tg_send_message(platform_id, text, None, None, None, False, False, False, None, entities`)

</details>

{% hint style="info" %}
To assign text with line breaks to a variable, specify the value as follows:

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

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

<table><thead><tr><th width="288.94140625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> token</strong></td><td>Telegram bot token obtained from BotFather</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>Telegram user ID to which a message should be sent <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> text</strong></td><td>Message text</td></tr><tr><td><strong>client_message_id</strong></td><td>Message ID to be quoted</td></tr><tr><td><strong>reply_markup</strong></td><td>Button settings  <a href="/pages/Hnbda5NTFjVq0C62bPTZ#how-to-delete-reply-buttons"><strong>**</strong></a></td></tr><tr><td><strong>parse_mode</strong></td><td>Bold and italic text formatting in the description <a href="/pages/wMXXeZgtnAnTVGr1tWVF"><strong>***</strong></a><strong>.</strong> It can have values such as html, markdown, markdownV2.</td></tr><tr><td><strong>disable_web_page_preview</strong></td><td>Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".</td></tr><tr><td><strong>protect_content</strong></td><td>Content protection flag. Pass any value except 0, False, or '' to enable.</td></tr><tr><td><strong>disable_notification</strong></td><td>Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.</td></tr><tr><td><strong>message_thread_id</strong> </td><td>Topic ID (available for supergroups with forum functionality enabled)</td></tr><tr><td><strong>entities</strong></td><td>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.</td></tr><tr><td><strong>business_connection_id</strong></td><td>The <strong>Business ID</strong> 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.</td></tr></tbody></table>

<details>

<summary>Example</summary>

Example of passing the parameter:\
`entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":"`<mark style="color:red;">**`https://mavibot.ai"},`**</mark>`{"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.

</details>

## How to edit text in Telegram message

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

The message editing function is available only for new and recently sent messages. <br>

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

According to the messenger’s technical support, the optimal time frame for editing a message is 48 hours.
{% endhint %}

tg\_edit\_message\_text(platform\_id, message\_id, text, reply\_markup, parse\_mode, disable\_web\_page\_preview, entities)

<table><thead><tr><th width="270.03125">Параметр</th><th>Описание</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>Telegram user ID to which a message should be sent <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>Message ID to be edited. This ID must be saved beforehand when sending the message.</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> text</strong></td><td>Message text</td></tr><tr><td><strong>reply_markup</strong></td><td>Button settings  <a href="/pages/Hnbda5NTFjVq0C62bPTZ#how-to-delete-reply-buttons"><strong>**</strong></a></td></tr><tr><td><strong>parse_mode</strong></td><td>Bold and italic text formatting in the description <a href="/pages/wMXXeZgtnAnTVGr1tWVF"><strong>***</strong></a><strong>.</strong> It can have values such as html, markdown, markdownV2.</td></tr><tr><td><strong>disable_web_page_preview</strong> </td><td>Show link preview. To disable it, pass 1; otherwise, pass 0 or leave it empty "".</td></tr><tr><td><strong>entities</strong></td><td>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.</td></tr></tbody></table>

## How to send a reaction to a message

tg\_set\_reaction(platform\_id, message\_id, reaction)

<table><thead><tr><th width="305.015625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> platform_id</td><td>Telegram chat ID</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark> message_id</td><td>Message ID</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark> reaction</td><td>The required reaction is passed as a string.</td></tr></tbody></table>

<details>

<summary>Example</summary>

Code example for copying:

react = tg\_set\_reaction(platform\_id, 1556, '👌')

Example in the calculator:

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

</details>

## How to edit an attachment description

**tg\_edit\_message\_caption(platform\_id, message\_id, caption, reply\_markup, parse\_mode, entities, show\_caption\_above\_media)**

<table><thead><tr><th width="305.015625">Parameter </th><th>Descritption</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> platform_id</td><td>Telegram user ID to which a message should be sent <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark> message_id</td><td>Message ID to be edited</td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> caption</strong></td><td>Description text</td></tr><tr><td><strong>reply_markup</strong></td><td>Button settings <a href="#kak-propisyvat-knopki-v-parametre-reply_markup"><strong>**</strong></a></td></tr><tr><td><strong>parse_mode</strong></td><td>Bold and italic text formatting in the description<a href="/pages/wMXXeZgtnAnTVGr1tWVF"> <strong>***</strong></a><strong>.</strong>  It can have values such as html, markdown, markdownV2.</td></tr><tr><td><strong>entities</strong> </td><td><p>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.<br><br>Example of passing the parameter:<br><code>entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":"</code><mark style="color:red;"><strong><code>https://,mavibot.ai"}</code></strong></mark><code>,{"offset":11,"length":9,"type":"strikethrough"},{"offset":21,"length":6,"type":"spoiler"},{"offset":29,"length":12,"type":"code"}]</code></p><p></p><p>The example shows only the dictionary, while the message text itself is assigned to a separate variable.</p></td></tr><tr><td><strong>show_caption_above_media</strong></td><td>Takes the value True; if this parameter is specified, the message text will be displayed above the attachment.</td></tr></tbody></table>

## How to edit media attachments in a message

<table><thead><tr><th width="270.03125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>Telegram user ID to which a message should be sent <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>Message ID to be edited. This ID must be saved beforehand when sending the message. </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> media</strong></td><td><p>A dictionary describing the media file:<br><em>Example of a JSON dictionary to replace a previously sent photo:</em><br><code>media = '{"type": "photo", "media": "&#x3C;file_to_send>"}'</code></p><p></p><p>where &#x3C;file_to_send> is recommended to be the file_id obtained via the full <a href="/pages/rxLQ6GbBnHPOssk8NQNx">Telegram webhook</a>. </p><p></p><p>For more details, the parameters for the dictionary are described in the official <a href="/pages/djOGHQf8Ip8VkuLqL455">Telegram documentation</a>. </p></td></tr><tr><td><strong>reply_markup</strong></td><td>Button settings <a href="#kak-propisyvat-knopki-v-parametre-reply_markup"><strong>**</strong></a></td></tr></tbody></table>

## **How to edit an inline keyboard in a message**

<table><thead><tr><th width="270.03125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong></td><td>Telegram user ID to which a message should be sent <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>Message ID to be edited. This ID must be saved beforehand when sending the message. </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> reply_markup</strong></td><td>Button settings <a href="#kak-propisyvat-knopki-v-parametre-reply_markup"><strong>**</strong></a></td></tr></tbody></table>

{% hint style="warning" %}
You can edit only an inline keyboard.
{% endhint %}

<details>

<summary><strong>Example: message editing with Telegram API</strong></summary>

You can find a detailed example of working with Telegram API functions for editing messages below.&#x20;

</details>

## 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)**

<table><thead><tr><th width="270.03125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td> <mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>Telegram user ID TO which a message should be copied <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> from_chat_id</strong> </td><td>Telegram user ID FROM which a message should be copied <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>Message ID to be copied</td></tr><tr><td><strong>reply_to_message_id</strong> </td><td>Original message ID if the copied message is a comment</td></tr><tr><td><strong>reply_markup</strong> </td><td>Button settings <a href="#kak-propisyvat-knopki-v-parametre-reply_markup"><strong>**</strong></a></td></tr><tr><td><strong>parse_mode</strong></td><td><p>Bold and italic text formatting in the description <a href="/pages/wMXXeZgtnAnTVGr1tWVF"><strong>***</strong></a><strong>.</strong></p><p>It can have values such as html, markdown, markdownV2.</p></td></tr><tr><td><strong>protect_content</strong></td><td>Content protection flag. Pass any value except 0, False, or '' to enable.</td></tr><tr><td><strong>disable_notification</strong> </td><td>Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.                          </td></tr><tr><td><strong>caption</strong> - </td><td>Description up to 1024 characters.</td></tr><tr><td><strong>message_thread_id</strong> </td><td>Topic ID (available for supergroups with forum functionality enabled)</td></tr><tr><td><strong>entities</strong> </td><td>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.<br><br>Example of passing the parameter: <br><code>entities = [{"offset":0,"length":5,"type":"bold"},{"offset":6,"length":4,"type":"text_link","url":</code><mark style="color:red;"><strong><code>"https://mavibot.ai"}</code></strong></mark><code>,{"offset":11,"length":9,"type":"strikethrough"},{"offset":21,"length":6,"type":"spoiler"},{"offset":29,"length":12,"type":"code"}]</code>  <br><br>The example shows only the dictionary, while the message text itself is assigned to a separate variable.</td></tr><tr><td><strong>show_caption_above_media</strong> </td><td>Takes the value True; if this parameter is specified, the message text will be displayed above the attachment.</td></tr></tbody></table>

## How to forward a message

**tg\_forward\_message(platform\_id, from\_chat\_id, message\_id, protect\_content, disable\_notification,** **message\_thread\_id)**&#x20;

<table><thead><tr><th width="312.0703125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>Telegram user ID TO which a message should be sent <a href="#gde-vzyat-platform_id-dlya-otpravki-uvedomlenii"><strong>*</strong></a></td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> from_chat_id</strong></td><td>Telegram user ID FROM which a message should be sent <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>Forwarding message ID</td></tr><tr><td><strong>protect_content</strong></td><td>Content protection flag. Pass any value except 0, False, or '' to enable.</td></tr><tr><td><strong>disable_notification</strong></td><td>Sound notification flag (default: 0). Pass 1 to disable notification, 0 to enable it.</td></tr><tr><td><strong>message_thread_id</strong> </td><td>Topic ID (available for supergroups with forum functionality enabled)</td></tr></tbody></table>

## How to delete a message

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

<mark style="color:red;">**!**</mark> 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.&#x20;

<table><thead><tr><th width="294.3203125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark><strong> platform_id</strong> </td><td>Telegram user ID <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>Message ID to be deleted</td></tr></tbody></table>

## **How to delete multiple messages**

tg\_delete\_messages(platform\_id, message\_ids)

<mark style="color:red;">**!**</mark> 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.&#x20;

<table><thead><tr><th width="288.06640625">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>!</strong></mark> platform_id</td><td>Telegram user ID </td></tr><tr><td><mark style="color:red;"><strong>!</strong></mark> message_ids</td><td>An array of message IDs to be deleted. Maximum of 100 items.</td></tr></tbody></table>

## **Example: message sending with Telegram API**

<details>

<summary>Code example for copying</summary>

Example 1

```
/*It’s convenient to define the text in a variable beforehand*/
text='Writing-writing-witing text'
/*Send a message function*/
soob=tg_send_message(platform_id, text)
/*Save the sent message ID*/
soob_id=soob['result']['message_id']

```

Example 2

```
id_group=-1001847103100
text='Testing message sending via API method. For example, *bold text*'
opts = {"inline_keyboard": [[{"text": "👍","callback_data":1}, {"text": "👎","callback_data":2}]]}
disable_web_page_preview=1
protect_content=''
disable_notification=1
parse_mode='markdown'
soob=tg_send_message(id_group, text,client_message_id, opts, parse_mode, disable_web_page_preview, protect_content, disable_notification) 


```

</details>

## **Example: message editing with Telegram API**

<details>

<summary>Example of configuration</summary>

So, let’s send ourselves a message with an inline keyboard:

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

Next, edit the message text:

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

And edit the buttons:

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

Let’s try to edit a message with an image. To do this, send a message with an image and save the sent message ID. Read the detailed instructions on how to get the image URL [here](/chatbot/messengers/telegram/api/messages.md):&#x20;

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

Now, let's edit the image and its description:

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

</details>

<details>

<summary>Code example for copying</summary>

```
/*It’s convenient to define the parameters in a variable beforehand.*/
text='What package would you like to choose?'
opts = {"inline_keyboard": [[{"text": "Package 1","callback_data":1}, {"text": "Package 2","callback_data":2}]]}
/*Send message function*/
soob=tg_send_message(platform_id, text, None, opts)
/*Save the sent message ID*/
soob_id=soob['result']['message_id']

/*Edit the message*/
text='What package are you interested in?'
tg_edit_message_text(platform_id, soob_id, text, opts)  

/*Edit the inline keyboard*/
opts = {"inline_keyboard": [[{"text": "Standard","callback_data":1}, {"text": "Premium","callback_data":2}]]}
tg_edit_message_reply_markup(platform_id, soob_id, opts)


/*Send image with the decription*/
soob=tg_send_photo(platform_id, "AgACAgIAAxkBAAIPpWO4T7jhOgYHq6uR8rjnq9rIvBs-AAJlwDEb5fHASaGdhzgWjyn7AQADAgADeAADLQQ", "This is an image")
/*Save the sent message ID*/
soob_id=soob['result']['message_id']

/*Edit the image*/
media='{"type": "photo", "media": "AgACAgIAAxkBAAIPrmO4UiH7Tazqn-3IbFVzPKNsVEZmAAJ1wDEb5fHASWcNXKah-egvAQADAgADeQADLQQ"}'
tg_edit_message_media(platform_id, soob_id, media)
/*Edit the image description*/
tg_edit_message_caption(platform_id, soob_id, 'This is ME!')
```

</details>

## **Example: message copying with Telegram API**

<details>

<summary>Example</summary>

Let's send a message and save its ID.

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

And copy the previously sent message.

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

</details>

<details>

<summary>Code example for copying</summary>

```
/*It’s convenient to define the parameters in a variable beforehand.*/
text='What package would you like to choose?'
opts = {"inline_keyboard": [[{"text": "Package 1","callback_data":1}, {"text": "Package 2","callback_data":2}]]}
/*Send message function*/
soob=tg_send_message(platform_id, text, None, opts)
/*Save the sent message ID*/
soob_id=soob['result']['message_id']


/*Copy the sent message*/
tg_copy_message('5081438490', '1840834360', soob_id, None, opts, None, None, 1)
```

</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/messages.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.
