Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 'phonenumbers' for '_is_phone_number()' #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 24 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ aiohttp = "^3.8.1"
python = "^3.9"
redis = "^4.1.4"
websockets = "^10.2"
phonenumbers = "^8.13.37"

[tool.poetry.dev-dependencies]
black = "^22.1.0"
Expand Down
11 changes: 5 additions & 6 deletions signalbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Optional, Union, List, Callable
import re
import uuid
import phonenumbers

from .api import SignalAPI, ReceiveMessagesError
from .command import Command
Expand Down Expand Up @@ -255,13 +256,11 @@ def _resolve_receiver(self, receiver: str) -> str:
raise SignalBotError(f"Cannot resolve receiver.")

def _is_phone_number(self, phone_number: str) -> bool:
if phone_number is None:
return False
if phone_number[0] != "+":
return False
if len(phone_number[1:]) > 15:
try:
parsed_number = phonenumbers.parse(phone_number, None)
return phonenumbers.is_valid_number(parsed_number)
except phonenumbers.phonenumberutil.NumberParseException:
return False
return True

def _is_valid_uuid(self, receiver_uuid: str):
try:
Expand Down
Loading