Telegram bot
Add a Telegram bot to your groups and channels to copy their new messages into your organization as a dataset. Direct messages (DMs) that people send to the bot are copied too. The ingestion uses a bot token, so nobody logs in with a personal account. It only reads from Telegram. It never sends or changes anything there.
A bot cannot read messages sent before it joined a chat. To read a chat from its start, use the Telegram account integration.
Create the bot and store its token
- In Telegram, open @BotFather and send
/newbot. BotFather replies with the bot token. - In OSO, add the token as a secret in one of your environments.
- Add the bot to each group or channel you want to ingest. In a channel, the bot must be an admin.
Add an ingestion
- From your organization, open Integrations in the sidebar. On the Telegram bot tile, add an ingestion.
- Pick the environment and the secret that holds the token, and enter a dataset name.
- Click Add ingestion. OSO schedules the ingestion every hour. If the dialog says the schedule was not saved, set one in the Data Catalog.
The dialog lists what the ingestion reads and the limits below. Click What this ingests or Limits to open each list.
What the tables look like
| Table | One row per | Key |
|---|---|---|
messages | message, group post, channel post or DM | chat_id, message_id |
chats | group, channel or private chat | chat_id |
users | person or bot that sent a message | user_id |
bot_memberships | chat that added or removed the bot (status) | chat_id |
An edited message replaces its row, so messages shows the newest version.
messages has these columns:
text: the text, or the caption of a photo, video or file.content_type: one value per message.text,photo,video,animation,audio,voice,video_note,document,sticker,story,paid_media,poll,dice,location,venue,contact,game,invoice,giveawayorchecklist. A service message, such as a new member or a new chat title, isservice:<event>, for exampleservice:new_chat_members. A kind that Telegram added after this ingestion was written isunknown.- File details, for media only:
file_id,file_unique_id,file_name,mime_type,file_size,duration,width,height. The file itself is not downloaded. For a photo, the details are of its largest size. Paid media has no file details. - Forwards:
forward_origin_type(user,hidden_user,chatorchannel),forward_from_id(the user or chat id),forward_sender_name(for a user who hides their account),forward_dateandforward_from_message_id(for a channel post). - Threads and albums:
message_thread_id,is_topic_message(true in a forum topic) andmedia_group_id(the same for each photo or video of one album). - Replies:
reply_to_msg_id,quote_text(the quoted part) andexternal_reply_chat_id(a reply to a message in another chat). via_bot_id(a message sent through an inline bot),sender_chat_id(a message sent on behalf of a chat, for example by an anonymous admin) andhas_protected_content(the message cannot be forwarded or saved).entities: a JSON list of the links, mentions and formatting in the text, each withtype,offset,length,urlanduser_id.date,edit_date,sender_idandupdate_id.
What is not ingested
- Media files. The ingestion keeps the captions and file details (type, name, size) of photos, videos, files, voice and stickers. The files are not downloaded.
- Messages sent before the bot joined a chat.
- Deleted messages. Telegram does not tell a bot about a deletion, so a deleted message stays in the dataset.
- Reactions, poll votes and clicks on inline buttons.
- Role and status changes of other members. The service messages for joins and leaves are kept.
Limits
- Privacy mode. It is on by default. In a group, the bot then receives only
commands, replies to the bot and service messages. To receive every group
message, turn privacy mode off in BotFather (
/setprivacy), or make the bot an admin of the group. Remove the bot from the group and add it again after you change the setting. - 24 hours. Telegram keeps the updates for a bot for 24 hours. The ingestion must run at least once a day; it is scheduled every hour. If it does not run for more than 24 hours, for example because the secret is wrong or the schedule is paused, the messages of that gap are lost.
- One reader per token. Telegram gives each update to one reader. If another program reads updates with the same token, those updates are removed for this ingestion. Use a separate bot for each program.
- No webhook. The bot must have no webhook set. While a webhook is set, Telegram refuses to give updates to the ingestion.
- Older groups. A group that added the bot before memberships were recorded
shows in
bot_membershipsonly after its next message or membership change.