aboutsummaryrefslogtreecommitdiffstats
path: root/signald/main.py
diff options
context:
space:
mode:
authorStavros Korokithakis <hi@stavros.io>2018-12-06 17:14:15 +0200
committerStavros Korokithakis <hi@stavros.io>2018-12-06 17:14:15 +0200
commitebcdbfa987cfd0434a0915e22905a471d7fbd31b (patch)
treef8ebd1b5f7a43b09f7a5c2a43c36cd070d9cc24c /signald/main.py
parent4770bd2f277eac1a11ae3cfbe5757f5ce67b1982 (diff)
downloadpysignald-ebcdbfa987cfd0434a0915e22905a471d7fbd31b.tar.gz
pysignald-ebcdbfa987cfd0434a0915e22905a471d7fbd31b.zip
Add message type
Diffstat (limited to 'signald/main.py')
-rw-r--r--signald/main.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/signald/main.py b/signald/main.py
index 61ae1a5..2c07d39 100644
--- a/signald/main.py
+++ b/signald/main.py
@@ -3,7 +3,7 @@ import random
import socket
from typing import Iterator, List # noqa
-from .types import Message
+from .types import Attachment, Message
def readlines(s: socket.socket) -> Iterator[bytes]:
@@ -78,7 +78,26 @@ class Signal:
if message.get("type") != "message":
continue
- yield message
+ message = message["data"]
+
+ yield Message(
+ username=message["username"],
+ source=message["source"],
+ message=message["dataMessage"]["message"],
+ source_device=message["sourceDevice"],
+ timestamp=message["dataMessage"]["timestamp"],
+ timestamp_iso=message["timestampISO"],
+ expiration_secs=message["dataMessage"]["expiresInSeconds"],
+ attachments=[
+ Attachment(
+ content_type=attachment["contentType"],
+ id=attachment["id"],
+ size=attachment["size"],
+ stored_filename=attachment["storedFilename"],
+ )
+ for attachment in message["dataMessage"]["attachments"]
+ ],
+ )
def send_message(self, recipient: str, message: str) -> None:
payload = {"type": "send", "username": self.username, "recipientNumber": recipient, "messageBody": message}