Add forward spam detection via quote text and external reply photo OCR#115
Merged
Add forward spam detection via quote text and external reply photo OCR#115
Conversation
Szer
commented
Feb 27, 2026
Spam forwarded as "reply to external message" was bypassing ML because the bot only analyzed message.Text/Caption and message.Photo. Now we extract text from message.Quote and run OCR on message.ExternalReply.Photo, prepending the result before the original message text so the ML pipeline sees the full content. Feature-flagged via FORWARD_SPAM_DETECTION_ENABLED (default: true). Made-with: Cursor
fe89d6b to
43c9d81
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the bot’s spam-detection enrichment pipeline to include forwarded/quoted content by prepending message.Quote.Text and OCR text from message.ExternalReply.Photo to the message text, controlled by a new FORWARD_SPAM_DETECTION_ENABLED configuration flag.
Changes:
- Add
ForwardSpamDetectionEnabledtoBotConfigurationand wire it toFORWARD_SPAM_DETECTION_ENABLED(defaulttrue). - Add forwarded-content enrichment (quote text + external reply photo OCR) and refactor shared OCR logic into
ocrPhotos. - Extend test utilities and add ML tests covering quote and external reply OCR scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/VahterBanBot/Types.fs | Adds ForwardSpamDetectionEnabled to configuration. |
| src/VahterBanBot/Program.fs | Reads FORWARD_SPAM_DETECTION_ENABLED env var (default true). |
| src/VahterBanBot/Bot.fs | Adds forwarded-content enrichment + shared ocrPhotos; wires enrichment into onUpdate. |
| src/VahterBanBot.Tests/ContainerTestBase.fs | Sets forward-spam env var appropriately for ML-enabled/disabled containers. |
| src/VahterBanBot.Tests/TgMessageUtils.fs | Adds helpers for TextQuote / ExternalReplyInfo; extends quickMsg. |
| src/VahterBanBot.Tests/MLBanTests.fs | Adds tests for spam/ham detection via quote text and external reply photo OCR. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…itored chats - ocrPhotos: handle case where all candidate photos have null FileSize by falling back to largest by dimensions instead of throwing on empty sequence. Extracted selectLargestPhoto to avoid FS3511 in task CE. - tryEnrichMessageWithForwardedContent and tryEnrichMessageWithOcr now skip processing for messages from chats not in ChatsToMonitor, avoiding unnecessary OCR network calls. Made-with: Cursor
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.
Summary
message.Quote.Textand running OCR onmessage.ExternalReply.Photo, prepending the content before the original message text so ML sees the full pictureFORWARD_SPAM_DETECTION_ENABLEDenv var (default:true)ocrPhotoshelper to deduplicate the photo-to-text pipeline between existing OCR enrichment and the new forward enrichmenttryEnrichMessageWithOcrandtryEnrichMessageWithForwardedContentnow skip messages from non-monitored chats, avoiding unnecessary OCR/network callsocrPhotosnow handles the case where all candidate photos have nullFileSizeby falling back to largest by dimensions instead of throwing on an empty sequenceChanges
ForwardSpamDetectionEnabledtoBotConfigurationFORWARD_SPAM_DETECTION_ENABLEDenv var (defaulttrue)tryEnrichMessageWithForwardedContent+ocrPhotos/selectLargestPhotohelpers, called inonUpdatebefore existing OCR enrichment; added monitored-chat guards to both enrichment functionstrue) and ML-disabled (false) test containersTg.textQuote,Tg.externalReplyhelpers; addedquote/externalReplyparams toTg.quickMsgTest plan