Telegram Data Transformation
Telegram Data Transformation receives a Telegram message as it reaches your bot and extracts the data a flow usually needs: which chat it was written in, who wrote it, when and what it says. It can also prepare that data in the right shape to reply to the same chat.
Place it right after a Telegram Webhook, so the following steps work with simple fields instead of the full Telegram message.
When to use it
- Saving to a sheet or a database who writes to the bot, from which chat and what they ask for.
- Separating the text of the message from its attachments to handle them in different ways.
- Preparing the chat identifier and the text to send a reply with Telegram Message.
Configuration
The component needs a Telegram bot API credential with your bot’s token. See Credentials.
| Field | What it does |
|---|---|
| Credential (required) | The Telegram bot credential. |
| Raw Update (required) | The message received. Connect the Data output of a Telegram Webhook. |
| Operation | What it does with the message. Normalize Data (default): extracts the message data. Prepare Output Payload: gets it ready for a reply. |
The component works with messages written in chats and channels, also when they are edited. If what arrives does not contain a message, it fails.
Output
The Transformed Data output delivers the message data.
With Normalize Data:
| Field | What it contains |
|---|---|
chat_id | The identifier of the chat it was written in. |
message_id | The number of the message within the chat. |
from_id and from_username | The identifier and username of whoever wrote it. |
timestamp | The date and time of the message. |
text and original_text | The text of the message, or the caption if it is a file, on a single line. |
document, photo, audio, video, animation, sticker, contact | The message’s attachments, if any. |
is_edited | Whether the message is an edit of an earlier one, in a chat or a channel. |
is_channel_post | Whether the message was published in a channel. |
is_pinned | Whether the message is Telegram’s notice that a message was pinned in the chat. |
With Prepare Output Payload, only the data needed to reply: chat_id, message_id and text and, if the message carried a contact, its phone number and name. Empty fields are left out.
To read a specific field, connect the output to Get Value By Key.
Example
Floristería Camelia receives orders through its Telegram bot and wants to record them:
- Add a Telegram Webhook with the bot’s credential.
- Connect its Data output to Raw Update on Telegram Data Transformation, with the same credential and Operation set to Normalize Data.
- Connect Transformed Data to a component that saves the data, for example a spreadsheet or a database.
For each message, the flow saves the user who writes, the date and the text of the order, such as “A bouquet of roses for Friday”.
Good practices
- Use the same bot credential in Telegram Webhook and in this component.
- Test the flow in the editor with a sample message in the Telegram Webhook before publishing it.
Related components
- Telegram Webhook: receives the bot’s messages.
- Telegram Message: sends the reply to the chat.
- Get Value By Key: reads a specific field of the data.