mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Add ability to send messages to contacts by using their phone numbers
This commit is contained in:
parent
c33719be9e
commit
c5281eb963
@ -135,6 +135,7 @@ class Client:
|
||||
|
||||
self.peers_by_id = {}
|
||||
self.peers_by_username = {}
|
||||
self.peers_by_phone = {}
|
||||
|
||||
self.channels_pts = {}
|
||||
|
||||
@ -225,6 +226,7 @@ class Client:
|
||||
continue
|
||||
|
||||
username = entity.username
|
||||
phone = entity.phone
|
||||
|
||||
input_peer = InputPeerUser(
|
||||
user_id=user_id,
|
||||
@ -236,6 +238,9 @@ class Client:
|
||||
if username is not None:
|
||||
self.peers_by_username[username] = input_peer
|
||||
|
||||
if phone is not None:
|
||||
self.peers_by_phone[phone] = input_peer
|
||||
|
||||
if isinstance(entity, Chat):
|
||||
chat_id = entity.id
|
||||
|
||||
@ -795,6 +800,12 @@ class Client:
|
||||
if peer_id in ("self", "me"):
|
||||
return InputPeerSelf()
|
||||
|
||||
if peer_id.startswith("+"):
|
||||
try:
|
||||
return self.peers_by_phone[peer_id]
|
||||
except KeyError:
|
||||
raise PeerIdInvalid
|
||||
|
||||
peer_id = peer_id.lower().strip("@")
|
||||
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user