Handle Telegram forward-to-bot provenance#12
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d292c78ff6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| DedupeKey: provider.DedupeKey{ | ||
| ProviderID: ProviderID, | ||
| Value: fmt.Sprintf("%s:%s", externalID, ref.StableID()), | ||
| Value: externalID, |
There was a problem hiding this comment.
Preserve Telegram dedupe compatibility
For installations that have already scraped Telegram media, DownloadedPhoto.URL is stored from stableDedupeKey, and before this change Telegram keys included the media stable ID (<chat>:<message>:<file_unique_id>). This line now emits only <chat>:<message>, while duplicate detection only checks the exact new key for Telegram, so previously kept Telegram items will be treated as new and re-downloaded/re-recorded after upgrade. Keep the old key shape or add a Telegram legacy lookup/migration before changing it.
Useful? React with 👍 / 👎.
| Type string `json:"type"` | ||
| SenderUser *User `json:"sender_user"` | ||
| SenderUserName string `json:"sender_user_name"` | ||
| Chat *Chat `json:"chat"` |
There was a problem hiding this comment.
Parse MessageOriginChat sender_chat
For forwards where Telegram reports forward_origin.type == "chat" (messages originally sent on behalf of a group/chat), the origin payload uses sender_chat, not chat. With only this field mapped, o.Chat stays nil, ForwardOrigin.SourceRef returns false, and the later fallback records the bot/private chat instead of the original collection, so those forwarded media lose their source provenance. Add a sender_chat path before falling back.
Useful? React with 👍 / 👎.
| if ref.MessageID > 0 { | ||
| return ref | ||
| } | ||
| if m.ForwardSenderName != "" { | ||
| ref.ChatName = m.ForwardSenderName | ||
| } | ||
| if m.ForwardSignature != "" { | ||
| ref.ChatName = m.ForwardSignature | ||
| } | ||
| } |
There was a problem hiding this comment.
Preserve legacy chat provenance
When Telegram sends forward_from_chat without forward_from_message_id, SourceRef builds the origin chat ref but never returns it, so the code falls through to the bot message as the source. The legacy message id is optional, so these forwards lose the source channel or group metadata instead of using the origin collection with bot-message dedupe fallback.
Context Used: Review OK Folio pull requests as a merge gate. Pri... (source)
Artifacts
Repro: focused Go test for legacy forward_from_chat without forward_from_message_id
- Contains supporting evidence from the run (text/x-go; charset=utf-8).
Repro: verbose go test output showing HTTP 200 OK and dropped origin collection metadata
- Keeps the command output available without making the summary code-heavy.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/provider/telegram/types.go
Line: 117-126
Comment:
**Preserve legacy chat provenance**
When Telegram sends `forward_from_chat` without `forward_from_message_id`, `SourceRef` builds the origin chat ref but never returns it, so the code falls through to the bot message as the source. The legacy message id is optional, so these forwards lose the source channel or group metadata instead of using the origin collection with bot-message dedupe fallback.
**Context Used:** Review OK Folio pull requests as a merge gate. Pri... ([source](greptile.json))
How can I resolve this? If you propose a fix, please make it concise.
Refs #6
What changed
forward_originand legacyforward_from_chatintoDiscoveredMediasource metadata.<source_chat>:<source_message_id>:<file_unique_id>or<bot_chat>:<message_id>:<file_unique_id>while keepingSource.ExternalIDas the source/bot message identity.forward_origin.sender_chatforMessageOriginChatforwards so forwarded group/chat posts keep their original collection provenance.file_idand fixture-backed tests without live credentials.Verification
Maestro-Backend: codex (0-9m); codex (9m-end, in_place_respawn)
Greptile Summary
This PR adds Telegram forwarded-media provenance handling. The main changes are:
forward_originmetadata into discovered media source fields.forward_from_chatandforward_from_message_idprovenance.file_id.Confidence Score: 4/5
Mostly safe to merge after fixing the legacy Telegram forward provenance handling so channel/group source metadata is preserved when the original message id is absent.
The change is narrow and fixture-backed, and the remaining issue is isolated to legacy Telegram forward metadata handling rather than the broader media download path.
internal/provider/telegram/types.go
What T-Rex did
Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "Fix Telegram forward provenance dedupe" | Re-trigger Greptile
Context used: