diff options
author | Stavros Korokithakis <hi@stavros.io> | 2020-06-01 11:36:42 +0000 |
---|---|---|
committer | Stavros Korokithakis <hi@stavros.io> | 2020-06-01 11:36:42 +0000 |
commit | 7190fd50c24a95cc00d42b940859226e4bf744fc (patch) | |
tree | 13e5f62ef981cf72b5b789dc9735cd6182db4d95 | |
parent | 36d96687fa0eaea53371fb8293892395ace6ab14 (diff) | |
parent | 0c46d635c0fd4d78ab603aab894ba8e1c75df71c (diff) | |
download | pysignald-7190fd50c24a95cc00d42b940859226e4bf744fc.tar.gz pysignald-7190fd50c24a95cc00d42b940859226e4bf744fc.zip |
Merge branch 'feature/send_group_message' into 'master'
send_group_message implementation
See merge request stavros/pysignald!3
-rw-r--r-- | signald/main.py | 20 |
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. |