Skip to content

Allow telegram bot only in whitelisted chats - #5262

Open
tspenov wants to merge 1 commit into
masterfrom
allo-telegram-bot-in-whitelisted-chats
Open

Allow telegram bot only in whitelisted chats#5262
tspenov wants to merge 1 commit into
masterfrom
allo-telegram-bot-in-whitelisted-chats

Conversation

@tspenov

@tspenov tspenov commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Changes

Ticket

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have tried to find clearer solution before commenting hard-to-understand parts of code
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • New Features

    • Added configurable access controls for the Telegram Q&A bot.
    • Administrators can allow specific chats by numeric ID or username, or allow all chats.
    • Messages from non-whitelisted chats are silently ignored.
  • Documentation

    • Documented the new environment variable and its supported configuration formats.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Telegram Q&A bot now reads TELEGRAM_QA_BOT_ALLOWED_CHAT_IDS, matches chats by username or numeric ID, supports *, falls back to defaults when unset, and ignores non-whitelisted group messages with logging. The README documents the configuration.

Changes

Telegram Q&A chat whitelist

Layer / File(s) Summary
Whitelist contract and enforcement
lib/sanbase/telegram_bot/message_handler.ex, lib/sanbase/telegram_bot/README.md
The handler parses whitelist entries, supports default and allow-all behavior, matches usernames or numeric chat IDs, logs rejected chats, and documents the environment variable.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: restricting the Telegram bot to whitelisted chats.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch allo-telegram-bot-in-whitelisted-chats

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/sanbase/telegram_bot/message_handler.ex (1)

34-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove in-code comments to comply with coding guidelines.

As per coding guidelines, you must "Avoid adding comments to code". The information in these comments is either self-evident from the implementation or already comprehensively covered in the module's @moduledoc. Please remove them to maintain compliance with the project's standards.

  • lib/sanbase/telegram_bot/message_handler.ex#L34-L38: Remove the comments preceding @default_allowed_chats.
  • lib/sanbase/telegram_bot/message_handler.ex#L95-L95: Remove the inline comment about replying to a bot answer.
  • lib/sanbase/telegram_bot/message_handler.ex#L104-L107: Remove the comments preceding the chat_allowed?/1 function.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/sanbase/telegram_bot/message_handler.ex` around lines 34 - 38, Remove the
comments at lib/sanbase/telegram_bot/message_handler.ex lines 34-38, 95, and
104-107, including the comments before `@default_allowed_chats`, the inline
bot-answer reply comment, and the comments before chat_allowed?/1; leave the
associated implementation unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/sanbase/telegram_bot/message_handler.ex`:
- Around line 34-38: Remove the comments at
lib/sanbase/telegram_bot/message_handler.ex lines 34-38, 95, and 104-107,
including the comments before `@default_allowed_chats`, the inline bot-answer
reply comment, and the comments before chat_allowed?/1; leave the associated
implementation unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0c147db-9de0-4b4d-add7-8d2cb55107c9

📥 Commits

Reviewing files that changed from the base of the PR and between 138ff53 and 3181d2f.

📒 Files selected for processing (2)
  • lib/sanbase/telegram_bot/README.md
  • lib/sanbase/telegram_bot/message_handler.ex

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