From 5a44b93574a47af7ba227141af5495e98aaf1202 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Feb 2018 15:48:10 +0100 Subject: [PATCH] Accept phone numbers with and without a leading "+" --- pyrogram/client/client.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 8f149c94..2548998c 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -800,19 +800,21 @@ class Client: if peer_id in ("self", "me"): return InputPeerSelf() - if peer_id.startswith("+"): + peer_id = peer_id.lower().strip("@+") + + try: + int(peer_id) + except ValueError: + try: + return self.peers_by_username[peer_id] + except KeyError: + return self.resolve_username(peer_id) + else: try: return self.peers_by_phone[peer_id] except KeyError: raise PeerIdInvalid - peer_id = peer_id.lower().strip("@") - - try: - return self.peers_by_username[peer_id] - except KeyError: - return self.resolve_username(peer_id) - if type(peer_id) is not int: if isinstance(peer_id, types.PeerUser): peer_id = peer_id.user_id