Telegram Bot – Triggers & Methods

Estimated reading time: 27 min

A Telegram bot does not pull messages.
Telegram always pushes messages to a single HTTPS URL called the webhook.

Wiresk receives these updates through the HTTP Trigger Routing Key.
Every message sent to the bot, group, or channel is forwarded to that Routing Key according to Telegram’s rules.

Telegram sends updates only in these three cases.

Direct messages to the bot.
Group messages when the bot is a member of the group.
Channel posts when the bot is an administrator of the channel.

If the bot is not present in the chat, or not an admin in a channel, Telegram will not send updates.

Telegram allows only one webhook per bot. The existing webhook must be deleted or overwritten before setting a new one.

This operation tells Telegram where to deliver all incoming updates.
The webhook must point to the Routing Key URL of your Wiresk HTTP Trigger.

Endpoint: https://api.telegram.org/bot<token>/setWebhook

Required parameter: url = <Wiresk Routing Key URL>

Configuration inside Wiresk:

  • Connection: Standard HTTP no Authentication
  • URL: https://api.telegram.org/bot<token>/setWebhook
  • Method: POST
  • Query Parameters: url = <Wiresk Routing Key URL>
  • Headers: Not required.
  • Body: Leave empty.

When executed, Telegram links your bot to Wiresk. Every message received by the bot in allowed contexts will be forwarded to your Flow.

This operation retrieves the status of the current webhook.
It is useful to confirm that the webhook is set correctly or to investigate errors.

Endpoint: https://api.telegram.org/bot<token>/getWebhookInfo

Configuration inside Wiresk:

  • Connection: Standard HTTP no Authentication
  • URL: https://api.telegram.org/bot<token>/getWebhookInfo
  • Method: GET
  • Query Parameters: Leave empty.
  • Headers: Not required.
  • Body: Leave empty.

The response includes the current webhook URL, pending updates count, last error date, last error message, and IP address.
If the webhook field is empty, no webhook is active.

This operation removes the active webhook.
It is required when switching between Flows, replacing the Routing Key, or moving from testing to production.

Endpoint: https://api.telegram.org/bot<token>/deleteWebhook

Configuration inside Wiresk:

  • Connection: Standard HTTP no Authentication
  • URL: https://api.telegram.org/bot<token>/deleteWebhook
  • Method: POST
  • Query Parameters: Leave empty.
  • Headers: Not required.
  • Body: Leave empty.

After deletion, Telegram stops sending updates until setWebhook is used again.

In Wiresk, the Chat ID will be use in Methods settings to identify your Telegram bot/channel/group.
To use the Telegram Bot Methods:
– First add the Telegram Bot to your Telegram Group/Channel where you want to send the message or interact with
– Promote the bot to admin using either the Telegram Mobile Application(recommended) or the Telegram Desktop Application.

Messages and files are kept in different locations. A file on the Telegram servers is identified by a file_id, consisting of a lengthy string of characters like this: AgADBAADZRAxGyhM3FKSE4qKa-RODckQHxsoABDHe0BDC1GzpGACAAEC.

  • Open the chat with the user you want to get the user ID from.
  • Forward a message of that user to userinfobot (search @userinfobot)
  • Userinfobot will send back a message with the user ID.
  • Keep it for later use in your Flows.

By default, bots are able to message their users at no cost – but have limitations on the number of messages they can broadcast in a single interval:

  • In a single chat, avoid sending more than one message per second. We may allow short bursts that go over this limit, but eventually you’ll begin receiving 429 errors.
  • In a group, bots are not be able to send more than 20 messages per minute.
  • For bulk notifications, bots are not able to broadcast more than about 30 messages per second, unless they enable paid broadcasts to increase the limit.

What your automation will do…

Telegram bots are capable of not only exchanging plain text messages, but also various other types of messages like images and videos. This includes managing files in the messages.
 
Sending files
There are three ways to send files (photos, stickers, audio, media, etc.):
If the file is already stored somewhere on the Telegram servers, you don’t need to reupload it: each file object has a file_id field, simply pass this file_id as a parameter instead of uploading. There are no limits for files sent this way.
Provide Telegram with an HTTP URL for the file to be sent. Telegram will download and send the file. 5 MB max size for photos and 20 MB max for other types of content.
Via uploading your own file. 10 MB max size for photos, 50 MB for other files.

Sending by file_id
It is not possible to change the file type when resending by file_id. I.e. a video can’t be sent as a photo, a photo can’t be sent as a document, etc.
It is not possible to resend thumbnails.
Resending a photo by file_id will send all of its sizes.
file_id is unique for each individual bot and can’t be transferred from one bot to another.
file_id uniquely identifies a file, but a file can have different valid file_ids even for the same bot.
 
Sending by URL
When sending by URL the target file must have the correct MIME type (e.g., audio/mpeg for sendAudio, etc.).
In sendDocument, sending by URL will currently only work for GIFPDF and ZIP files.
To use sendVoice, the file must have the type audio/ogg and be no more than 1MB in size. 1-20MB voice notes will be sent as files.
 
Upload local file
Wiresk use Base64 encoding format to transfer files from your computer.
Choose the method send by “File Data” to send files via Base64.
For more details Refer to Base64 encoding documentation.
Important 01 Telegram Bot - Triggers & Methods