Update to use jsonrpc
This commit is contained in:
parent
46a83d1c23
commit
9b14906462
4 changed files with 20 additions and 19 deletions
|
@ -5,7 +5,7 @@ Provide ways to send notifications to signal-cli through webhooks
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
virtualenv -p python3 --system-site-packages venv
|
virtualenv -p python3 venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
@ -13,6 +13,3 @@ pip install -r requirements.txt
|
||||||
cp signal_webhook/configuration.sample.py signal_webhook/configuration.py
|
cp signal_webhook/configuration.sample.py signal_webhook/configuration.py
|
||||||
$EDITOR signal_webhook/configuration.py
|
$EDITOR signal_webhook/configuration.py
|
||||||
```
|
```
|
||||||
|
|
||||||
**Beware!** Sending messages to Signal requires `gi`, which cannot be installed
|
|
||||||
in a virtualenv; hence the need for `--system-site-packages`.
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
Flask
|
Flask
|
||||||
pydbus
|
|
||||||
|
|
|
@ -3,3 +3,6 @@ RECIPIENTS = {"foo": ["+42..."]} # FIXME
|
||||||
|
|
||||||
# Recipient from the dict above to send to by default
|
# Recipient from the dict above to send to by default
|
||||||
DEFAULT_RECIPIENT = "foo" # FIXME
|
DEFAULT_RECIPIENT = "foo" # FIXME
|
||||||
|
|
||||||
|
# Unix socket location
|
||||||
|
SIGNAL_SOCKET = "/var/signal-cli/socket"
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
import logging
|
import logging
|
||||||
from pydbus import SystemBus
|
from . import configuration
|
||||||
from gi.repository.GLib import GError
|
import socket
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def signal_send(recipients: list[str], message: str) -> None:
|
def signal_send(recipients: list[str], message: str) -> None:
|
||||||
try:
|
payload = {
|
||||||
bus = SystemBus()
|
'jsonrpc': '2.0',
|
||||||
signal_bus = bus.get("org.asamk.Signal")
|
'method': 'send',
|
||||||
for recipient in recipients:
|
'params': {
|
||||||
signal_bus.sendMessage(
|
'message': message,
|
||||||
message,
|
'recipient': recipients,
|
||||||
[],
|
},
|
||||||
recipient,
|
'id': random.randint(0, (1<<24)),
|
||||||
)
|
}
|
||||||
except GError as exn:
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as signal_json:
|
||||||
logger.error("Cannot send Signal notification: %s", exn)
|
signal_json.connect(configuration.SIGNAL_SOCKET)
|
||||||
|
client.send(json.dumps(payload))
|
||||||
|
|
Loading…
Reference in a new issue