Skip to content

feat(query): add GetMessages by-id helper#1752

Merged
ernado merged 2 commits into
mainfrom
feat/217-get-messages
Jun 11, 2026
Merged

feat(query): add GetMessages by-id helper#1752
ernado merged 2 commits into
mainfrom
feat/217-get-messages

Conversation

@ernado

@ernado ernado commented Jun 11, 2026

Copy link
Copy Markdown
Member

What

Adds messages.QueryBuilder.GetMessages(ctx, peer, ids...) — a helper to fetch messages by their IDs, addressing the get-by-id helpers request in #217.

msgs, err := messages.NewQueryBuilder(raw).GetMessages(ctx, peer, 10, 11, 12)

It automatically routes to channels.getMessages for channel peers and messages.getMessages otherwise. This spares callers a well-known footgun: passing channel message IDs to messages.getMessages silently returns unrelated messages instead of the requested ones. The returned []tg.MessageClass preserves the raw server response, including tg.MessageEmpty for IDs that don't exist or are inaccessible.

The helper reuses the existing channel-aware private getMessages (added alongside GetMediaGroup), so routing logic stays in one place.

Scope

#217 also mentions optional ETag/hash-based caching as a "nice to have" — that is intentionally left out here, and user/channel get-by-id is already served by telegram/peers. This PR fills the missing messages-by-id helper.

Tests

TestGetMessages (tgmock): user path asserts messages.getMessages with the expected InputMessageID list; channel path asserts channels.getMessages with the resolved InputChannel access hash; empty-ids returns an error.

Closes #217

🤖 Generated with Claude Code

ernado and others added 2 commits June 11, 2026 06:47
Add messages.QueryBuilder.GetMessages to fetch messages by their IDs in
a peer. It automatically routes to channels.getMessages for channel
peers and messages.getMessages otherwise, sparing callers the common
footgun of passing channel message IDs to messages.getMessages (which
returns unrelated messages).

Closes #217

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ernado ernado merged commit 9e46cec into main Jun 11, 2026
12 checks passed
@ernado ernado deleted the feat/217-get-messages branch June 11, 2026 04:07
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.10%. Comparing base (2797d74) to head (ac96500).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
telegram/query/messages/get_messages.go 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1752      +/-   ##
==========================================
- Coverage   71.10%   71.10%   -0.01%     
==========================================
  Files         470      471       +1     
  Lines       20736    20746      +10     
==========================================
+ Hits        14745    14751       +6     
- Misses       4913     4917       +4     
  Partials     1078     1078              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

client: get by id helpers

1 participant