From 0c46d635c0fd4d78ab603aab894ba8e1c75df71c Mon Sep 17 00:00:00 2001 From: Alexey Haidamaka Date: Mon, 1 Jun 2020 11:36:42 +0000 Subject: send_group_message implementation --- signald/main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/signald/main.py b/signald/main.py index d4ece1d..e66fad9 100644 --- a/signald/main.py +++ b/signald/main.py @@ -142,6 +142,18 @@ class Signal: payload = {"type": "send", "username": self.username, "recipientNumber": recipient, "messageBody": text} self._send_command(payload, block) + def send_group_message(self, recipient_group_id: str, text: str, block: bool = False) -> None: + """ + Send a group message. + + recipient_group_id: The base64 encoded group ID to send to. + text: The text of the message 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, "messageBody": text} + self._send_command(payload, block) + def chat_handler(self, regex, order=100): """ A decorator that registers a chat handler function with a regex. @@ -180,7 +192,13 @@ class Signal: else: stop = True - self.send_message(recipient=message.source, text=reply) + # In case a message came from a group chat + group_id = message.group_info.get("groupId") + + if group_id: + self.send_group_message(recipient_group_id=group_id, text=reply) + else: + self.send_message(recipient=message.source, text=reply) if stop: # We don't want to continue matching things. -- cgit v1.2.3-54-g00ecf