Merge branch 'master' of github.com:FAUSheppy/signal-http-gateway

This commit is contained in:
2024-02-16 13:58:38 +01:00
2 changed files with 14 additions and 8 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ sqlite.db
instance/ instance/
__pycache__/ __pycache__/
signal_targets.txt signal_targets.txt
sqlite.db

View File

@@ -14,8 +14,7 @@ def signal_send(phone, message):
'''Send message via signal''' '''Send message via signal'''
cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone] cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone]
p = subprocess.run(cmd) p = subprocess.run(cmd)
# TODO check return code # p.check_returncode()
def report_dispatch_error(target, uid, error): def report_dispatch_error(target, uid, error):
'''Report an error for a give dispatch''' '''Report an error for a give dispatch'''
@@ -64,21 +63,27 @@ if __name__ == "__main__":
# track dispatches that were confirmed to avoid duplicate confirmation # # track dispatches that were confirmed to avoid duplicate confirmation #
dispatch_confirmed = [] dispatch_confirmed = []
dispatch_failed = []
# track failed dispatches #
errors = dict()
# iterate over dispatch requests #
for entry in response.json(): for entry in response.json():
print(entry)
user = entry["person"] user = entry["person"]
phone = entry["phone"] phone = entry.get("phone")
if not phone:
print("No phone number! Skipping...", file=sys.stderr)
continue
message = entry["message"] message = entry["message"]
uid_list = entry["uids"] uid_list = entry["uids"]
# send message # # send message #
if entry["method"] == "signal": if entry["method"] == "signal":
uid, error = signal_send(phone, message) try:
signal_send(phone, message)
except subprocess.CalledProcessError as e:
print("Dispatch failed {}".format(e))
continue
else: else:
print("Unsupported dispatch method {}".format(entry["method"]), print("Unsupported dispatch method {}".format(entry["method"]),
sys=sys.stderr) sys=sys.stderr)