Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Era-Dorta committed Oct 6, 2024
2 parents 8d98fb9 + 628ea80 commit 6974dff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ maintainers = ["René Filip"]
name = "signalbot"
readme = "README.md"
repository = "https://github.com/filipre/signalbot"
version = "0.9.2"
version = "0.10.1"

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

from .api import SignalAPI, ReceiveMessagesError
from .command import Command
Expand Down Expand Up @@ -240,6 +241,9 @@ def _resolve_receiver(self, receiver: str) -> str:
if self._is_phone_number(receiver):
return receiver

if self._is_valid_uuid(receiver):
return receiver

if self._is_group_id(receiver):
return receiver

Expand All @@ -259,6 +263,13 @@ def _is_phone_number(self, phone_number: str) -> bool:
return False
return True

def _is_valid_uuid(self, receiver_uuid: str):
try:
uuid.UUID(str(receiver_uuid))
return True
except ValueError:
return False

def _is_group_id(self, group_id: str) -> bool:
"""Check if group_id has the right format, e.g.
Expand Down
9 changes: 9 additions & 0 deletions signalbot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Message:
def __init__(
self,
source: str,
source_number: Optional[str],
source_uuid: str,
timestamp: int,
type: MessageType,
text: str,
Expand All @@ -27,6 +29,8 @@ def __init__(
):
# required
self.source = source
self.source_number = source_number
self.source_uuid = source_uuid
self.timestamp = timestamp
self.type = type
self.text = text
Expand Down Expand Up @@ -74,10 +78,13 @@ async def parse(cls, signal: SignalAPI, raw_message: str):
# General attributes
try:
source = raw_message["envelope"]["source"]
source_uuid = raw_message["envelope"]["sourceUuid"]
timestamp = raw_message["envelope"]["timestamp"]
except Exception:
raise UnknownMessageFormatError

source_number = raw_message["envelope"].get("sourceNumber")

# Option 1: syncMessage
if "syncMessage" in raw_message["envelope"]:
type = MessageType.SYNC_MESSAGE
Expand Down Expand Up @@ -113,6 +120,8 @@ async def parse(cls, signal: SignalAPI, raw_message: str):

return cls(
source,
source_number,
source_uuid,
timestamp,
type,
text,
Expand Down

0 comments on commit 6974dff

Please sign in to comment.