From 71b6e527a6c867a3c7ac7a534791e0ecb2922aaa Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 1 Oct 2017 14:21:17 +0200 Subject: [PATCH] Allow using parenthesis or spaces in phones when .get_entity --- telethon/telegram_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 45d42440..56c55fa6 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -3,6 +3,8 @@ from datetime import datetime, timedelta from functools import lru_cache from mimetypes import guess_type +import re + try: import socks except ImportError: @@ -852,10 +854,10 @@ class TelegramClient(TelegramBareClient): return self(GetChannelsRequest([input_entity]))[0] if isinstance(entity, str): - if entity.startswith('+') or entity.isdigit(): + stripped_phone = re.sub(r'[+-()\s]', '', entity) + if stripped_phone.isdigit(): contacts = self(GetContactsRequest(0)) try: - stripped_phone = entity.strip('+') return next( u for u in contacts.users if u.phone and u.phone.endswith(stripped_phone)