feat(telegram): promo bot + channel-chat moderation gate
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 57s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m39s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 57s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m39s
Add a second standalone promo bot to the bot container (answers /start with a localized message + a URL button into the main bot's Mini App) and gate write access in a channel's linked discussion chat: grant on join when the Telegram user is registered and neither admin-suspended nor holding a new chat_muted role, and revoke/grant on the matching moderation change for a member currently in the chat. Eligibility (registered AND NOT suspended AND NOT chat_muted; the game suspension dominates) is resolved once in the backend and reached two ways: the bot's join-time unary ResolveChatEligibility over the existing mTLS bot-link, and a backend chat_access_changed event -> gateway -> ChatGate command (idempotent; a temporary-block-expiry sweeper may over-emit). The bot guards the block/unblock path with getChatMember, since bots cannot list members. A web_app button cannot open another bot's Mini App (it signs initData with the sending bot's token), so the promo button is a t.me ?startapp URL reusing the UI's VITE_TELEGRAM_LINK. The bot must be a chat admin with the restrict-members right and chat_member in its allowed updates. No schema change: chat_muted reuses the data-driven account_roles table.
This commit is contained in:
@@ -20,6 +20,13 @@ service BotLink {
|
||||
// Link opens the single bot <-> gateway stream. The first client message is
|
||||
// Hello; thereafter the client sends one Ack per received Command.
|
||||
rpc Link(stream FromBot) returns (stream ToBot);
|
||||
|
||||
// ResolveChatEligibility answers whether the Telegram user identified by
|
||||
// external_id may write in the moderated discussion chat: registered with an
|
||||
// account and neither admin-suspended nor chat-muted. The bot calls it over the
|
||||
// same mTLS channel when a user joins the chat, to decide whether to grant the
|
||||
// write permission. Delivery of the answer is request/response (not best-effort).
|
||||
rpc ResolveChatEligibility(ChatEligibilityRequest) returns (ChatEligibilityResponse);
|
||||
}
|
||||
|
||||
// FromBot is a message the bot sends to the gateway: the opening Hello, then one
|
||||
@@ -53,6 +60,7 @@ message Command {
|
||||
scrabble.telegram.v1.NotifyRequest notify = 2;
|
||||
scrabble.telegram.v1.SendToUserRequest send_to_user = 3;
|
||||
scrabble.telegram.v1.SendToGameChannelRequest send_to_channel = 4;
|
||||
ChatGateCommand chat_gate = 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,3 +73,29 @@ message Ack {
|
||||
bool delivered = 2;
|
||||
string error = 3;
|
||||
}
|
||||
|
||||
// ChatGateCommand sets a Telegram user's write access in the moderated discussion
|
||||
// chat. external_id is the user's Telegram identity (as in the backend identities
|
||||
// table); allow grants the right to write when true and revokes it when false. The
|
||||
// bot applies it only to a user currently in the chat — it guards on getChatMember,
|
||||
// so a command for an absent user is a no-op. The gateway emits one whenever the
|
||||
// user's eligibility may have changed: an admin block or unblock, a chat_muted
|
||||
// grant or revoke, or a temporary block lapsing.
|
||||
message ChatGateCommand {
|
||||
string external_id = 1;
|
||||
bool allow = 2;
|
||||
}
|
||||
|
||||
// ChatEligibilityRequest asks whether the Telegram user identified by external_id
|
||||
// may write in the moderated discussion chat.
|
||||
message ChatEligibilityRequest {
|
||||
string external_id = 1;
|
||||
}
|
||||
|
||||
// ChatEligibilityResponse is the eligibility answer. registered reports whether the
|
||||
// external_id maps to an account at all; eligible is the final gate the bot acts on
|
||||
// (registered and neither admin-suspended nor chat-muted).
|
||||
message ChatEligibilityResponse {
|
||||
bool registered = 1;
|
||||
bool eligible = 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user