Telegram client API : USER_ID_INVALID for all except me

130 views Asked by At

Faced with some strange issue using Telegram Client API. I use https://github.com/wiz0u/WTelegramClient to read messages from group i am already in.

But on new message event - i can't retrieve user's username by calling Client.Users_GetFullUser method - it firing "USER_ID_INVALID". It works well for me as a user, but not for the sender of exact message to the chat...

Can't find the information why it may happens. Any limitations from Telegram's side?

//works like a charm
Users.TryGetValue({my_id}, out var u);
var usr = await Client.Users_GetFullUser(new InputUser({my_id}, u.access_hash));

//does not work, USER_ID_INVALID throwing
Users.TryGetValue(unm.message.From.ID, out var u);
var usr = await Client.Users_GetFullUser(new InputUser(unm.message.From.ID, u.access_hash));
1

There are 1 answers

0
Nigrimmist On

The reason is Privacy/Perf optimizations :

Check documentation : https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md#4-how-to-use-ids-and-access_hash-why-the-error-channel_invalid-or-user_id_invalid

It says :

Note: An access_hash obtained from a User/Channel structure with flag min may not be usable for most requests. See Min constructors.

This flag described here : https://core.telegram.org/api/min

So the reason is : all users are coming with Base info (with min flag) and to get extended information, you need any "proof". MessageId from Chat is enough, see working solution.

//working solution
var usr = await Client.Users_GetFullUser(new InputUserFromMessage()
{
    user_id = unm.message.From.ID,
    msg_id = unm.message.ID,
    peer = _chats.chats[unm.message.Peer.ID].ToInputPeer()
});