aboutsummaryrefslogtreecommitdiffstats
path: root/signald/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'signald/main.py')
-rw-r--r--signald/main.py20
1 files changed, 19 insertions, 1 deletions
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.