I create a group and add 2 users: myself and another one. got an error{ _: 'error', code: 3, message: 'User not found' }
If I try to invoke getUser with this id - I get info as expected.
It works well with some users and bots. But doesn't with other users/bots.
What could be wrong?
Thank you.
After client restart you need to call getUser to load the information about the user from database before you can use a user_id, unless you have already received the user from TDLib.
Thank you so much, it works!
It is obvious? Where I can find info about this behavior?
@gen4sp This is never needed for ordinary TDLib-based clients with interface which are supposed to save nothing between client restarts, because they can get a user_id only from TDLib. Hence this seems to be not covered by current documentation, only in some other Github issues.
In general, an object can't be used by its ID after restart before it's known to TDLib, and many get* methods are suitable for preloading such objects from the database by their ID.
I've changed an appId and now I always get
{ _: 'error', code: 6, message: 'User not found' } on getUser function invoke
but users exist.
Why it could be so?
Is there any error code reference page?
If there is no user in the database then you need to receive it from the server and it's impossible to do that just by user's ID. You need to use some other request. For example, you can use getContacts if the user is in your contact list, searchPublicChat to get it by username, getChats if it is in your chat list..
Hm, that is weird. the user id is a unique number and should work anyway, why it isn't?
My situation is the following: I have a bot, which receives messages like this
{ id: 872635786,
is_bot: false,
first_name: 'Anton',
last_name: 'Brif',
language_code: 'en' }
after that, at some point of time, I should create a group and add all users who asked the bot about that.
A group could be created only by tdlib and user I logged in in tdlib have no contact, chat or whatever other contacts with these users should be added to the group.
What the best way to handle a situation like that?
It shouldn't work because otherwise it would be possible to get all Telegram users and spam them.
You can send by the bot a message with mentions by IDs of that users, so you will be able to access them. But the final goal is likely to be not possible anyway, because a user can create only a few groups per day and because users can restrict, who will be able to invite them to groups. Also if some of the invited users reports the group, then you can be restricted and aren't allowed to invite users to groups at all for some time. The recommended way is to send users an invite link instead of adding them.
Thank you very much for the clarification, appreciate that!
Most helpful comment
It shouldn't work because otherwise it would be possible to get all Telegram users and spam them.
You can send by the bot a message with mentions by IDs of that users, so you will be able to access them. But the final goal is likely to be not possible anyway, because a user can create only a few groups per day and because users can restrict, who will be able to invite them to groups. Also if some of the invited users reports the group, then you can be restricted and aren't allowed to invite users to groups at all for some time. The recommended way is to send users an invite link instead of adding them.