Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Jan 10, 2026

Summary

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

Changes

  • Add TELEGRAM_ALLOWED_TOPICS configuration using Links Notation format chatId topicId
  • Add parseLinks() and formatLinks() methods to lino library for parsing topic pairs
  • Add isTopicAuthorized() function with authorization logic:
    • If chat is in TELEGRAM_ALLOWED_CHATS, all topics in that chat are allowed
    • If specific topic is in TELEGRAM_ALLOWED_TOPICS, only that topic works
    • If neither, access is denied
  • Update /help command to:
    • Always be allowed (bypass authorization for diagnostics)
    • Show both chat ID and topic ID in diagnostic information
    • Show configuration hint when in unauthorized topic
  • Update /solve, /hive, /limits, /version to use isTopicAuthorized()
  • Update dry-run output to show allowed topics configuration
  • Update case study documentation with new format and logic

Configuration Format

Uses Links Notation with space-separated chatId topicId pairs:

# Allow specific topic only
TELEGRAM_ALLOWED_TOPICS="(
  -1002975819706 857
)"

# Or with multiple topics
TELEGRAM_ALLOWED_TOPICS="(
  -1002975819706 857
  (-1001234567890 456)
)"

Authorization Logic

  1. If chat is in TELEGRAM_ALLOWED_CHATS: All topics in that chat are allowed
  2. If topic is in TELEGRAM_ALLOWED_TOPICS: Only that specific topic works
  3. /help command: Always allowed (to show chat and topic IDs for configuration)

This design is backward compatible - existing deployments work unchanged.

Test Plan

  • Run local lint checks (ESLint, Prettier)
  • Test dry-run mode with topic configuration
  • Test parseLinks() method with various input formats
  • CI checks pass

Fixes #1100


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1100
@konard konard self-assigned this Jan 10, 2026
This case study investigates adding support for allowed Telegram topics
(inside chats) in addition to the existing allowed chats feature.

Key findings:
- Topic IDs are relative to their parent chat, not globally unique
- General topic always has id=1
- Other topics get IDs from the messageActionTopicCreate service message
- Implementation requires chat:topic pairs format

Documents included:
- README.md: Overview and current implementation analysis
- analysis.md: Problem statement and proposed solutions
- telegram-api-reference.md: API documentation reference
- implementation-plan.md: Step-by-step implementation guide

Fixes #1100

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@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
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
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
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.

- Add TELEGRAM_ALLOWED_TOPICS config using Links Notation format "chatId topicId"
- Add parseLinks() and formatLinks() methods to lino library
- Add isTopicAuthorized() function with authorization logic:
  - If chat is in TELEGRAM_ALLOWED_CHATS, all topics allowed
  - If specific topic is in TELEGRAM_ALLOWED_TOPICS, only that topic works
- Update /help command to:
  - Always be allowed (bypass authorization for diagnostics)
  - Show topic ID in diagnostic information
  - Show configuration hint when in unauthorized topic
- Update /solve, /hive, /limits, /version to use isTopicAuthorized()
- Update dry-run output to show allowed topics configuration
- Update case study documentation with new format and logic

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@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 and others added 2 commits January 11, 2026 02:45
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add buildAuthErrorMessage helper function
- Compact verbose logging patterns
- Simplify command handlers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 11, 2026 01:55
@konard
Copy link
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.

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)

2 participants