Developer docs

Bots and the Bot API

On this page

Bots are ordinary accounts driven by a program. A bot either speaks the Telvoro protocol directly, or uses the Telegram-compatible HTTP Bot API, so most existing bot frameworks work by changing only their API base URL.

This page collects the bot sections of the protocol specification (§6 Bots and §20 Member management, join requests and the admin Bot API). Payments for bots (Stars invoices) are in §17.5; mini apps are described in Mini apps.

6. Bots

Create a bot as a user: BotsService/CreateBot(name, username) → token (<bot_id>:<secret>). The bot then either:

  • speaks this protocol after AuthService/ImportBotAuthorization(token) and receives messages as normal updates plus callback_query / inline_query; or
  • uses the Telegram-compatible HTTP Bot API at https://<host>/bot<token>/<method>, see BOT_API.md. Most Telegram bot frameworks work by changing only their API base URL.

Users interact with bots through commands (/start), inline keyboards (MessagesService/GetCallbackAnswer) and reply keyboards.

Bot API notes on reactions and privacy:

  • setMessageReaction(chat_id, message_id, reaction, is_big): reaction is a list of ReactionType ({"type":"emoji","emoji":"👍"}, {"type":"custom_emoji", "custom_emoji_id":"…"}) that replaces the bot’s reactions; an empty or missing list removes them. Like Telegram, a bot may set one reaction, a custom emoji only if it is already on the message, and never a paid one.
  • Bots see users through the same privacy rules as anyone else (photo, bio, last seen…), and sendVoice / sendVideoNote to a premium user who restricted voice messages fails with VOICE_MESSAGES_FORBIDDEN.

20. Member management, join requests and the admin Bot API

Built-in anti-spam for groups stays minimal on purpose: the only built-in gate is join-request approval. Everything else (captcha bots, spam filters, warn/mute/ban policies, welcome messages, channel management) is left to third-party admin bots through a Telegram-compatible Bot API, so existing frameworks (python-telegram-bot, aiogram, grammY, telegraf) and Rose/Combot-style bots work by changing the base URL. Every Bot API method below calls the same service method a user’s client calls, so the same permission checks apply (requireRight, outranks, rightsSubset, the moderation Gate/BotGate, requireCap); there is no bot-only path.

20.1 Rights

TelegramTelvoro (AdminRights)
can_change_infochange_info
can_post_messages / can_edit_messages (channels)post_messages / edit_messages
can_delete_messagesdelete_messages
can_restrict_membersban_users
can_invite_usersinvite_users
can_pin_messagespin_messages
can_promote_membersadd_admins
is_anonymousanonymous
can_manage_topicsmanage_topics (also: change_info or pin_messages, as before)
can_manage_chat, can_manage_video_chatsevery admin (reported true)
can_post/edit/delete_stories, can_send_welcome_messagesno stories / welcome messages: false

Who may act on whom (unchanged rules, now reachable from the Bot API): the owner can’t be banned, restricted or demoted; an admin may demote, ban or edit only admins they promoted (inviter_id), unless they are the owner; a promoter grants only rights they hold (rightsSubset, including anonymous). Bot API can_be_edited = the bot promoted that admin.

20.2 Restrictions and timed bans

  • ChatPermissions gained Telegram’s granular sending permissions (send_photos, send_videos, send_audios, send_documents, send_voice_notes, send_video_notes, send_polls, send_other = stickers/GIFs/inline/cards, manage_topics) with granular = true. A value written by an older client (granular false) is read as “every media kind follows send_media”; the server always stores and returns the granular form with send_media = any media kind allowed. send_links is Bot API can_add_web_page_previews. Location and contact need only send_messages.
  • RestrictMember(chat_id, user_id, permissions, until_date) (groups; ban_users): the member’s effective permission is the chat defaults AND their restriction. All-true permissions lift it. A restricted user who isn’t in the chat is kept (role LEFT, restricted), and the restriction survives leaving and rejoining (Telegram). Admins can’t be restricted (promote/demote first).
  • RemoveMember(ban: true, until_date, revoke_messages). until_date (unix ms) < 30 s or

    366 days away means forever (Telegram). revoke_messages also deletes the user’s messages in the chat (up to 10 000, needs delete_messages; Telegram’s deleteParticipantHistory). A removed user loses access to the history in every case.

  • Expiry: posting checks a restriction’s until_date exactly; a sweeper (every 10 s, in the scheduler loop) lifts expired bans (→ LEFT) and restrictions.
  • Errors on sending: CHAT_WRITE_FORBIDDEN (no send_messages, links), or per kind CHAT_SEND_PHOTOS_FORBIDDEN, …_VIDEOS_…, …_AUDIOS_…, …_DOCS_…, …_VOICES_…, …_ROUNDVIDEOS_…, …_POLLS_…, …_STICKERS_…, …_GIFS_…, …_MEDIA_… (Telegram’s types; the Bot API answers “Bad Request: not enough rights to send photos to the chat”).

20.3 Join requests

  • Where they come from. A link created with creates_join_request (no usage limit allowed, as in Telegram), or a public group/channel with “Approve new members” (ToggleJoinRequest, ban_users; ChatFull.join_by_request). JoinByInvite / JoinChat then file a request and answer INVITE_REQUEST_SENT (400) instead of joining; repeating it while pending gives the same answer. CheckInviteLink returns request_needed and request_pending. Bots can’t request; banned users get USER_BANNED_IN_CHANNEL. Limits: cap(join_public), the join budget, and at most 200 pending requests per user.
  • Who handles them. Admins with invite_users (Telegram’s right for approve/decline): GetJoinRequests(chat_id, invite_hash?, query?) (newest first, with the requester’s bio as seen by that admin), HideJoinRequests(user_ids | all, approve, invite_hash?) (up to 100 listed users or 1000 per “all” call). ChatFull.pending_join_requests + recent_requesters (3) for those admins, and UserEvent.pending_join_requests{chat_id, count, recent_requesters} whenever the list changes (Telegram updatePendingJoinRequests).
  • Approval adds the user (inviter_id = the approver, link usage counted), posts the service message joined_by_request (groups) and the user gets dialog_added like any join. Declining is silent for the user, as in Telegram. Joining by any other route settles the request.
  • Expiry. Telegram documents no expiry for pending requests; Telvoro drops them after 30 days (JoinRequestTTL) so an unattended queue can’t grow forever. Expired requests are invisible at once and deleted by the sweeper; the user may request again.
  • Bot DM window (Bot API ChatJoinRequest.user_chat_id): an admin bot with invite_users that received chat_join_request may message the requester even though they never started it — the single exception to BOT_CANT_INITIATE. The window is 5 minutes, closes when the request is approved or declined, allows at most 5 messages, and a (bot, user) pair gets one window per 24 h. Once the user writes to the bot (or grants write access) the chat is an ordinary bot chat. The check runs in canPost, so it holds for bots on the native protocol too.

20.4 Invite links

ExportInviteLink(name, expire_at, usage_limit, creates_join_request, primary); primary replaces my primary link (Bot API exportChatInviteLink). GetInviteLinks (mine; other admins’ with add_admins), EditInviteLink(hash, name?, expire_at?, usage_limit?, creates_join_request?, revoke): the creator or the owner; the primary link can only be revoked, and revoking it makes a new primary link. InviteLink carries name, creates_join_request, primary, revoked, creator_id, created_at, pending_requests. Links stop working when their creator loses the right (unchanged). In Bot API objects, other admins’ links are shown with the end replaced by “…” (Telegram).

20.5 Bot updates

UpdateSent toDefault
my_chat_memberthe bot whose own membership changed (added, promoted, demoted, restricted, banned, left)on
chat_memberadmin bots of the chat, for anyone else’s change (join, leave, ban, restrict, promote; via_join_request, invite_link)opt-in
chat_join_requestadmin bots with invite_users (user_chat_id, bio, invite_link)on
message_reactionadmin bots of a group; not for reactions set by botsopt-in
message_reaction_countadmin bots of a channel (reactions there are anonymous)opt-in
chat_boost— (no boosts)—

allowed_updates is one stored setting per bot (as in Telegram): getUpdates and setWebhook store it when the parameter is present and keep the previous value when it is omitted (deleteWebhook keeps it too); [] restores the default (everything except chat_member, message_reaction, message_reaction_count). Opt-in types are filtered when the update is created (not queued at all unless allowed) and again on delivery. Internally they are Update.chat_member (one message for both member kinds; the Bot API picks my_chat_member when the subject is the bot), chat_join_request, message_reaction, message_reaction_count.

20.6 Bot API coverage (chat and member management)

MethodStatusNotes
banChatMember (kickChatMember)✅until_date, revoke_messages (deletes the user’s messages; needs delete right)
unbanChatMember✅default kicks a current member (Telegram); only_if_banned
restrictChatMember✅all ChatPermissions incl. granular media, use_independent_chat_permissions, until_date
promoteChatMember✅every right; stories / video-chat / welcome rights accepted, no effect
setChatAdministratorCustomTitle✅≤ 16 chars, no emoji, admins promoted by the bot
banChatSenderChat / unbanChatSenderChat◐stored and validated; Telvoro has no “send as my channel”, so nothing else to block yet
setChatPermissions✅ban_users alone is enough
exportChatInviteLink✅new primary link, previous one revoked
createChatInviteLink / editChatInviteLink / revokeChatInviteLink✅name, expire_date, member_limit, creates_join_request
createChatSubscriptionInviteLink / editChatSubscriptionInviteLink✗deferred: needs recurring Stars charges in the ledger (§17.4)
approveChatJoinRequest / declineChatJoinRequest✅HIDE_REQUESTER_MISSING when there is no live request
setChatTitle / setChatDescription✅
setChatPhoto / deleteChatPhoto✅photo must be uploaded (as in Telegram)
setChatStickerSet / deleteChatStickerSet✗no group sticker sets; getChat.can_set_sticker_set = false
pinChatMessage / unpinChatMessage / unpinAllChatMessages✅
getChat✅+ permissions, join_by_request, join_to_send_messages, slow_mode_delay, accepted_gift_types
getChatMember / getChatAdministrators✅creator / administrator (all rights, can_be_edited) / member / restricted (is_member, every permission, until_date) / left / kicked (until_date)
getChatMemberCount, leaveChat✅
Updates: chat_member, my_chat_member, chat_join_request, message_reaction, message_reaction_count✅see §20.5
Update chat_boost / removed_chat_boost, getUserChatBoosts✗no boosts
Join-request bot queries (query_id, Bot API 10)✗

Compatibility is tested with unmodified python-telegram-bot 22.8 and aiogram 3.34 admin bots (ban as a reply, restrict with until_date, get_chat/get_chat_member/ get_chat_administrators parsing, DM a requester and approve, chat_member handler): server/internal/itest/testdata/{ptb,aiogram}_admin_bot.py, run with TELEVO_PTB_PYTHON=/path/to/venv/bin/python go test ./internal/itest -run 'PythonTelegramBotAdmin|AiogramAdmin'.

Generated from docs/PROTOCOL.md §6, §20 in the Telvoro repository. Wire names such as televo.v1 are unchanged.