mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Created Retrieving an entity (markdown)
parent
e5df84dbed
commit
f0e568521d
28
Retrieving-an-entity.md
Normal file
28
Retrieving-an-entity.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
An "entity" is used to refer to either an [`User`](https://lonamiwebs.github.io/Telethon/types/user.html) or a [`Chat`](https://lonamiwebs.github.io/Telethon/types/chat.html) (which includes a [`Channel`](https://lonamiwebs.github.io/Telethon/constructors/channel.html)). Perhaps the most straightforward way to get these is by [resolving their username](https://lonamiwebs.github.io/Telethon/methods/contacts/resolve_username.html):
|
||||
|
||||
```python
|
||||
from telethon.tl.functions.contacts import ResolveUsernameRequest
|
||||
|
||||
result = client.invoke(ResolveUsernameRequest('username'))
|
||||
found_chats = result.chats
|
||||
found_users = result.users
|
||||
# result.peer may be a PeerUser, PeerChat or PeerChannel
|
||||
```
|
||||
|
||||
See [`Peer`](https://lonamiwebs.github.io/Telethon/types/peer.html) for more information about this result.
|
||||
|
||||
If the user you want to talk to is a contact, you can use [`GetContactsRequest`](https://lonamiwebs.github.io/Telethon/methods/contacts/get_contacts.html):
|
||||
|
||||
```python
|
||||
from telethon.tl.functions.contacts import GetContactsRequest
|
||||
from telethon.tl.types.contacts import Contacts
|
||||
|
||||
# `.sign_in()´ returns your User, otherwise use:
|
||||
self_user = client.get_me()
|
||||
contacts = client.invoke(GetContactsRequest(self_user.access_hash))
|
||||
if isinstance(contacts, Contacts):
|
||||
users = contacts.users
|
||||
contacts = contacts.contacts
|
||||
```
|
||||
|
||||
If, on the other hand, all you know is that your contact is somewhere in your chat list, you can try [retrieving all dialogs](Retrieving-all-dialogs).
|
Loading…
Reference in New Issue
Block a user