Skip to content

AI spam: classify captions, log alert delivery, add /testalert - #49

Merged
rezhajulio merged 2 commits into
rezhajulio:mainfrom
TayoBus:fix/ai-spam-caption-alert-log
Oct 9, 2026
Merged

rezhajulio merged 2 commits into
rezhajulio:mainfrom
TayoBus:fix/ai-spam-caption-alert-log

Conversation

@TayoBus

@TayoBus TayoBus commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Context

Porn spam (forwarded channel posts, payload in the media caption) bypassed the AI spam monitor: the filter and handler only inspected message.text, so caption-carried spam never reached classifier.dev. Separately, alert delivery failures were silent — a misconfigured ai_spam_alert_chat_id produced no visible signal.

Changes

Caption support (handlers/ai_spam_monitor.py)

  • New _classifiable_text() helper returns message.text or message.caption or "".
  • ai_spam_filter and handle_ai_spam_monitor now match/classify text or caption (still skips commands, short texts, bots, admins/trusted).

Alert delivery logging (handlers/ai_spam_monitor.py)

  • Warning when no alert chat is configured for the group (previously a silent return).
  • Info log with the target chat_id before sending, success confirmation after.
  • Send failures now include the chat_id in the error log.

New /testalert DM command

  • Admin-only, DM-only: /testalert sends a clearly-marked test message to the configured ai_spam_alert_chat_id of every group the caller admins (or one group via /testalert <group_id>), then reports ✅/❌ per group in the DM with the chat id used and the error detail on failure.
  • New handlers/testalert.py + plugins/builtin/testalert.py, registered in manager.py/definitions.py (MANIFEST_ORDER); not guard_plugin-gated, same as /status.

Verification

  • 1299 tests pass (pytest), including 9 new /testalert tests and 6 new caption/filter tests; test_plugin_manager expectations updated for the new plugin.
  • ruff check and mypy clean.
  • Classifier sanity-checked live against the reported spam text: explicit 0.98.

Note

Bot API chat_id for a group is the numeric group id, so ai_spam_alert_chat_id should be the (negative) admin group id with the bot as a member — /testalert confirms exactly this.

The AI spam monitor only inspected message.text, so spam sent as a
photo/video with the payload in the caption never reached the
classifier. Match and classify message.text or message.caption.

Also add logging around alert delivery: warn when no alert chat is
configured, log the target chat id before/after sending, and include
the chat id on send failures, so a misconfigured ai_spam_alert_chat_id
is visible in Logfire instead of failing silently.
Admin-only DM command: sends a clearly-marked test message to the
configured ai_spam_alert_chat_id of the caller's admin groups (or a
single group via /testalert <group_id>) and reports per-group
success/failure back in the DM, including the chat id used and the
error on failure. Lets an admin confirm the alert chat is correct and
reachable without waiting for real spam.
@rezhajulio
rezhajulio merged commit 7619ba0 into rezhajulio:main Oct 9, 2026
6 checks passed
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.

2 participants