Skip to content

feat: add contact card spam handler for all members#7

Open
rezhajulio wants to merge 4 commits intomainfrom
feat/contact-spam-handler
Open

feat: add contact card spam handler for all members#7
rezhajulio wants to merge 4 commits intomainfrom
feat/contact-spam-handler

Conversation

@rezhajulio
Copy link
Owner

@rezhajulio rezhajulio commented Mar 14, 2026

Summary

Block contact card (phone number) sharing for all non-admin members in monitored groups. Messages are deleted, users are restricted, and a notification is sent to the warning topic.

Changes

New handler: handle_contact_spam

  • Detects and deletes Telegram contact card messages from non-admin members
  • Restricts the user (same behavior as inline keyboard spam)
  • Sends notification to warning topic (with fallback template if restrict fails)
  • Registered in its own priority group (group=2) to avoid being shadowed by other handlers
  • Admins and bots are exempt

Handler priority groups updated

group=-1  # topic_guard
group=0   # Commands, DM, captcha
group=1   # inline_keyboard_spam
group=2   # contact_spam (NEW)
group=3   # new_user_spam (was group=2)
group=4   # duplicate_spam (was group=3)
group=5   # message_handler (was group=4)

Files changed

  • src/bot/handlers/anti_spam.py — Added has_contact() helper and handle_contact_spam() handler with restrict
  • src/bot/constants.py — Added CONTACT_SPAM_NOTIFICATION and CONTACT_SPAM_NOTIFICATION_NO_RESTRICT templates
  • src/bot/main.py — Registered handler, updated group numbers
  • tests/test_anti_spam.py — 14 new tests (533 total, all passing)
  • AGENTS.md / README.md — Updated docs, mermaid diagram with restrict step

Testing

  • 533 tests, 100% pass rate
  • 99.9% coverage maintained

Block contact card (phone number) sharing for all non-admin members
in monitored groups. Messages are deleted and a notification is sent
to the warning topic. No restriction is applied.

- Add has_contact() helper and handle_contact_spam() handler
- Register handler in its own priority group (group=2)
- Shift probation/duplicate/message handlers to groups 3/4/5
- Add CONTACT_SPAM_NOTIFICATION Indonesian template
- Add 12 tests (531 total, all passing)
- Update handler descriptions and priority group numbers
- Add contact card blocking to features list
- Update test counts (519 → 531)
- Add contact spam flow to mermaid workflow diagram
- Update architecture section with new handler groups
- Add user restriction to contact spam handler (delete + restrict + notify)
- Add CONTACT_SPAM_NOTIFICATION_NO_RESTRICT fallback template
- Add tests for restrict behavior and restrict failure (533 total)
- Update README mermaid diagram with restrict step
- Update test counts in AGENTS.md and README.md
- Add contact_spam_restrict field to GroupConfig (default: true)
- Add .env fallback in config.py and build_group_registry
- Skip restrict in handler when config is false
- Add to groups.json.example and .env.example
- Add test for disabled restrict config (534 total)
- Update docs with new config option
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