Repository navigation
fix(send): take an unknown positive ID as a user, not a basic group - #53
Merged
Merged
Conversation
A 0.2.0 binary that is still running after the upgrade writes a group or channel to chats_cache under its bare ID until the next open re-keys the row. resolveCachedId skipped such a row, and a short number then reached the fallback that builds basic group N. That gave the right peer for a bare group row by chance, and basic group N for a bare channel row. Now the bare row resolves through its type to the marked ID, with the row's access hash, after users and the marked 0.2.0 lookup. This keeps the group case working once the fallback stops building basic groups (#47), and fixes the channel case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every tg command prints basic group N as -N, and a positive marked ID is a user. Yet a positive number the cache didn't know (and too short for a phone number) became basic group N, so tg send --to 4242 with an uncached user ID or a typo sent to basic group 4242, or failed with PEER_ID_INVALID. tg messages list and get --chat read the same way. Now such a number is user N with access hash 0, as for a cached user without a hash: Telegram may refuse the user, but the peer never names a group. The 10+ digit phone rule and -N for basic groups stay. The docs say so and how to get the user cached. Fixes #47 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bare-row fix in 28f8834 also changed what happens to a supergroup or channel row an older binary wrote under a 10+ digit bare ID, the usual shape of a channel ID. Before, such a row fell through to the phone rule and made a contacts.resolvePhone call, which could match an unrelated user with that number. Now it resolves to the channel with no API call. The test only covered the 4-digit 4242, which never reached the phone rule, so a change that put the phone check first would still pass. The case now runs for channel 4242 and supergroup 1234567890, with a client that answers PHONE_NOT_OCCUPIED, and asserts no API call. Both fail against the resolver before 28f8834. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Send section said an uncached 10+ digit number "is tried as a phone number first", which reads as a fallback to the user ID. There is none: resolveByPhone fails with "Could not resolve phone number N" when no account has the number. Current user IDs often have 10 digits, so a reader would expect tg send --to with such an uncached ID to reach the user. Now the section says the number is read only as a phone number, the command fails if no account has it, and the ID works once the user is cached, whatever its length. docs/api-design.md already said so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
What and why
tg send --to 4242with a user ID the cache doesn't know (or a typo) built basic group 4242, so it sent to that group or failed withPEER_ID_INVALID.tg messages listandget --chatread the number the same way. Everytgcommand prints basic group N as-N, and a positive marked ID is a user.Fixes #47
Fix
resolveUncachedId(src/commands/send/peer-resolver.ts) now takes an uncached positive number as user N with access hash 0, the way the resolver already handles a cached user that has no hash. It builds the peer withtoInputPeerFromPeerId, so IDs are still converted only intelegram-peer-ids.ts. Telegram may refuse that user, but the peer never names a group. The 10+ digit phone rule and-Nfor basic groups stay as they were: an uncached number with 10 or more digits is still read only as a phone number, with no fallback to a user ID.INVALID_ARGS. I picked the user, as the issue's context suggests. A user ID is the only thing a positive marked ID can mean, and once the user is cached through@usernameor+phone, the same ID works, whatever its length.contacts.resolvePhonecall, which could match an unrelated user with that number; it now resolves to the channel with no API call. Without this commit, the rule above would have made a short bare row user N.docs/api-design.md(Peer Resolution) anddocs/cli-commands.md(Send) describe the new rule, that an uncached 10+ digit number is only a phone number, and how to get a user cached so its ID works.Callers checked:
tg sendandtg messages list/get(throughresolveHistoryChat) are the only callers ofresolvePeer.tg chats get --idandtg chats syncare cache-only (findCachedChatById) and haven't changed.How I checked it
bun run check,bun run test(1560 pass) andbun run test:e2e(193 pass) all pass locally. No live Telegram run.New tests, each failing before its change:
peer-resolver.test.ts:resolvePeer('4242')with an empty cache, and with messages cached only in group-4242, givesinputPeerUser4242 with hash 0, notinputPeerChat;'-4242'still givesinputPeerChat4242. A bare channel row 4242 and a bare supergroup row 1234567890 from an older binary resolve to the channel with its access hash and no API call, with a client that answersPHONE_NOT_OCCUPIED(before, the 10-digit one went to a phone lookup and failed).send.test.ts: thesendcommand with an empty cache callsmessages.sendMessagewith user 4242.resolvePeer('12345')with an empty cache gives a user, replacing the old "fallback to inputPeerChat" case.messages-history-command.test.ts:resolveHistoryChat('4343')gives chat 4343 (the user's DM) and'-4343'gives-4343, with no API call.Tests pass locally and use made-up data only
README, docs and affected demos follow the product content standard
Title follows Conventional Commits
🤖 Generated with Claude Code