Telegram

The Telegram handler in Bot Studio is responsible for managing Telegram bots. This handler leverages the Telegraf NPM package and uses the official Telegram API to handle bot functionalities.

Verifications

The origin server sends verification requests to the Telegram handler to validate the provided Telegram bot tokens. The handler uses the getMe method from the Telegram API to verify if a provided token is valid.

Activating Bots

When running a Telegram bot instance, the handler creates a new Telegraf client with a random webhook address, such as https://telegram.botstudioo.com/webhook/xxxxxxxxxx. This webhook address is more secure and unique compared to a static webhook address.

If you have defined a security signature for your bot, requests will always include a signature to ensure they are received from Telegram. Bot Studio creates a default signature for Telegram bots, and we recommend keeping it in your bot's configuration for security.

The client listens for all events defined in your functional system, such as the Message Event.

When your bot starts, it will ignore all pending updates (events sent while the bot was offline).

Receiving Events

When an event is received, the executor of the event will be the ID of the chat that sent the event. The variables received in this process include:

  • update_id: The ID of the update received from Telegram.
  • bot: Information related to your bot.
  • Event-specific variables: For instance, in message events, the message_id variable is always included. Check all variables received from each event here.

Executing Worker Nodes

Node names in Bot Studio are not opinionated. Each name references a specific feature. Each Telegram node has a worker function based on its name, corresponding to Telegram bot API. Bot Studio does not save node names in an opinionated manner; they are set according to the Telegram bot API. Examples include:

Find a list of all methods related to these nodes here.

Each node sends an API request to its corresponding endpoint. The request body for these API requests includes the data used in the node.

Advertisements

Advertisements are only shown if the bot is not upgraded to remove ads.

After sending API requests with worker nodes, the handler checks if the request has a valid chat ID where an advertisement message can be sent. There is a 1 in 8 random chance of showing an advertisement. If all conditions are met, an advertisement message is sent to the chat.

Advertisements are designed to be non-intrusive.