Repository navigation
AI spam: classify captions, log alert delivery, add /testalert - #49
Merged
rezhajulio merged 2 commits intoOct 9, 2026
Merged
Conversation
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.
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.
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 misconfiguredai_spam_alert_chat_idproduced no visible signal.Changes
Caption support (
handlers/ai_spam_monitor.py)_classifiable_text()helper returnsmessage.text or message.caption or "".ai_spam_filterandhandle_ai_spam_monitornow match/classify text or caption (still skips commands, short texts, bots, admins/trusted).Alert delivery logging (
handlers/ai_spam_monitor.py)chat_idbefore sending, success confirmation after.chat_idin the error log.New
/testalertDM command/testalertsends a clearly-marked test message to the configuredai_spam_alert_chat_idof 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.handlers/testalert.py+plugins/builtin/testalert.py, registered inmanager.py/definitions.py(MANIFEST_ORDER); notguard_plugin-gated, same as/status.Verification
pytest), including 9 new/testalerttests and 6 new caption/filter tests;test_plugin_managerexpectations updated for the new plugin.ruff checkandmypyclean.explicit0.98.Note
Bot API
chat_idfor a group is the numeric group id, soai_spam_alert_chat_idshould be the (negative) admin group id with the bot as a member —/testalertconfirms exactly this.