telethon fetch access_hass by user_id

3.9k views Asked by At

I am trying to send a message to a user that does not have username and not in my contact list (using telethon ), but I don't know the access_hash, only the user_id.

1- Is it possible to do that?

2- How do I fetch the access_hash for a user?

1

There are 1 answers

0
Lonami On

No library can figure out the access_hash from only the user, chat or channel ID. However, if the library has "seen" this user before (through .get_dialogs(), or through an Update, or in any other way).

Telethon will by default save the received information into the *.session file. To make use of it, call client.get_input_entity(user_id), and it will return a InputPeerUser if possible (i.e. the library saw such user). This function also accepts usernames and phone numbers, in case those are more convenient, and don't forget to check the official documentation.