Skip to content

feat(groups): answer the backend with each group's native admins - #159

Closed
BIA3IA wants to merge 1 commit into
mainfrom
feat/sync-group-admins
Closed

BIA3IA wants to merge 1 commit into
mainfrom
feat/sync-group-admins

Conversation

@BIA3IA

@BIA3IA BIA3IA commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bot side of PoliNetworkOrg/backend#98. People needs who administers each Telegram group, and Telegram is the only source (RFC v3 decision 2). The backend stores nothing: it asks the bot.

  • Cache: the bot keeps each group's getChatAdministrators (without bots) in Redis (group_admins:<chatId>, through RedisFallbackAdapter, so it falls back to memory when Redis is down). Entries expire after a day, so a group the bot can no longer read becomes unknown instead of stale.
  • Answering the backend: the socket event getGroupAdmins returns the cached admins of the requested groups, leaving out groups not read yet.
  • Refresh:
    • when someone becomes or stops being an admin (chat_member), once a burst of changes in that chat settles (5 s);
    • 30 s after the bot is promoted in a group;
    • for every group 2 minutes after startup and every 6 hours, one Telegram request at a time (100 ms apart). A full refresh is skipped while another runs; a failing group keeps its previous entry and doesn't stop the others.

The middleware runs right after BotMembershipHandler, before the moderation handlers that end the chain on chat_member. The logic is in src/lib/group-admins with injected dependencies, so it is tested without Telegram, Redis or the backend.

⚠️ Draft until the backend is released

getGroupAdmins is not in the published @polinetwork/backend socket types yet, so CI typecheck fails on this branch. After backend#98 is merged and released, bump @polinetwork/backend here, then mark ready. Deploy the bot together with or before the backend: an older bot just doesn't answer, and People shows groups without admins.

Verification

Against the SDK built locally from backend#98:

  • pnpm typecheck, biome check, pnpm build: OK.
  • pnpm test: 192 passed, 1 skipped. New tests: who counts as an admin, which updates trigger a refresh, debouncing, failures keeping the previous entry, the full refresh, and the answer to the backend.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

People needs who administers each Telegram group, and Telegram is the only source (RFC v3 decision 2). The bot keeps a cache of getChatAdministrators (without bots) in Redis and answers the backend's getGroupAdmins over the socket; the backend stores nothing.

The cache is refreshed when someone becomes or stops being an admin, once a burst of changes settles; 30 seconds after the bot is promoted in a group; and for every group 2 minutes after startup and every 6 hours, one Telegram request at a time. Entries expire after a day, so a group the bot can no longer read becomes unknown instead of stale.

Needs @polinetwork/backend with getGroupAdmins (PoliNetworkOrg/backend#98).
@BIA3IA
BIA3IA force-pushed the feat/sync-group-admins branch from 91a99ab to ff078fc Compare October 26, 2026 19:59
@BIA3IA BIA3IA changed the title feat(groups): report each group's native admins to the backend feat(groups): answer the backend with each group's native admins Oct 26, 2026
@BIA3IA BIA3IA closed this Oct 26, 2026
@BIA3IA
BIA3IA deleted the feat/sync-group-admins branch October 26, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant