Skip to content

refactor(telegram)!: remove legacy commands and anonymous backend access - #157

Merged
toto04 merged 1 commit into
mainfrom
feat/idp-phase5-bot-cleanup
Oct 21, 2026
Merged

toto04 merged 1 commit into
mainfrom
feat/idp-phase5-bot-cleanup

Conversation

@BIA3IA

@BIA3IA BIA3IA commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Completes RFC v3 Phase 4b step 4 and prepares the bot for Phase 5 (LEGACY_ANONYMOUS=deny).

  • Remove /addrole, /delrole, /link and /test_db.
  • Drop overrideGroupAdminCheck: per RFC §4 decision 5, tg_group_admins is replaced by the native Telegram admin shortcut (decision 2), which allowTelegramChatAdmins already provides.
  • Remove the shadow/anonymous decision modes, IDP_DECISIONS and legacyBackend. The IdP variables are now required and every check applies the IdP decision; an unavailable decision denies.
  • Remove the legacy fallbacks: message trust, bot adder, hashtag/campaign exemptions, ban-all immunity, grants interrupt/delete, report and campaign-review menus, /audit, tg.auditLog.create and the test.dbQuery health check. The socket always authenticates with its token.
  • Drop the SDK-derived Role type and the dead role declarations on commands.

The bot no longer calls tg.permissions.*, tg.link.*, tg.groupLabels.*, auth.*, test.* or tg.auditLog.create, and sends no actor fields in requests. Older audit rows and socket payloads are still read with adminId/performerId until the v2 SDK.

Deploy

Works with the current backend (token sockets and tg.access.resolve are already accepted). Deploy before the backend switches to LEGACY_ANONYMOUS=deny; rolling back to an older bot image needs LEGACY_ANONYMOUS=allow.

BREAKING CHANGE: IDP_PUBLIC_URL, OAUTH_BACKEND_RESOURCE_URI, OAUTH_BOT_CLIENT_ID and OAUTH_BOT_PRIVATE_JWK are required; IDP_DECISIONS is removed.

Verification

typecheck, biome check, 184 tests (1 optional Redis test skipped), build. Also typechecked against the Phase 5 backend SDK. Not verified against a real IdP, backend or Telegram.

…ecisions

Completes RFC v3 Phase 4b step 4 and prepares the bot for Phase 5
(LEGACY_ANONYMOUS=deny).

- Remove /addrole, /delrole, /link and /test_db.
- Drop overrideGroupAdminCheck: per RFC §4 decision 5, tg_group_admins is
  replaced by the native Telegram admin shortcut (decision 2).
- Remove the shadow/anonymous decision modes, IDP_DECISIONS and
  legacyBackend; every check applies the IdP decision.
- The socket always authenticates with its token.

BREAKING CHANGE: IDP_PUBLIC_URL, OAUTH_BACKEND_RESOURCE_URI,
OAUTH_BOT_CLIENT_ID and OAUTH_BOT_PRIVATE_JWK are required; IDP_DECISIONS
is removed. Deploy before setting backend LEGACY_ANONYMOUS=deny.
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5a30f1ce-d157-4b29-a130-6a1917a2d133
📥 Commits

Reviewing files that changed from the base of the PR and between cca8990 and 31fdca6.

📒 Files selected for processing: 54
  • .env.example
  • README.md
  • docs/idp-phase4b-handoff.md
  • src/access/decision.ts
  • src/access/index.ts
  • src/backend.ts
  • src/commands/access.ts
  • src/commands/index.ts
  • src/commands/invite.ts
  • src/commands/link-admin-dashboard.ts
  • src/commands/management/audit.ts
  • src/commands/management/groups.ts
  • src/commands/management/index.ts
  • src/commands/management/role.ts
  • src/commands/management/userid.ts
  • src/commands/moderation/ban.ts
  • src/commands/moderation/banall.ts
  • src/commands/moderation/del.ts
  • src/commands/moderation/index.ts
  • src/commands/moderation/kick.ts
  • src/commands/moderation/mute.ts
  • src/commands/pin.ts
  • src/commands/report.ts
  • src/commands/search.ts
  • src/commands/test/args.ts
  • src/commands/test/conversation.ts
  • src/commands/test/db.ts
  • src/commands/test/format.ts
  • src/commands/test/index.ts
  • src/commands/test/menu.ts
  • src/env.ts
  • src/idp/config.ts
  • src/lib/group-management/index.ts
  • src/lib/managed-commands/command.ts
  • src/middlewares/campaign-spam/authorization.ts
  • src/middlewares/campaign-spam/index.ts
  • src/middlewares/campaign-spam/review.ts
  • src/middlewares/group-specific-actions.ts
  • src/middlewares/message-trust.ts
  • src/modules/audit/index.ts
  • src/modules/moderation/ban-all-immunity.ts
  • src/modules/moderation/ban-all.ts
  • src/modules/tg-logger/grants.ts
  • src/modules/tg-logger/index.ts
  • src/modules/tg-logger/report.ts
  • src/modules/websocket.ts
  • src/utils/types.ts
  • tests/ban-all-audit.test.ts
  • tests/ban-all-immunity.test.ts
  • tests/campaign-spam-authorization.test.ts
  • tests/campaign-spam-guard.test.ts
  • tests/idp-decisions.test.ts
  • tests/idp-fetch.test.ts
  • tests/tg-logger-resilience.test.ts
💤 Files with no reviewable changes: 6
  • src/commands/test/db.ts
  • src/middlewares/campaign-spam/authorization.ts
  • src/commands/link-admin-dashboard.ts
  • tests/campaign-spam-authorization.test.ts
  • tests/ban-all-audit.test.ts
  • src/access/decision.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The bot now requires IdP configuration and uses authenticated backend access. Commands, middleware, and operational flows use IdP permissions instead of legacy role checks. The /link, /addrole, and /delrole commands and anonymous backend paths were removed.

Changes

IdP Authorization Cutover

Layer / File(s) Summary
Required IdP configuration and authenticated clients
.env.example, README.md, docs/idp-phase4b-handoff.md, src/env.ts, src/idp/config.ts, src/backend.ts, src/websocket.ts, tests/idp-fetch.test.ts, tests/tg-logger-resilience.test.ts
The IdP public URL, backend resource URI, bot client ID, and private JWK are required. Backend and WebSocket connections use token authentication. Documentation now describes the required configuration and the updated deployment guidance.
Direct IdP authorization for commands
src/access/*, src/commands/*, src/utils/types.ts, src/lib/managed-commands/command.ts, tests/idp-decisions.test.ts
authorizeAction evaluates IdP access directly and denies when evaluation fails. Command collections use string keys, and command permission declarations no longer use legacy role checks. The /link, /addrole, /delrole, and test database commands were removed.
IdP checks in middleware and operations
src/lib/group-management/index.ts, src/middlewares/*, src/modules/moderation/ban-all-immunity.ts, src/modules/tg-logger/*, tests/ban-all-immunity.test.ts, tests/campaign-spam-*.test.ts
Group management, campaign handling, message trust, moderation immunity, and grant and report actions now use direct IdP permission checks instead of legacy role fallbacks.
Authenticated audit and BanAll recovery
src/modules/audit/index.ts, src/modules/moderation/ban-all.ts, tests/ban-all-audit.test.ts, README.md
Audit records always use the Redis-backed outbox. BanAll flows always receive audit data. The tests no longer cover the removed anonymous flow.

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant authorizeAction
  participant Backend
  participant idpDecision
  Command->>authorizeAction: actor, chat, and required permissions
  authorizeAction->>Backend: resolve actor access
  Backend-->>authorizeAction: access entry
  authorizeAction->>idpDecision: access entry, permissions, and chat-admin status
  idpDecision-->>authorizeAction: allowed or denied decision
  authorizeAction-->>Command: authorization result
Loading

Priority: ➖ Normal

Change: Other

Merge Risk: ⚪ Minimal · up to 31fdc

No actionable issue is established from the reviewed changes. The PR is mergeable after normal checks.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 45 files. (3 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title accurately and concisely describes the main changes: removing legacy commands and anonymous backend access.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 70.59% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 45 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

@toto04
toto04 merged commit 4ecb2ff into main Oct 21, 2026
2 checks passed
@toto04
toto04 deleted the feat/idp-phase5-bot-cleanup branch October 21, 2026 18:37
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.

2 participants