Signal Consumer

This commit is contained in:
Ben 2025-07-29 00:02:07 -07:00
parent beefb8c73e
commit b45f4f8bb7
Signed by: webmaster
GPG key ID: A5FCBAF34E6E8B50
4 changed files with 41 additions and 33 deletions

View file

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

View file

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

View file

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

View file

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