Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ability to send messages to contacts by using their phone numbers
  • Loading branch information
delivrance committed Feb 20, 2018
commit c5281eb963d0bbc9f3627dbcfa0e8a3ef5a8754b
11 changes: 11 additions & 0 deletions pyrogram/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(self,

self.peers_by_id = {}
self.peers_by_username = {}
self.peers_by_phone = {}

self.channels_pts = {}

Expand Down Expand Up @@ -225,6 +226,7 @@ def fetch_peers(self, entities: list):
continue

username = entity.username
phone = entity.phone

input_peer = InputPeerUser(
user_id=user_id,
Expand All @@ -236,6 +238,9 @@ def fetch_peers(self, entities: list):
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

Expand Down Expand Up @@ -795,6 +800,12 @@ def resolve_peer(self, peer_id: int or str):
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:
Expand Down