Add the /plain hook
This commit is contained in:
parent
f880feccb3
commit
46a83d1c23
2 changed files with 22 additions and 1 deletions
|
@ -53,3 +53,24 @@ def alertmanager(recipient=None):
|
|||
signal.signal_send(recipient_nums, msg)
|
||||
|
||||
return "OK", 200
|
||||
|
||||
|
||||
@app.route("/plain", methods=["POST"])
|
||||
def plain():
|
||||
"""Send a message through Signal, plain POST args.
|
||||
|
||||
Expects:
|
||||
* message: plaintext message to be sent;
|
||||
* recipient: ID of recipient. If absent, default recipient is used.
|
||||
"""
|
||||
|
||||
if "message" not in request.form:
|
||||
return "Missing message", 400
|
||||
recipient = request.form.get("recipient", configuration.DEFAULT_RECIPIENT)
|
||||
try:
|
||||
recipient_num = configuration.RECIPIENTS[recipient]
|
||||
except KeyError:
|
||||
return "Unauthorized recipient", 400
|
||||
|
||||
signal.signal_send(recipient_num, request.form["message"])
|
||||
return "OK", 200
|
||||
|
|
|
@ -5,7 +5,7 @@ from gi.repository.GLib import GError
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def signal_send(recipients, message):
|
||||
def signal_send(recipients: list[str], message: str) -> None:
|
||||
try:
|
||||
bus = SystemBus()
|
||||
signal_bus = bus.get("org.asamk.Signal")
|
||||
|
|
Loading…
Reference in a new issue