signal backend, app cleanup
This commit is contained in:
parent
4b157ed1d1
commit
6f18890739
43 changed files with 695 additions and 124 deletions
54
app/signalbot/rpc.py
Normal file
54
app/signalbot/rpc.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import json
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
rpc_id = 1
|
||||
|
||||
|
||||
def api(method, params):
|
||||
global rpc_id
|
||||
rpc_id += 1
|
||||
url = "http://127.0.0.1:8080/api/v1/rpc"
|
||||
msg = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": str(rpc_id),
|
||||
"method": method,
|
||||
}
|
||||
if params:
|
||||
msg["params"] = params
|
||||
if settings.DEBUG:
|
||||
print("POST signal rpc:", msg)
|
||||
response = requests.post(url, json=msg).json()
|
||||
if "result" in response:
|
||||
return response["result"]
|
||||
else:
|
||||
raise Exception("Error: %s", response)
|
||||
|
||||
|
||||
def send(msg, to=None, group=None):
|
||||
params = {
|
||||
"message": msg
|
||||
}
|
||||
if group:
|
||||
params["groupId"] = group
|
||||
else:
|
||||
params["recipient"] = to
|
||||
return api("send", params)
|
||||
|
||||
|
||||
def send_reaction(target_address, target_ts, emoji, to=None, group=None, remove=False):
|
||||
params = {
|
||||
"emoji": emoji,
|
||||
"targetTimestamp": target_ts,
|
||||
"targetAuthor": target_address,
|
||||
}
|
||||
if group:
|
||||
params["groupId"] = group
|
||||
else:
|
||||
params["recipient"] = to
|
||||
|
||||
return api("sendReaction", params)
|
||||
Loading…
Add table
Add a link
Reference in a new issue