feat(query): generate peer-resolve helpers for query builders#1779
Merged
Conversation
Generate `<Method>Resolve(from string)` helpers for query builders that
take a tg.InputPeerClass parameter, so callers can pass a domain, phone
or deeplink directly instead of resolving the peer by hand first:
query.NewQuery(raw).Messages().GetHistoryResolve("telegram").ForEach(ctx, cb)
The package QueryBuilder now carries a peer.Resolver (defaulting to
peer.DefaultResolver, overridable via WithResolver). The peer is resolved
lazily inside Query, wrapping resolve errors per context-error semantics.
Closes #283
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1779 +/- ##
==========================================
+ Coverage 71.24% 71.26% +0.01%
==========================================
Files 503 503
Lines 23593 23602 +9
==========================================
+ Hits 16809 16819 +10
- Misses 5551 5552 +1
+ Partials 1233 1231 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
pull Bot
pushed a commit
to dumpmemory/td
that referenced
this pull request
Jun 15, 2026
Query builders that take a peer now accept peer.InputPeer, so a peer can
be addressed by username/phone/deeplink and resolved lazily instead of
being resolved by hand beforehand:
query.NewQuery(raw).Messages().GetHistory(peer.Resolve("durov")).ForEach(ctx, cb)
Concrete tg.InputPeerClass values still work unchanged, as they satisfy
peer.InputPeer. The package QueryBuilder carries a peer.Resolver
(peer.DefaultResolver by default, overridable via WithResolver) and the
peer is resolved inside Query, wrapping errors per context-error
semantics.
peer.Resolve is repurposed to take a single textual argument and return a
lazy *Resolved reference; bind a resolver with Resolved.Bind to get a
Promise. peer.ResolveInputPeer resolves a peer.InputPeer to a concrete
tg.InputPeerClass.
This replaces the generated GetHistoryResolve-style helpers (gotd#1779) with
the API requested in the original issue.
BREAKING CHANGE: peer.Resolve(resolver, from) is now peer.Resolve(from);
use peer.Resolve(from).Bind(resolver) for the previous behavior.
Closes gotd#283
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #283.
Problem
Query builders that take a peer required the caller to resolve the peer by hand first:
Change
The
itergengenerator now emits a<Method>Resolve(from string)sibling for every query builder that has a requiredtg.InputPeerClassparameter, so the peer can be addressed by domain / phone / deeplink directly:QueryBuildernow carries apeer.Resolver, defaulting topeer.DefaultResolver(raw)and overridable viaWithResolver(...)— mirroringmessage.Sender.Query(ctx, …)and cached; resolve errors are wrapped so context cancellation surfaces correctly.fromaccepts the same inputs aspeer.Resolve(@telegram,telegram,t.me/telegram,tg://resolve?domain=…, phone numbers).messagesbuilders:GetHistory,GetRecentLocations,GetReplies,GetSavedHistory,GetUnreadMentions,GetUnreadPollVotes,GetUnreadReactions,Search.photos,participants,dialogs, …) are unchanged.Generator-only edits
Per
CLAUDE.md, only the generator was hand-edited;messages/queries.gen.gois regenerated.make generateis stable (no further diff).Testing
go test -race ./telegram/query/...— green, including newresolve_test.gocovering the default-resolver path and a customWithResolverpath.ExampleQuery_resolveHistory.go build ./...,go vet ./telegram/query/...clean.🤖 Generated with Claude Code