Skip to content

feat: targeted announce#47

Merged
MattiaFailla merged 6 commits intomasterfrom
feature/targeted-announce
Feb 28, 2026
Merged

feat: targeted announce#47
MattiaFailla merged 6 commits intomasterfrom
feature/targeted-announce

Conversation

@MattiaFailla
Copy link
Copy Markdown
Member

@MattiaFailla MattiaFailla commented Feb 28, 2026

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.

0xMett 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.
Copilot AI review requested due to automatic review settings February 28, 2026 22:36
@MattiaFailla MattiaFailla self-assigned this Feb 28, 2026
@MattiaFailla MattiaFailla added the enhancement New feature or request label Feb 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 /groups command implemented in announce.py, with target resolution logic (_resolve_target_chats) supporting numeric IDs, @usernames (via Telegram API), and case-insensitive title search.
  • Repository layer extended with title persistence in bot_chats, new get_all_chats_with_titles() and find_chats_by_title() methods across base.py, in_memory.py, postgres.py, and a new Chat dataclass in models.py.
  • Comprehensive tests for the new InMemoryRepository chat methods and _parse_target_and_message parser.

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

Comment thread src/python_italy_bot/db/postgres.py
Comment thread src/python_italy_bot/db/in_memory.py
Comment thread src/python_italy_bot/db/postgres.py
Comment thread src/python_italy_bot/handlers/announce.py
@MattiaFailla MattiaFailla merged commit 2ff2273 into master Feb 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants