From 77363255ef2f69212c0aeb874d82cd15273ddcd4 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Fri, 18 Sep 2020 17:19:12 +0200 Subject: implement (basic) attachment sending --- signald/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/signald/main.py b/signald/main.py index 7373b65..414d82b 100644 --- a/signald/main.py +++ b/signald/main.py @@ -145,6 +145,27 @@ class Signal: payload = {"type": "send", "username": self.username, "recipientAddress": recipient, "messageBody": text} self._send_command(payload, block) + def send_attachment(self, recipient: str, filename: str, block: bool = True) -> None: + """ + Send an attachment. + + recipient: The recipient's phone number, in E.123 format. + filename: The filename of the attachment to send. + block: Whether to block while sending. If you choose not to block, you won't get an exception if there + are any errors. + """ + payload = { + "type": "send", + "username": self.username, + "recipientAddress": recipient, + "attachments": [ + { + "filename": filename + } + ] + } + self._send_command(payload, block) + def send_group_message(self, recipient_group_id: str, text: str, block: bool = False) -> None: """ Send a group message. @@ -162,6 +183,27 @@ class Signal: } self._send_command(payload, block) + def send_group_attachment(self, recipient_group_id: str, filename: str, block: bool = False) -> None: + """ + Send an attachment to a group. + + recipient: The recipient's phone number, in E.123 format. + filename: The filename of the attachment to send. + block: Whether to block while sending. If you choose not to block, you won't get an exception if there + are any errors. + """ + payload = { + "type": "send", + "username": self.username, + "recipientGroupId": recipient_group_id, + "attachments": [ + { + "filename": filename + } + ] + } + self._send_command(payload, block) + def chat_handler(self, regex, order=100): """ A decorator that registers a chat handler function with a regex. -- cgit v1.2.3-54-g00ecf