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
|
RECIPIENTS = {"foo": ["+42..."]} # FIXME
|
||||||
|
|
||||||
# Recipient from the dict above to send to by default
|
# 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:
|
def signal_send(recipients: list[str], message: str) -> None:
|
||||||
payload = {
|
def to_dest(recipient: str) -> dict[str, str]:
|
||||||
"jsonrpc": "2.0",
|
if recipient.startswith("G:"):
|
||||||
"method": "send",
|
return {"groupId": recipient[2:]}
|
||||||
"params": {
|
return {"userId": recipient}
|
||||||
"message": message,
|
|
||||||
"recipient": recipients,
|
|
||||||
},
|
|
||||||
"id": random.randint(0, (1 << 24)),
|
|
||||||
}
|
|
||||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as signal_json:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as signal_json:
|
||||||
signal_json.connect(configuration.SIGNAL_SOCKET)
|
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