Skip to content

feat: add TELEGRAM_ALLOWED_TOPICS for forum topic filtering#1101

Merged
konard merged 3 commits intomainfrom
issue-1100-45539e9d3099
Mar 31, 2026
Merged

feat: add TELEGRAM_ALLOWED_TOPICS for forum topic filtering#1101
konard merged 3 commits intomainfrom
issue-1100-45539e9d3099

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Jan 10, 2026

Summary

Adds support for filtering bot commands by Telegram forum topics, in addition to existing chat filtering. Users can configure specific topics within supergroups where the bot should respond.

Changes

  • Add parseLinks() and formatLinks() to lino library for parsing chatId:topicId pairs in Links Notation
  • Add --allowedTopics CLI option and TELEGRAM_ALLOWED_TOPICS environment variable
  • Add isTopicAuthorized() function with hierarchical authorization:
    1. If chat is in TELEGRAM_ALLOWED_CHATS → all topics allowed
    2. If specific topic is in TELEGRAM_ALLOWED_TOPICS → only that topic works
    3. Otherwise → denied
  • Update /help command to always be allowed (no auth check) and show topic ID in diagnostics
  • Update all command handlers (/solve, /hive, /limits, /version, /accept_invites, /merge, /solve_queue, /top) to use topic-level authorization
  • Update dry-run and startup logging to show allowed topics configuration

Configuration Format

Uses Links Notation with space-separated chatId topicId pairs:

TELEGRAM_ALLOWED_TOPICS="(
  -1002975819706 857
  -1001234567890 456
)"

Or nested format:

TELEGRAM_ALLOWED_TOPICS="(
  (-1002975819706 857)
  (-1001234567890 456)
)"

Backward Compatibility

  • Existing deployments work unchanged (feature only active when TELEGRAM_ALLOWED_TOPICS is set)
  • If only TELEGRAM_ALLOWED_CHATS is configured, all topics in allowed chats remain accessible
  • /help always works in any chat/topic to show IDs for configuration

Test Plan

  • 19 unit tests covering parseLinks, formatLinks, and authorization logic
  • All existing tests pass (70 solve-queue, 50 limits, 67 usage-limit, 51 message-filters, 22 solve-queue-command, 10 queue-display, 41 bot-launcher)
  • ESLint passes
  • File line limit (1500) respected
  • CI checks pass

Fixes #1100


🤖 Generated with Claude Code

@konard konard self-assigned this Jan 10, 2026
@konard konard changed the title [WIP] In addition to allowed chats, add support for allowed telegram topics (inside chats) Case Study: Telegram forum topics support for allowed chats Jan 10, 2026
@konard konard marked this pull request as ready for review January 10, 2026 23:41
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 10, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.994650 USD
  • Calculated by Anthropic: $2.243870 USD
  • Difference: $-0.750780 (-25.07%)
    📎 Log file uploaded as GitHub Gist (471KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 11, 2026

# New - optional topic restrictions within allowed chats
TELEGRAM_ALLOWED_TOPICS="(
  -1002975819706 857
  (-1001234567890 456)
)"

Lets add these, also /help command should show not only chat, but also topic, and should be allowed in all cases, as it is required to see actual topic ids.

If we have access to topic, but not to chat, only topic is working, if we have acces also to chat - that means all topics allowed in the chat, so no need for * syntax.

And everything will be backward compatible.

Links syntax allows omitting ( ) on the end of lines, so in both cases pair of ids (references in links notation) will be parsed as single link.

@konard konard marked this pull request as draft January 11, 2026 01:32
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 11, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-11T01:32:52.762Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

@konard konard changed the title Case Study: Telegram forum topics support for allowed chats Implement TELEGRAM_ALLOWED_TOPICS for forum topic filtering Jan 11, 2026
@konard konard marked this pull request as ready for review January 11, 2026 01:55
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 11, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $13.589566 USD
  • Calculated by Anthropic: $8.564278 USD
  • Difference: $-5.025288 (-36.98%)
    📎 Log file uploaded as GitHub Gist (2081KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 29, 2026

Lino arguments and lenv do not use = sign, so we should be links notation first for that configuration.

Also lots of changes were made previously, so we need to get fresh version of the code, and resolve conflicts.

We need to ensure these changes will not break anything, they are tested, traced, and enabled only when new additional ENV variable is used or corresponding CLI option. So the end result is that we will be able to allow full chat as previously, of if we don't want full chat, we just allow specific topics in it.

Also we need to ensure all changes are correct, consistent, validated, tested, logged and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard konard marked this pull request as draft March 29, 2026 11:19
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 29, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-03-29T11:19:09.033Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

Add support for filtering bot commands by Telegram forum topics
using Links Notation format. Users can configure specific topics
within supergroups where the bot should respond.

- Add parseLinks/formatLinks to lino.lib.mjs for chatId:topicId pairs
- Add --allowedTopics CLI option and TELEGRAM_ALLOWED_TOPICS env var
- Add isTopicAuthorized() with hierarchical auth: chat > topic
- Update /help to always work and show topic ID for diagnostics
- Update all command handlers to use topic-level authorization
- Add 19 tests covering parsing, formatting, and authorization logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard force-pushed the issue-1100-45539e9d3099 branch from ab686fb to e7ce2dd Compare March 29, 2026 11:31
@konard konard changed the title Implement TELEGRAM_ALLOWED_TOPICS for forum topic filtering feat: add TELEGRAM_ALLOWED_TOPICS for forum topic filtering Mar 29, 2026
@konard konard marked this pull request as ready for review March 29, 2026 11:32
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 29, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $11.862222
  • Calculated by Anthropic: $7.866476 USD
  • Difference: $-3.995746 (-33.68%)

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Main model: Claude Opus 4.6 (claude-opus-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (5602KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 29, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

Resolve conflicts.

And double-triple check all previously discussed requirements.

We need to ensure all changes are correct, consistent, validated, tested, logged and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard konard marked this pull request as draft March 31, 2026 22:36
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-03-31T22:36:17.708Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

konard and others added 2 commits March 31, 2026 22:38
Merge latest main into issue-1100-45539e9d3099, resolving conflicts in
telegram-bot.mjs and telegram-merge-command.lib.mjs. Integrates
start/stop command support (issue #1081) with topic authorization
(issue #1100) by adding isChatStopped and getStoppedChatRejectMessage
to sharedCommandOpts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add missing chatId declarations before isChatStopped checks in
  /solve and /hive handlers (caused no-undef ESLint errors after merge)
- Fix /solve_queue hint text to use unescaped underscore (fixes
  pre-existing test failure from main)
- Add JSDoc entries for isChatStopped/getStoppedChatRejectMessage in
  merge command
- Condense comments to keep telegram-bot.mjs under 1500 line limit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review March 31, 2026 22:51
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $3.810393
  • Calculated by Anthropic: $3.810393 USD
  • Difference: $0.000000 (+0.00%)

📊 Context and tokens usage:

Claude Opus 4.6:

  • Max context window: 80.5K / 1M input tokens (8%)
  • Max output tokens: 18.9K / 128K output tokens (15%)

Total input tokens: 70.7K + 5.1M cached
Total output tokens: 18.9K output
Cost: $3.480491

Claude Haiku 4.5:

  • Context window: 2.0M / 200K tokens (1006%)
  • Max output tokens: 7.9K / 64K output tokens (12%)

Total input tokens: 77.4K + 1.9M cached
Total output tokens: 7.9K output
Cost: $0.329902

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Main model: Claude Opus 4.6 (claude-opus-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (3627KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit aed8481 into main Mar 31, 2026
21 checks passed
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.

In addition to allowed chats, add support for allowed telegram topics (inside chats)

1 participant