feat: targeted announce#47
Merged
MattiaFailla merged 6 commits intomasterfrom Feb 28, 2026
Merged
Conversation
added 6 commits
February 28, 2026 23:35
Extend register_chat to accept an optional title parameter and add get_all_chats_with_titles() and find_chats_by_title() to support looking up groups by name. Updates both InMemoryRepository and PostgresRepository, and adds the title column to schema.sql.
Add get_all_chats_with_titles() and find_chats_by_title() delegation, and update register_chat to forward the title parameter.
Update welcome and moderation handlers to forward the group title to register_chat so it gets persisted for later lookup.
Add ANNOUNCE_SENDING_TARGETED, ANNOUNCE_GROUP_NOT_FOUND, ANNOUNCE_AMBIGUOUS_GROUPS, and GROUPS_LIST_* strings. Update ANNOUNCE_USAGE to document the new pipe syntax.
Rewrite announce handler to support pipe syntax for targeting a specific group: /announce <target> | <message>. Target resolution tries numeric ID, @username via Telegram API, then title search. Ambiguous title matches are reported back to the owner. Add /groups command (owner-only) to list all registered groups with their IDs and titles.
…t parsing 18 tests covering InMemoryRepository new methods (register with title, find by title, update title), ModerationService delegation, and _parse_target_and_message edge cases.
There was a problem hiding this comment.
Pull request overview
This PR implements a "targeted announce" feature for the Python Italy Telegram bot. Previously, /announce sent a message to all registered groups. Now it supports an optional target | message syntax to send to a specific group (by numeric ID, @username, or title substring). A new /groups command is also added so the owner can list all registered groups. Chat titles are now persisted alongside chat IDs so that title-based lookup is possible.
Changes:
- New
/announce <target> | <message>syntax and/groupscommand implemented inannounce.py, with target resolution logic (_resolve_target_chats) supporting numeric IDs,@usernames(via Telegram API), and case-insensitive title search. - Repository layer extended with
titlepersistence inbot_chats, newget_all_chats_with_titles()andfind_chats_by_title()methods acrossbase.py,in_memory.py,postgres.py, and a newChatdataclass inmodels.py. - Comprehensive tests for the new InMemoryRepository chat methods and
_parse_target_and_messageparser.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/python_italy_bot/handlers/announce.py |
Adds _parse_target_and_message, _resolve_target_chats, _handle_groups; extends _handle_announce with targeted send |
src/python_italy_bot/db/models.py |
New Chat dataclass |
src/python_italy_bot/db/base.py |
Adds title param to register_chat, new abstract methods get_all_chats_with_titles and find_chats_by_title |
src/python_italy_bot/db/in_memory.py |
Implements new methods; changes _bot_chats from set to dict |
src/python_italy_bot/db/postgres.py |
Implements new methods; updates register_chat to upsert title |
src/python_italy_bot/db/__init__.py |
Exports new Chat model |
src/python_italy_bot/services/moderation.py |
Delegates two new repo methods through service layer |
src/python_italy_bot/handlers/welcome.py |
Passes chat.title when registering chat |
src/python_italy_bot/handlers/moderation.py |
Passes chat.title when registering chat |
src/python_italy_bot/strings.py |
Adds new Italian string constants for targeted announce and groups list |
schema.sql |
Adds title TEXT column to bot_chats; idempotent ALTER TABLE |
tests/test_announce.py |
New test file covering InMemoryRepository chat methods and parse logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The user wants to add a targeted announce feature to their Python Italy Telegram Bot. The /announce command should support sending announcements to a specific group by group ID or group name, in addition to the existing broadcast-to-all behavior.