resolvePeer doesn't work for private channels #76
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
rfc
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: teidesu/mtcute#76
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I have faced with problem that
GetMessageByLink
(and probably some other methods) fail for private channels.When I call this method for message in private channel, method fails with error:
Looks like
resolvePeer
method doesn't work well for private channels. See my investigation below.To Reproduce
Call
client.GetMessageByLink("https://t.me/c/1339581220/20441")
Expected behavior
GetMessageByLink
should resolve message correctly.Environment
Issue doesn't depend on exact environment. It is reproduced with latest version of mtcute.
Investigation and potential root cause
All mtcute methods call resolvePeer method under hood.
resolvePeer
method searches for peer in cache. If peer is not found in cache,resolvePeer
tries to resolve peer using Telegram API.It calls two different API methods based on peer id format:
Public telegram channels have links like
https://t.me/science/3774
wherescience
is channel name.resolvePeer
works fine becausecontacts.resolveUsername
works for public channels.Private telegram channels have links like
https://t.me/c/1339581220/20441
where1339581220
is channel Id.resolvePeer
fails to resolve channel by Id and fails.I think
resolvePeer
should be improved with additional case for private telegram channels. In case if peer id is channel id,resolvePeer
method should callchannels.getChannels
API.Workaround
I managed to overcome this bug using the following code. Obviously, it is just a workaround and correct fix will be improving
resolvePeer
to handle private channels correctly.your investigation is unfortunately not exactly correct.
getMessageByLink
correctly detects the channel id, but the peer is not cached and thus mtcute cannot reliably get it.using it with
access_hash=0
is a workaround that is very fragile and works in some very limited cases, the better solution would be to usefindDialogs
, as mentioned in the faq(btw, instead of parsing like that you might want to use links.message.parse. and explicitly saving the peer is not necessary, it's cached automatically.)
the one thing i could improve with
resolvePeer
is to try fetching the channel withaccess_hash=0
and only then fail, but im not sure i want to do additional implicit network requests. might be worth it putting it behind some feature flag.