Skip to content

feat(telegram): channel whitelist + auto-leave with message#101

Open
asdigitos wants to merge 1 commit intoPleasePrompto:mainfrom
asdigitos:feature/channel-whitelist-auto-leave
Open

feat(telegram): channel whitelist + auto-leave with message#101
asdigitos wants to merge 1 commit intoPleasePrompto:mainfrom
asdigitos:feature/channel-whitelist-auto-leave

Conversation

@asdigitos
Copy link
Copy Markdown

Summary

  • Adds allowed_channel_ids: list[int] config field so Telegram channels can be explicitly whitelisted, separate from allowed_group_ids (which covers groups/supergroups)
  • When the bot is added to a non-whitelisted channel it sends "This channel is not whitelisted, I am out." before leaving — instead of reusing the group rejection message or leaving silently
  • audit_groups now correctly exempts whitelisted channels from periodic eviction
  • allowed_channel_ids is hot-reloadable (edit config.json, takes effect within seconds, no restart needed)

Changed files

File Change
ductor_bot/config.py Add allowed_channel_ids field
ductor_bot/messenger/telegram/app.py Branch _on_bot_added on chat.type == "channel"; fix audit_groups; hot-reload
ductor_bot/i18n/en/chat.toml Add telegram.channel_not_whitelisted string
tests/messenger/telegram/test_channel_whitelist.py 14 new tests (config, _on_bot_added, audit_groups, hot-reload)

Test plan

  • pytest tests/messenger/telegram/test_channel_whitelist.py — 14/14 pass
  • pytest tests/messenger/ — 780/780 pass, no regressions
  • ruff format + ruff check — clean
  • Manual: add bot to a non-whitelisted channel → bot sends message and leaves
  • Manual: add channel ID to allowed_channel_ids → bot stays and sends join notification

Config example

{
  "allowed_group_ids": [-100123456789],
  "allowed_channel_ids": [-100987654321]
}

Note: Other language strings (de, fr, es, ru, pt, nl) still use the English fallback for channel_not_whitelisted. Native translations welcome in follow-up PRs.

🤖 Generated with Claude Code

Adds `allowed_channel_ids` config field so Telegram channels can be
explicitly whitelisted, separate from `allowed_group_ids`.

When the bot is added to a non-whitelisted channel it now sends
"This channel is not whitelisted, I am out." before leaving, instead
of silently leaving or reusing the group rejection message.

Changes:
- config.py: `allowed_channel_ids: list[int]` field (default [])
- app.py _on_bot_added: branch on chat.type == "channel" to pick the
  right allowlist and i18n key; logs use "channel"/"group" correctly
- app.py audit_groups: channels are checked against allowed_channel_ids
  so whitelisted channels are not evicted during periodic audits
- app.py _on_auth_hot_reload: hot-reload support for allowed_channel_ids
- i18n/en/chat.toml: new `telegram.channel_not_whitelisted` string
- tests: 14 new tests covering config, _on_bot_added, audit_groups,
  and hot-reload for the channel whitelist feature

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