Support groups

This commit is contained in:
Théophile Bastian 2024-03-01 15:01:54 +01:00
parent b335b52b7f
commit 38fbf813d2
2 changed files with 15 additions and 11 deletions

View file

@ -1,4 +1,5 @@
# Signal 'address book' # Signal 'address book'. Refer to groups with `G:[base64_encoded_group_id]`, eg.
# `G:UGVyZHUgIQo=`.
RECIPIENTS = {"foo": ["+42..."]} # FIXME RECIPIENTS = {"foo": ["+42..."]} # FIXME
# Recipient from the dict above to send to by default # Recipient from the dict above to send to by default

View file

@ -8,15 +8,18 @@ logger = logging.getLogger(__name__)
def signal_send(recipients: list[str], message: str) -> None: def signal_send(recipients: list[str], message: str) -> None:
def to_dest(recipient: str) -> dict[str, str]:
if recipient.startswith("G:"):
return {"groupId": recipient[2:]}
return {"userId": recipient}
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as signal_json:
signal_json.connect(configuration.SIGNAL_SOCKET)
for recipient in recipients:
payload = { payload = {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"method": "send", "method": "send",
"params": { "params": {"message": message, **to_dest(recipient)},
"message": message,
"recipient": recipients,
},
"id": random.randint(0, (1 << 24)), "id": random.randint(0, (1 << 24)),
} }
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as signal_json:
signal_json.connect(configuration.SIGNAL_SOCKET)
signal_json.send(json.dumps(payload).encode("utf-8")) signal_json.send(json.dumps(payload).encode("utf-8"))