Briar consumer

This commit is contained in:
Ben 2025-06-19 15:42:03 -07:00
parent 11152ae8de
commit 99871321c2
4 changed files with 43 additions and 31 deletions

View file

@ -2,7 +2,7 @@
# DO NOT CHANGE THIS UNLESS YOU KNOW WHAT YOU ARE DOING # DO NOT CHANGE THIS UNLESS YOU KNOW WHAT YOU ARE DOING
command_prefix: report 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, # This bot will include the designator in the pushed notificaion if this is disabled,
# or if the allowed_locations contains multiple strings # or if the allowed_locations contains multiple strings
allowed_locations_enabled: false allowed_locations_enabled: false
@ -10,7 +10,7 @@ allowed_locations:
- arizona - arizona
- california - 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 # If the state/territory is not in allowed_senders, then the bot will allow all senders
# Otherwise only listed senders # Otherwise only listed senders
allowed_senders: allowed_senders:
@ -21,13 +21,14 @@ allowed_senders:
- "@reports:example.com" - "@reports:example.com"
# Where and how the plugin will send the data to # Where and how the plugin will send the data to
server_url: "https://ntfy.sh" brair_url: "http://localhost:7000"
server_topic: "changeMe" # Authentication token
brair_token: "changeMe"
# If the plugin should use a username and password to send notifications # Which user IDs to send alerts to (these are incremental integers)
server_use_authentication: false brair_sendto:
server_username: "foo" - 1
server_password: "bar" - 2
# If this bot should send a reaction to the message if the notification was successful # 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 send_reaction: true

View file

@ -22,7 +22,7 @@ class Config(BaseProxyConfig):
helper.copy("server_password") helper.copy("server_password")
helper.copy("send_reaction") helper.copy("send_reaction")
class ConsumerNTFY(Plugin): class ConsumerBriar(Plugin):
# Get configuration at startup # Get configuration at startup
async def start(self) -> None: async def start(self) -> None:
self.config.load_and_update() self.config.load_and_update()
@ -62,24 +62,33 @@ class ConsumerNTFY(Plugin):
if not evt.sender in self.config['allowed_senders'].get(st_desig, []): if not evt.sender in self.config['allowed_senders'].get(st_desig, []):
return 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"] # Loop through each user
body = ' '.join(tokens[1:]) for userId in self.config["brair_sendto"]:
if len(self.config["allowed_locations"]) != 1: # Reset sent status first time, as we want to detect if
body = tokens[0] + ": " + body 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 if self.config.["send_reaction"]:
authentication = None if sent is True:
if self.config["server_use_authentication"]: await evt.react("👍")
authentication = aiohttp.BasicAuth(self.config["server_username"], self.config["server_password"]) if sent is False:
await evt.react("👎")
# 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

View file

@ -1,10 +1,10 @@
maubot: 0.1.0 maubot: 0.1.0
id: org.fiftyfiftyonearizona.reports.consumerntfy id: org.fiftyfiftyonearizona.reports.consumerbriar
version: 1.0.0 version: 1.0.0
license: MIT license: MIT
modules: modules:
- consumerntfy - consumerbriar
main_class: ConsumerNTFY main_class: ConsumerBriar
config: true config: true
extra_files: extra_files:
- base-config.yaml - base-config.yaml

View file

@ -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 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. 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