Native request

It works only on Telegram.

Native request component also works like a Request, but these components are set up differently.

When using the GET request in the Native request, an empty {} object must be entered in the field for the request body.

When using the POST request in the Native Request, the user needs to select Platform, Method, and fill in the Request Body. If you skip the chat_id parameter for Telegram in the Request Body, the Native request will add them automatically. By default, these parameters will contain {{this_user.platform_id}}. This means that a request where these parameters are not specified will work for the user who will be on the screen with the request.

For example, the request body to send a sticker to a user who appears on the screen with the request may look like this:

{
"sticker": "12345"
}

If you need to specify a value other than {{this_user.platform_id}} in chat_id use the standard request body with all the specified parameters.

We forward the message to chat_id, {{this_user.platform_id}} is the ID of the user whose request will be triggered, you can also specify another value. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.

The remaining settings will be added by default, they will not be visible in the component.

If necessary, you can specify the variable name for the response body to save data from the server to the variable you specify instead of the standard variable last_native_request.

When the Request method is selected in the component, an active link appears in the settings leading to Telegram API documentation of the selected method.

Text Formatting in Native Request

Native Request supports formatting. In order to send formatted text via Native Request, add a tag or tags for formatting to Request Body. The tags should be the same as when formatting plain text.

Request Body parameters:

  • chat_id is a unique user identifier in the bot. We get it as the main {{this_user.platform_id}} variable. You can leave it unchanged, then the images will be sent to the user who got to the Native Request component in the bot. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.
  • text is the text that will be sent to the user.
  • parse_mode is a parameter for the text to come to the user in a formatted form. In our case, it should have the HTML value.
  • disable_web_page_preview disables link preview. If you remove this parameter, then the text, if there is a link in it, will come with a preview.

If you need to wrap strings, use the \n character, as in this example of Request Body:

{
    "chat_id": "{{this_user.platform_id}}",
    "text": "<b>This sentence should be in bold</b>\n<i>This sentence should be in italics</i>",
         "parse_mode": "HTML",
    "disable_web_page_preview": true
}

All the tags for text formatting are collected here:

Messages sent via a Native Request, as in these examples, will come to the bot as formatted text sent via the Message component.

Telegram provides a large number of methods with which you can interact with bot users. Many of them are already implemented in the builder in the form of components, but you can also do some specific things using API requests.

For example, we will send three images in one message using Native request. Method: sendMediaGroup.

Using this method, you can send several files of the same type: images, documents, video or audio.

In the bot, the sent images will look like this:

Required parameters for Request body:

  • chat_id is the unique identifier of the user in the bot. We get it as the main variable {{this_user.platform_id}}. You can leave it unchanged, then the images will be sent to the user who got to the Native request component in the bot. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.
  • media — links to images, for example, images from google drive. Try to change the links from the example to your own — the bot will receive images from the links that you specify.

Let's write Request body with these parameters:

{
"chat_id": "{{this_user.platform_id}}",
"media":[{
"type": "photo",
"media": "https://disk.yandex.ru/i/jC2Rq-TeuiXrGQ"},
{"type": "photo",
"media": "https://disk.yandex.ru/i/x6QRrK7lgdGgCA"},
{"type": "photo",
"media": "https://disk.yandex.ru/i/3KSERQbfbtBHoA"}]
}

And add it to the component settings:

Don't forget to save.

Now, when the component is activated, the bot will send three images at once.

Due to Telegram limitations, images can be cropped in a horizontal format.

Deleting the last message from a bot in Telegram

According to the Telegram rules, you cannot delete messages that were sent more than 48 hours ago.

Let's delete the last message from the bot with the Native Request.

1. In the Native Request component select the deleteMessage method from the drop-down list.

2. Add the Request body:

{
"chat_id": "{{this_user.platform_id}}",
"message_id": "{{lastMessageId}}"
}

Where:

  • chat_id — is where the message is forwarded to. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.
  • {{this_user.platform_id}} — ID of the user for whom the request will be triggered. You can leave it unchanged, then the request will be triggered for the user who has got to the Native request component in the bot.
  • message_id — is the message which will be deleted.
  • {{lastMessageId}} — ID of the last message in the bot.

How to delete a block of messages from a bot in Telegram

According to the Telegram rules, you can delete messages within 48 hours after sending.

Before deleting several messages in one block, it is necessary to write their ID using Assign a variable immediately after the messages. The last message ID should be output in the value of the Write Variable component:

{{lastMessageId}}

1. In the Native Request component, select the deleteMessages request method from the drop-down list.

2. Add variables with the message IDs to be deleted to the Request Body. The variables names can be anything, in the example we named the variables delete1 and delete2.

{
"chat_id": "{{this_user.platform_id}}",
"message_ids": ["{{delete1}}", "{{delete2}}"]
}

The other parameters of the Request Body are the following:

  • we delete messages from chat_id, {{this_user.platform_id}} is the ID of the user whose request will be triggered, you can also specify another value.
  • message_ids is the deleted messages ID.

Forwarding messages from a group/channel

Let’s forward the message in its original form from the channel/group using forwardMessage method in Native request.

This method can be used if you need to send an image and text in one block.

There can be only one image in the forwarded message. If there are more images, only the first one will come to the bot.

1. Add a bot to the group /channel from where the request will be sent, by an administrator with all rights.

2. Add the request body:

{
"chat_id": {{this_user.platform_id}},
"from_chat_id": "@channel_name",
"message_id": "23"
}

Where:

  • chat_id is where we forward the message. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.
  • {{this_user.platform_id}} — ID of the user for whom the request will be triggered. You can leave it unchanged, then the request will work for the user who got to Native request component in the bot.
  • from_chat_id — group/channel from where we forward the message.
  • Instead of @channel_name, there should be the name or ID of your channel/group.
  • message_id — message ID what we are forwarding. In our example, this is 23.

You can find out the message ID by right-clicking on the forwarded message in the channel/group and selecting Copy link to the message.

You will get a link of the form https://t.me/channel_name/23.

23 is the message ID. Let's add this ID to the request body, you don’t need the rest of the link.

3. Let's make Native request in the builder.

4. Make a save and test the bot. The message from the group/channel to the bot will come in this form:

If you want the message to come without the channel name, you can use the copyMessage method.

The Request body for this method will be the same as in the previous example, only the Request method changes.

Now a message will come to the bot without reference to the channel or group from where the message was forwarded.

Send a sticker

We will send a sticker to the user using Send Sticker method in Native Request.

This method can be used if you need to send the user a sticker message from the bot.

1. In Native Request component, select SendSticker request method from the drop-down list.

2. Add the Request body:

{
"chat_id": "{{this_user.platform_id}}",
"sticker": "54321"
}

Where 54321 is the ID of the sticker being sent. Sticker ID bot will help you find out the ID of any sticker.

How to make a button to go to a web application in Telegram

Such a button can be made using SendMessage method in Native request.

1. Add Request body to Native Request:

{
"PlatformId":"{{this_user.platform_id}}",
"chat_id":"{{this_user.platform_id}}",
"text":"Click on the button to go to the web bot",
"reply_markup":{
"inline_keyboard":[
     [
          {
             "text":"Go to",
             "web_app":{
                 "url": "https://docs.botmother.ru/article/41067 "
                    }
                }
           ]
       ]
   }
}

Where:

  • chat_id is where we forward the message. Without this parameter in the request body, only those users who got to the Native Request component in the bot will have their request triggered.
  • {{this_user.platform_id}} is a user ID for whom the request will be triggered. You can leave it unchanged, then the request will work for the user who got to Native request component in the bot.
  • text is the text in front of the buttons.

reply_markup is button settings, where:

  • text is the text on the button.
  • url is the address for clicking on the button.

3. Make a save and test the bot.

The message from the group / channel to the bot will come in this form:

You can add another object to the array of objects for the second or third button.
The request body for two buttons would be as follows:

{
  "platformId":"{{this_user.platform_id}}",
  "chat_id":"{{this_user.platform_id}}",
  "text":"Click the button to go to the web bot",
  "reply_markup":{
     "inline_keyboard":[
        [
           {
              "text":"EN",
              "web_app":{
                 "url": "https://docs.botmother.com/"
              }
           },
           {
              "text":"RU",
              "web_app":{
                 "url": "https://docs.botmother.ru/"
              }
           }
        ]
     ]
  }
}

You can use the widget link to your service support as the URL that opens when Web App is opened.

For example, for Chatra service, the link will be something like this:

https://chat.chatra.io/?isModern=true#hostId=12345&mode=widget&langOverride=en&lang=en

This link can be used in Request body in the URL field

This method will also help with widgets of other similar services.

How to pin a message in a bot

Pin the message at the top of the chat with PinChatMessage method in Native request.

1. Select PinChatMessage request method from the drop-down list in Native Request component.

2. Add the following Request Body if you need to pin a message from the user:

{
"chat_id": "{{this_user.platform_id}}",
"message_id": "{{lastUpdate.update.message_id}}"
}

This request body works if you need to pin a message from a bot.

   {
    "chat_id": "{{this_user.platform_id}}",
    "message_id": "{{last_telegram_message_id}}"
    }

How to send a round shape video in Telegram

To get a round shape video, you can use this bot.

Since this bot does not belong to Botmother, we are not responsible for its work.

Send the original video to the bot, taking into account certain restrictions that the bot will tell you about.

Please note that the uploaded video must be in the shape of a square. If your video has a different format, first change its size in any video editor.

Before you send a video to the bot, make sure that the video format does not exceed 640 by 640 pixels, and the size does not exceed 8 MB. The duration of the video should not be more than 60 seconds.

Then you need to send the received video to your bot. To do this, right-click on the video, select "Forward", then select the bot you want to forward the video to.

In the example, we will forward the video to the bot "My first bot".

When you send the video to your bot, go to the Users section in the builder, then open the variables of the user who forwarded the video.

The path to the desired file_id will be as follows: lastUpdate.update.video_note.file_id. In user variables, the desired file_id will be at the end of the variables list. Copy this video ID.

Go to the Builder section and add the Native Request component to the screen. In the Native request, select the sendVideoNote request method, the request body should be like this:

{
"chat_id": "{{this_user.platform_id}}",
"video_note": "12345"
}

Instead of 12345 in video_note, paste the file_id previously copied from variables.

The deliverability of such messages will be lower than text messages, regular videos or pictures deliverability because video clips can only be received by the users who have permission in their privacy settings to receive audio and video from everyone, not just from their contacts. The user can also block the receiving of such media files from a specific bot.

To the beginning ↑