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. # Code will push to both __global__ and region-specific endpoint.
region_configs: region_configs:
arizona: arizona:
# Where and how the plugin will send the data to endpoint: http://localhost:11938
server_url: "https://ntfy.sh" bearer: YourBearerKey
server_topic: "changeme" room_id: YourRoomID
# If the plugin should use a username and password to send notifications
username: "no"
password: "way"
# If this bot should send a reaction to the message # If this bot should send a reaction to the message
# Will send 👍 on successful POST to NTFY, and 👎 on failiure. # 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 from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
import aiohttp import aiohttp
import subprocess
# Ensures a running instance gets an updated config from the Maubot interface # Ensures a running instance gets an updated config from the Maubot interface
class Config(BaseProxyConfig): class Config(BaseProxyConfig):
@ -15,7 +16,7 @@ class Config(BaseProxyConfig):
helper.copy("region_configs") helper.copy("region_configs")
helper.copy("send_reaction") helper.copy("send_reaction")
class ConsumerNTFY(Plugin): class ConsumerSignal(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()
@ -74,38 +75,48 @@ class ConsumerNTFY(Plugin):
@command.argument("message", pass_raw=True) @command.argument("message", pass_raw=True)
async def report(self, evt: MessageEvent, message: str) -> None: async def report(self, evt: MessageEvent, message: str) -> None:
# If all have passed # If all have passed
ntfy_posts_passed = None signal_posts_passed = None
# Iterate through each endpoint that the message should be pushed to # Iterate through each endpoint that the message should be pushed to
# (if any) # (if any)
for region_config in self.validate_report(evt, message): for region_config in self.validate_report(evt, message):
# Detect no regions in reaction if signal_posts_passed is None: signal_posts_passed = True
if ntfy_posts_passed is None: ntfy_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() 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 headers = {
url = region_config["server_url"] + "/" + region_config["server_topic"] "Authentication": bearer,
"Content-Type": "application/json",
"Accept": "application/json",
}
# Consider authentication async with self.http.get(url, json=json, headers=headers) as response:
auth = None self.log.error(response.status)
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:
if not response.status == 200: if not response.status == 200:
ntfy_posts_passed = False signal_posts_passed = False
# Send reaction based on successful or failedPOSTs # Send reaction based on successful or failedPOSTs
if self.config["send_reaction"]: if self.config["send_reaction"]:
if ntfy_posts_passed is True: if signal_posts_passed is True:
await evt.react("👍") await evt.react("👍")
elif ntfy_posts_passed is False: elif signal_posts_passed is False:
await evt.react("👎") await evt.react("👎")
# That's all, folks # That's all, folks

View file

@ -1,10 +1,10 @@
maubot: 0.1.0 maubot: 0.1.0
id: org.fiftyfiftyonearizona.reports.consumerntfy id: org.fiftyfiftyonearizona.reports.consumersignal
version: 1.2.0 version: 1.2.0
license: MIT license: MIT
modules: modules:
- consumerntfy - consumersignal
main_class: ConsumerNTFY main_class: ConsumerSignal
config: true config: true
extra_files: extra_files:
- base-config.yaml - 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 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: This plugin supports the following:
* whitelisting regions, or allowing all regions. * whitelisting regions, or allowing all regions.
* allowed senders per region, or all regions. * allowed senders per region, or all regions.
* reaction receipt upon successful POST to NTFY. * reaction receipt upon successful POST to signal-cli-http.
* authenticated NTFY POSTing. * Different signal-cli-http endpoint, topic, and authentication per region.
* Different NTFY endpoint, topic, and authentication per region.
Please see [base-config.yaml](base-config.yaml) for explanation of behavior. Please see [base-config.yaml](base-config.yaml) for explanation of behavior.