diff --git a/base-config.yaml b/base-config.yaml index b7631ed..70026bf 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -2,7 +2,7 @@ # DO NOT CHANGE THIS UNLESS YOU KNOW WHAT YOU ARE DOING command_prefix: report -# Whether or not the bot should pay attention to only specific state/territory designators +# Whether or not the bot should pay attention to only specific reigon designators # This bot will include the designator in the pushed notificaion if this is disabled, # or if the allowed_locations contains multiple strings allowed_locations_enabled: false @@ -10,7 +10,7 @@ allowed_locations: - arizona - california -# Which accounts should be paid attention to on a state/territory-by-state/territory basis. +# Which accounts should be paid attention to on a reigon-by-reigon basis. # If the state/territory is not in allowed_senders, then the bot will allow all senders # Otherwise only listed senders allowed_senders: @@ -21,13 +21,14 @@ allowed_senders: - "@reports:example.com" # Where and how the plugin will send the data to -server_url: "https://ntfy.sh" -server_topic: "changeMe" - -# If the plugin should use a username and password to send notifications -server_use_authentication: false -server_username: "foo" -server_password: "bar" +brair_url: "http://localhost:7000" +# Authentication token +brair_token: "changeMe" +# Which user IDs to send alerts to (these are incremental integers) +brair_sendto: + - 1 + - 2 # If this bot should send a reaction to the message if the notification was successful +# Sends 👍 for successful send to all contacts, and 👎 if some contacts failed send_reaction: true \ No newline at end of file diff --git a/consumerntfy.py b/consumerbriar.py similarity index 69% rename from consumerntfy.py rename to consumerbriar.py index e54a1e5..9e951d7 100644 --- a/consumerntfy.py +++ b/consumerbriar.py @@ -22,7 +22,7 @@ class Config(BaseProxyConfig): helper.copy("server_password") helper.copy("send_reaction") -class ConsumerNTFY(Plugin): +class ConsumerBriar(Plugin): # Get configuration at startup async def start(self) -> None: self.config.load_and_update() @@ -62,24 +62,33 @@ class ConsumerNTFY(Plugin): if not evt.sender in self.config['allowed_senders'].get(st_desig, []): return - # Sending notification to NTFY + # Sending notification to Briar + sent = None # Indicates after the following loop if something has been sent, + # AND that it has been sent to all contacts - url = self.config["server_url"] + "/" + self.config["server_topic"] - body = ' '.join(tokens[1:]) - if len(self.config["allowed_locations"]) != 1: - body = tokens[0] + ": " + body + # Loop through each user + for userId in self.config["brair_sendto"]: + # Reset sent status first time, as we want to detect if + if sent is None: sent = True + + url = self.config["brair_url"] + "/v1/messages/" + str(userId) + + body = ' '.join(tokens[1:]) + if len(self.config["allowed_locations"]) != 1: + body = tokens[0] + ": " + body + body = '{"text":"' + body + '"}' + + headers = {'Authorization': 'Bearer ' + self.config["brair_token"]} + + async with self.http.post(url, data=body, auth=authentication, headers=headers) as response: + if not response.status == 200: + sent = False - # Consider authentication - authentication = None - if self.config["server_use_authentication"]: - authentication = aiohttp.BasicAuth(self.config["server_username"], self.config["server_password"]) - - # Send notification - for trash in range(3): # Try to send 3 times - async with self.http.post(url, data=body, auth=authentication) as response: - if response.status == 200: - await evt.react("👍") - return + if self.config.["send_reaction"]: + if sent is True: + await evt.react("👍") + if sent is False: + await evt.react("👎") diff --git a/maubot.yaml b/maubot.yaml index daf2dfb..68aae6c 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,10 +1,10 @@ maubot: 0.1.0 -id: org.fiftyfiftyonearizona.reports.consumerntfy +id: org.fiftyfiftyonearizona.reports.consumerbriar version: 1.0.0 license: MIT modules: - - consumerntfy -main_class: ConsumerNTFY + - consumerbriar +main_class: ConsumerBriar config: true extra_files: - base-config.yaml \ No newline at end of file diff --git a/readme.md b/readme.md index 4b621b7..0b79c9f 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ -# FiftyFiftyOneArizona's Matrix-Based Reporting System, NTFY Consumer +# FiftyFiftyOneArizona's Matrix-Based Reporting System, Briar Consumer Please see https://git.fiftyfiftyonearizona.org/webmaster/matrix-report-documentation -This plugin supports whitelisting state/territory designators, allowed senders, reaction receipt, and authenticated NTFY posting. \ No newline at end of file +This plugin supports whitelisting state/territory designators, allowed senders, reaction receipt, and multiple recipients through Briar. + +Note that this system requires Briar headless to be running on the system, see https://code.briarproject.org/briar/briar/-/blob/master/briar-headless/README.md \ No newline at end of file