Support groups
This commit is contained in:
parent
b335b52b7f
commit
38fbf813d2
2 changed files with 15 additions and 11 deletions
|
@ -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
|
||||
|
||||
# Recipient from the dict above to send to by default
|
||||
|
|
|
@ -8,15 +8,18 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def signal_send(recipients: list[str], message: str) -> None:
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "send",
|
||||
"params": {
|
||||
"message": message,
|
||||
"recipient": recipients,
|
||||
},
|
||||
"id": random.randint(0, (1 << 24)),
|
||||
}
|
||||
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)
|
||||
signal_json.send(json.dumps(payload).encode("utf-8"))
|
||||
for recipient in recipients:
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "send",
|
||||
"params": {"message": message, **to_dest(recipient)},
|
||||
"id": random.randint(0, (1 << 24)),
|
||||
}
|
||||
signal_json.send(json.dumps(payload).encode("utf-8"))
|
||||
|
|
Loading…
Reference in a new issue