Implements collectible usernames, official verification workflows, and third-party bot verification after maintainer protocol and migration review. The composite activity/moderation rating remains an admin-only read model; Telegram Stars Rating wire fields stay unset pending a dedicated official-semantics implementation. Reviewed-Head: 2796345775ea0f908fb7734601e5e1dee4b653b9 Original-Head: fa082b892fd5180c9c9bc53c81c21cf5d250a75b Co-authored-by: Egor Egorov <business.egor.sg@gmail.com>
23 KiB
Third-party bot verification
Third-party verification is an attributed mark: a bot that the operator appointed as a verifier attaches its own custom-emoji icon and one line of description to a peer. Official clients draw that icon before the peer's name and show the description in the profile, together with the name of the company the verifier vouches under.
Reference material:
- https://core.telegram.org/api/bots/verification
- https://telegram.org/verify#third-party-verification
Applications are collected by the built-in @verifierbot, decided in the admin
panel, and the decision commits together with the mark write. The protocol edge then
drops the cached peer projections and pushes the ordinary peer-refresh update, so an
online client shows the icon without a restart.
What this is not
This is not the platform checkmark. That one is a single boolean on the peer
(users.verified / channels.verified), granted by the operator after platform
review, collected by @verifybot, and documented in verification.md.
The two mechanisms are deliberately disjoint:
| Official verification | Third-party verification | |
|---|---|---|
| Stored as | users.verified, channels.verified (boolean) |
bot_verifier_settings, custom_verifications (attributed rows) |
| Granted by | the platform operator | a verifier bot the operator appointed |
| Rendered as | the standard checkmark after the name | the verifier's custom emoji before the name, plus a profile description |
| Front door | @verifybot |
@verifierbot (or bots.setCustomVerification directly) |
| Panel section | Official verification (/verification) |
Third-party verification (/bot-verification) |
| Permissions | verification.review, verification.revoke |
botverification.review, botverification.manage |
Neither reads the other's tables. Both can sit on one peer at the same time, an approval on one side never writes the other side's state, and revoking one leaves the other alone. The admin panel repeats that distinction in the section header and on every decision page, because "verified" in a ticket almost always means the other one.
TL constructors and flags (Layer 228)
Checked against the schema snapshot the server is built for,
/tmp/td/_schema/layers/layer-228.tl.
| Constructor / method | Field |
|---|---|
botVerification#f93cd45c |
bot_id:long icon:long description:string |
botVerifierSettings#b0cd6617 |
can_modify_custom_description:flags.1?true icon:long company:string custom_description:flags.0?string |
bots.setCustomVerification#8b89dfbd |
enabled:flags.1?true bot:flags.0?InputUser peer:InputPeer custom_description:flags.2?string = Bool |
user#b1b8cc83 |
bot_verification_icon:flags2.14?long |
channel#d49f34c6 |
bot_verification_icon:flags2.13?long |
userFull#6cbe645 |
bot_verification:flags2.12?BotVerification |
channelFull#a04e8d3a |
bot_verification:flags2.17?BotVerification |
chatInvite#5c9d3702 |
bot_verification:flags.13?BotVerification |
botInfo#4d8a0299 |
verifier_settings:flags.9?BotVerifierSettings |
One fact — "verifier B marked peer P with icon I and description D" — is
spread over six unrelated constructors, and a client renders the badge only when the
exact bit is set. Every projection therefore goes through the generated Set*
helpers (internal/rpc/bot_verification_projection.go): a struct field assigned
without its flag bit encodes as an absent field, and the badge silently disappears.
Note the asymmetry inside botVerifierSettings: custom_description:flags.0 is the
operator-configured default description, while
can_modify_custom_description:flags.1 is the permission that lets the verifier
override it per peer. botVerification.description is the resolved text actually
shown on a marked peer.
The icon is a custom emoji document
botVerification.icon and botVerifierSettings.icon are custom emoji document
ids. A client resolves them through messages.getCustomEmojiDocuments — exactly
the reader files.Service.GetDocuments answers from on this server.
Consequences that shape the whole feature:
- An id that names no fetchable document renders as nothing at all: the peer is marked in the database and the client draws an empty space. Nothing errors, nothing logs on the client, and the operator sees a granted mark that users cannot see.
- Therefore the icon is never a free-form number.
verification_iconsis a catalogue,botverification.Service.UpsertIconresolves the document before writing the row and refuses anything that is not a custom emoji (domain.Document.IsCustomEmoji), and a grant may only reference a catalogue entry that isactiveand either shared or reserved for that bot (VerificationIcon.UsableBy). - The mark denormalises the icon at grant time (
custom_verifications.icon_document_id), so a verifier changing its own icon later does not silently re-brand the peers it already marked.
The panel exposes the same rule: the icon catalogue tab is where document ids are registered and named, and the grant form only offers active catalogue entries.
End-to-end path
- Icon catalogue. An operator adds a custom emoji document to
verification_icons(panel: Third-party verification → Icon catalogue, orPOST /api/actions/upsert-verification-icon). Entries can be shared or reserved for one bot, and retiring an entry (set-verification-icon-active) stops new grants without touching marks that already carry it. - Verifier status. The operator grants a bot verifier status — an icon from the
catalogue, a company name, an optional default description and
can_modify_custom_description(panel: Verifiers, orPOST /api/actions/grant-bot-verifier). The row inbot_verifier_settingsis verifier status: it is the only authoritybots.setCustomVerificationconsults, and it is projected asbotInfo.verifier_settings. Nothing seeds it — not even migration0155for the built-in bot — because seeding verifier status would ship a badge printer with the schema. - Two ways to reach a mark.
- Direct RPC. The verifier bot (or the user who owns it) calls
bots.setCustomVerification.internal/rpc/bots_longtail.goresolves the two TL branches —bot:flags.0unset means "the caller is the bot", set means "a user acting through a bot it owns" — validates shape, and hands adomain.SetCustomVerificationRequestto the service. A missing or disabled verifier row answers403 BOT_VERIFIER_FORBIDDEN, and the error deliberately does not distinguish "never was a verifier" from "switched off". - Application queue. A peer owner talks to
@verifierbot(/verify,/status,/revoke,/cancel,/help), picks one of their own bots, channels or their own account, states a reason and optionally a wanted description. The bot writescustom_verification_requestswith statuspending; a partial unique index keeps one pending row per (verifier, peer) pair.@verifierbotdecides nothing — it says so in/start.
- Direct RPC. The verifier bot (or the user who owns it) calls
- Review. The panel lists the queue, the verifier roster, the icon catalogue and
every granted mark. BFF routes are
GET /api/botverification/{verifiers,icons,marks,requests,counts},GET /api/botverification/requests/{id}andPOST /api/botverification/requests/{id}/{approve,reject,revoke}; the manage-only mutations are the/api/actions/...commands listed above plusset-bot-verifier-enabled,revoke-bot-verifierandrevoke-custom-verification. Every mutation goes through the shared admin command journal (reason → dry run → confirm), so it lands inadmin_commands/admin_audit_logs. - Second gate at approval.
botverification.Service.Approvere-loads a fresh snapshot: the verifier must still exist and be enabled, the peer must still resolve, and the per-verifier quota is spent only when the approval would create a mark rather than update one. A queue that sat for days cannot launder a state the RPC path would refuse.versionis an optimistic lock — a stale panel gets a409and the page reloads instead of overwriting a fresher decision. - Decision transaction. The status transition and the mark write commit
together:
DecideCustomVerificationRequestruns the grant (or the revoke) through a callback whose context carries the decision's own transaction. "Approved" and "the peer carries the mark" can never disagree. The description is resolved byBotVerifierSettings.DescriptionFor— the applicant's wording only whencan_modify_custom_descriptionis set, otherwise the operator default — which is the single place that rule lives, so the RPC edge, the bot dialog and the panel preview cannot drift. - Protocol edge. After the commit the service calls
rpc.Router.NotifyPeerBotVerification(ctx, domain.Peer)(internal/rpc/bot_verification_notify.go), which:- drops the cached peer projections for the peer, and for a channel also the
channelFullbot-info cache that carriesbotInfo.verifier_settings; - for a user or bot, reuses
NotifyUserModerationFlagsChanged— the audience-wide, non-PTSupdateUserfan-out the scam/fake flags use, filtered to online sessions, with the peer re-projected per recipient; - for a channel, reuses
NotifyChannelChanged→updateChannelplus the refreshedchannel#d49f34c6object to members (and a linked monoforum when there is one); - is a no-op on a nil receiver and reports an error rather than panicking. A push failure never invalidates the committed decision.
- drops the cached peer projections for the peer, and for a channel also the
- Applicant notification.
@verifierbotmessages the applicant with the outcome (SendVerificationDecision).internal_noteis never rendered there under any status — onlydecision_reasonreaches the applicant. - What the client sees. The icon appears before the name in the dialog list,
search results, message headers and the profile, and the description appears in the
profile.
bots.setCustomVerificationreturnsBoolTruefor every successful application, including an idempotent re-apply or revoke; official clients treatBoolFalseas failure.
Where the mark surfaces
| Surface | Method | Field |
|---|---|---|
| Dialog list, search, history, difference | messages.getDialogs, contacts.search, contacts.resolveUsername, messages.getHistory, updates.getDifference, … |
user.bot_verification_icon, channel.bot_verification_icon |
| User profile | users.getFullUser |
userFull.bot_verification |
| Channel / supergroup info | channels.getFullChannel |
channelFull.bot_verification |
| Invite preview (non-member) | messages.checkChatInvite |
chatInvite.bot_verification |
| Verifier bot's own profile | users.getFullUser, channels.getFullChannel bot list |
botInfo.verifier_settings |
| Live updates | pushed updates envelopes |
updateUser / updateChannel plus the peer object |
The icon overlay runs at the response boundary, not inside tgUser/tgChannel:
applyPeerReadModels (internal/rpc/story_peer_projection.go) is the single hook
every handler funnels through, so all ~40 call sites get the field with one batched
read per response instead of an N+1 per peer. The userFull / channelFull /
chatInvite variants are post-cache overlays for the same reason — a cached full
object is still stamped with the current mark. A nil service or any read error leaves
every flag unset, which is byte-identical to the pre-feature wire shape.
Migrations
0155_bot_verificationcreates the four tables:verification_icons— the catalogue.document_idis unique and positive,owner_bot_id = 0means shared,activeretires an entry without deleting it.bot_verifier_settings— verifier status, keyed bybot_idwith an optimisticversion,enabledas the per-verifier kill switch, and the operator'sgranted_by/grant_reasonfor the audit trail.custom_verifications— granted marks.UNIQUE (peer_type, peer_id)matches the singleBotVerificationvalue on the wire: a different verifier replaces the current mark rather than leaving hidden fallback rows. It also haspeer_type IN ('user','channel'),icon_document_iddenormalised from the verifier,ON DELETE CASCADEfrom the verifier row.custom_verification_requests— the review queue.status IN ('pending','approved','rejected','revoked'), a partial unique index for onependingrow per (verifier, peer), and check constraints that pair each stamp with its status ((status = 'approved') = (approved_at IS NOT NULL)) and refuse a rejection without a reason.
0156_verifier_service_botseeds@verifierbot(id1250000013, fixedaccess_hashdouble-written withdomain.VerifierBotAccessHash), itsbotsrow and command list, and itspeer_usernamesregistry entry, so the handle is occupied from the moment the schema is current.verified = falseon purpose: a third-party verifier wearing the platform checkmark would blur the exact distinction it has to explain to every applicant. The seed grants no verifier status — an operator does that by hand in the panel.
Neither migration adds read-model triggers: the marks are read live at the response boundary rather than cached in a peer read model.
Configuration
Third-party verification (internal/config/config.go, .env.example):
| Key | Default | Meaning |
|---|---|---|
TELESRV_BOT_VERIFICATION_ENABLED |
true |
Master switch. When off, every third-party mutation is refused (grants, revocations, applications, catalogue edits) while marks already granted keep rendering — blanking one verifier's badges is what its per-verifier kill switch is for. |
TELESRV_BOT_VERIFICATION_MAX_PER_VERIFIER |
10000 |
Peers one verifier may mark. 0 disables the service bound and leaves only the storage bound (domain.MaxCustomVerificationsPerVerifier), which is also the maximum this key accepts. |
TELESRV_BOT_VERIFICATION_REQUEST_RATE_LIMIT |
5 |
Applications one applicant may file per window, across all verifier bots. 0 disables the budget. Looser than the official 3 on purpose: a deployment can run several verifier companies, and filing with a second one is not a retry of the first. |
TELESRV_BOT_VERIFICATION_REQUEST_RATE_WINDOW |
24h |
That window. A positive limit requires a positive window. |
Operator access:
| Key | Default | Meaning |
|---|---|---|
TELESRV_ADMIN_UI_PERMISSIONS |
* |
Permissions of an Admin UI session. Reading the section and deciding applications needs botverification.review; the verifier roster, the icon catalogue and stripping a granted mark need botverification.manage. |
TELESRV_ADMIN_SCOPED_TOKENS |
(empty) | name:token:perm1,perm2 entries separated by ;, for integrations that should get botverification.review and nothing else. |
The two rights are independent of the official ones: a reviewer may hold
verification.review without botverification.review, and vice versa. The panel
hides the nav entry, gates the route and hides the manage-only buttons accordingly;
every route is checked again server-side.
Manual check
Telegram Desktop
- In the panel, open Third-party verification → Icon catalogue and add a custom emoji document id. The Emoji section lists the documents this deployment holds with their ids; pick one that a client can actually fetch.
- Open Verifiers, grant
@verifierbotverifier status with that icon, a company name (sayAcme Verification Ltd), a default description (Verified by Acme) andcan_modify_custom_descriptionoff for the first pass. Confirm the audit entry appeared. - Log in to the deployment with official Telegram Desktop and open
@verifierbot. Its profile now carries a "verified by" block built frombotInfo.verifier_settings— the company and the icon — while its name has no platform checkmark. That contrast is the point. - Send
/verify, pick one of your channels from the inline picker, state a reason, confirm./statuslists the application as pending. - In the panel open the queue, open the application, read the Description the mark
would carry preview (with
can_modify_custom_descriptionoff it shows the verifier default, not what you asked for), and approve. - Within a moment
@verifierbotmessages you the decision. - Without restarting the client, check the icon on the approved channel:
- Profile — the icon sits immediately before the title, and the
description line ("Verified by Acme") appears in the profile body
(
channelFull.bot_verification). - Dialog list — the chat row shows the icon before the title.
- Message header — open the chat; the header title carries the icon.
- Search — type the
@usernamein global search; the result row carries it. - Invite preview — from a second account that is not a member, open an
invite link to that channel: the join box carries the icon
(
chatInvite.bot_verification).
- Profile — the icon sits immediately before the title, and the
description line ("Verified by Acme") appears in the profile body
(
- If the peer also holds the platform checkmark, both are visible at once: the custom icon before the name, the checkmark after it.
- In the panel, revoke from the application's danger zone (or Granted marks → Remove mark). The icon disappears from all of those surfaces on the next push or read, and the platform checkmark stays untouched.
- To check the invisible-badge failure mode on purpose, retire the icon and grant a verifier a catalogue entry whose document was deleted: the peer is marked in the database and the client draws nothing. That is why the catalogue validates documents up front.
Telegram Android
- Log in with the official Android client, force-close it and reopen it after the grant so the profile cache is cold.
@verifierbotprofile: the verifier block ("verified by company" with the icon) is rendered under the bot's info, and the bot's name has no checkmark.- Approve an application for a user account (your own) and open that account's
profile from a second device: the icon is drawn before the name in the profile
header and in the chat header, and the description is a line in the profile
(
userFull.bot_verification). - Chat list and global search rows carry the icon before the name
(
user.bot_verification_icon). - Custom emoji rendering follows the client's animated-emoji setting: with animated emoji disabled the icon shows as a static frame, and while the document is still being fetched the slot is briefly empty. Neither is a server-side problem.
- Revoke from the panel and pull-to-refresh the profile: the icon is gone.
Limitations
- A verifier can mark a peer that never asked.
bots.setCustomVerificationauthorises the caller (the bot itself, or a user who owns it) and the verifier status, not the target's consent. Verifier status is the trust boundary; that is why granting it is an operator-only action, why it has a kill switch, and whyTELESRV_BOT_VERIFICATION_MAX_PER_VERIFIERbounds it. A peer cannot refuse or remove a mark itself — only the verifier (/revokein the bot dialog, or the RPC withenabledunset) or an operator can. - No per-application event history. Unlike official verification, there is no
*_eventstable: an application keeps onlydecided_by,decision_reason,internal_noteand its stamps. The full trail lives in the sharedadmin_commands/admin_audit_logsjournal, so the panel's decision page shows a decision, not a timeline. - A revocation clears
approved_at.0155pairs each stamp with its status, so leaving the approved state nulls the approval stamp. After a revoke, "when was this approved?" can only be answered from the audit journal. - Applicant notifications are best-effort. They are sent directly by
@verifierbotafter the decision commits, not through a durable outbox like the official flow'sverification_notification_outbox. A delivery failure is logged and swallowed (notifyApplicant); the decision itself stands, and nothing retries the message, so an applicant can end up with a decided application they were never told about. - Only users and channels can be marked.
peer_typeis constrained touser/channel, matching the TL surface: legacy basic groups (chat#…) have nobot_verificationfield in Layer 228, so a non-migrated basic group can never show a mark. - Only bots can be verifiers, and system bots cannot — except the built-in
@verifierbot.botInfo.verifier_settingsexists only on a bot, so a user account granted verifier status would carry a status no client can see; seeded service accounts are refused outright (@verifybotin particular, which owns the other mechanism). - One icon per verifier, one mark per peer. A verifier cannot vary its icon per peer, there are no verification tiers, and no expiry: a mark lives until somebody removes it. Nothing re-validates a marked peer over time — losing its username or picking up a scam flag later does not clear the mark.
- A new verifier replaces the current peer mark.
user.bot_verification_iconandchannel.bot_verification_iconare singlelongfields, so the database stores one matching mark. Replacing it cannot leave an older hidden mark that unexpectedly reappears after a revoke or kill-switch change. - A retired icon keeps rendering on existing marks. Retiring a catalogue entry only blocks new grants, because the mark copied the document id at grant time. Blanking an already-granted icon means revoking the marks (or the verifier).
- An unresolvable document is an invisible badge. The catalogue validates the document when the entry is written, not continuously. A document deleted afterwards leaves marks that render as nothing, and the server has no way to notice.
- The live push only reaches online sessions, and the user fan-out is bounded by the same capped moderation audience the scam/fake flags use. Everybody else converges on their next authoritative read, which is always correct: the icon is an overlay read live at the response boundary rather than a cached read-model column.
updateUser/updateChannelcarry nopts. They are not persisted as message-box events, so a session that was offline during the decision never replays the push; it picks the mark up as state on its next read, not as an event.channelFull's bot-info cache is per process.NotifyPeerBotVerificationdrops it on the instance that handled the decision. On other instances a cachedchannelFull.bot_infocan still carry a staleverifier_settingsblock (the company/icon of the verifier bot, not the peer's mark) until that entry expires. The peer's ownbot_verificationfields are overlaid post-cache and are not affected.TELESRV_BOT_VERIFICATION_ENABLED=falseis not a badge switch. It refuses new mutations; the marks already granted keep being projected. Use the per-verifier kill switch, or revoke, to actually clear badges.