diff --git a/base-config.yaml b/base-config.yaml index e8b8b24..19739b9 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -22,13 +22,9 @@ allowed_regions: # Code will push to both __global__ and region-specific endpoint. region_configs: arizona: - # 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 - username: "no" - password: "way" + endpoint: http://localhost:11938 + bearer: YourBearerKey + room_id: YourRoomID # If this bot should send a reaction to the message # Will send 👍 on successful POST to NTFY, and 👎 on failiure. diff --git a/consumerntfy.py b/consumersignal.py similarity index 76% rename from consumerntfy.py rename to consumersignal.py index 5bce54e..b5af55a 100644 --- a/consumerntfy.py +++ b/consumersignal.py @@ -6,6 +6,7 @@ from typing import Type from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper import aiohttp +import subprocess # Ensures a running instance gets an updated config from the Maubot interface class Config(BaseProxyConfig): @@ -15,7 +16,7 @@ class Config(BaseProxyConfig): helper.copy("region_configs") helper.copy("send_reaction") -class ConsumerNTFY(Plugin): +class ConsumerSignal(Plugin): # Get configuration at startup async def start(self) -> None: self.config.load_and_update() @@ -74,38 +75,48 @@ class ConsumerNTFY(Plugin): @command.argument("message", pass_raw=True) async def report(self, evt: MessageEvent, message: str) -> None: # If all have passed - ntfy_posts_passed = None + signal_posts_passed = None # Iterate through each endpoint that the message should be pushed to # (if any) for region_config in self.validate_report(evt, message): - # Detect no regions in reaction - if ntfy_posts_passed is None: ntfy_posts_passed = True + if signal_posts_passed is None: signal_posts_passed = True - self.log.debug(region_config) + url = region_config["endpoint"] + bearer = region_config["bearer"] + group_id = region_config["group_id"] + groups = [group_id] + self.log.debug(url) + self.log.debug(bearer) + self.log.debug(group_id) - # Create notification text split_message = message.split() - text = "[" + split_message[0] + "] " + ' '.join(message.split()[1:]) + body = "[" + split_message[0] + "] " + ' '.join(split_message[1:]) + json = { + "jsonrpc": "2.0", + "method": "send", + "params": { + "groupId": groups, + "message": body + } + } - # Build URL - url = region_config["server_url"] + "/" + region_config["server_topic"] + headers = { + "Authentication": bearer, + "Content-Type": "application/json", + "Accept": "application/json", + } - # Consider authentication - auth = None - if "username" in region_config and "password" in region_config: - auth = aiohttp.BasicAuth(region_config["username"], region_config["password"]) - - # Send notification - async with self.http.post(url, data=text, auth=auth) as response: + async with self.http.get(url, json=json, headers=headers) as response: + self.log.error(response.status) if not response.status == 200: - ntfy_posts_passed = False + signal_posts_passed = False # Send reaction based on successful or failedPOSTs if self.config["send_reaction"]: - if ntfy_posts_passed is True: + if signal_posts_passed is True: await evt.react("👍") - elif ntfy_posts_passed is False: + elif signal_posts_passed is False: await evt.react("👎") # That's all, folks \ No newline at end of file diff --git a/maubot.yaml b/maubot.yaml index d040b22..57afd5d 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,10 +1,10 @@ maubot: 0.1.0 -id: org.fiftyfiftyonearizona.reports.consumerntfy +id: org.fiftyfiftyonearizona.reports.consumersignal version: 1.2.0 license: MIT modules: - - consumerntfy -main_class: ConsumerNTFY + - consumersignal +main_class: ConsumerSignal config: true extra_files: - base-config.yaml \ No newline at end of file diff --git a/readme.md b/readme.md index 5b3d88d..f571bbf 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,14 @@ -# FiftyFiftyOneArizona's Matrix-Based Reporting System, NTFY Consumer +# FiftyFiftyOneArizona's Matrix-Based Reporting System, Signal Consumer Please see https://git.fiftyfiftyonearizona.org/webmaster/matrix-report-documentation +Must be run with https://git.fiftyfiftyonearizona.org/webmaster/signal-cli-http + This plugin supports the following: * whitelisting regions, or allowing all regions. * allowed senders per region, or all regions. -* reaction receipt upon successful POST to NTFY. -* authenticated NTFY POSTing. -* Different NTFY endpoint, topic, and authentication per region. +* reaction receipt upon successful POST to signal-cli-http. +* Different signal-cli-http endpoint, topic, and authentication per region. Please see [base-config.yaml](base-config.yaml) for explanation of behavior. \ No newline at end of file