Native request
It works only on Telegram.
- How to send multiple images in one message →
- Deleting the last message from a bot →
- Forwarding messages from a group/channel →
- How to send a sticker →
- How to make a button to go to a web application in Telegram (web app) →
- How to pin a message in a bot →
- How to send a round shape video in Telegram →
Native request component also works like a Request, but these components are set up differently.
Unlike in Request, in Native request, the user selects Method and fill in Request body — for methods that send POST, for GET — an empty {} object must be written in the field for the request body.
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.
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.
- 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.
- {{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.
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.
- {{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.
- {{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.