Native request
It works only on Telegram.
- How to send multiple images in one message →
- 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 →
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.
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://drive.google.com/file/d/1Y09-df77xdYlpsze2rpqWGCbkms4HNpl/view?usp=sharing"}, {"type": "photo", "media": "https://drive.google.com/file/d/1GXpNm0bqtKB6MuRfMzwxO5Dj3iKQzJgY/view?usp=sharing"}, {"type": "photo", "media": "https://drive.google.com/file/d/1bsjPW2M75yCgeokn3j6_PixQY_hsMUUc/view?usp=sharing"}] }
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.
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}}" }