Separated listener by introducing create listener. Working State. Message loop prevention filters added to server

This commit is contained in:
Lyncoln
2026-10-17 03:42:46 -04:00
parent d260d3681e
commit c7628df30e
14 changed files with 84 additions and 51 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13 -6
View File
@@ -9,15 +9,22 @@ def buildLog (action, outputs, response):
f"{outputs[print_key]}",
)
except: (KeyError, TypeError)
except (KeyError, TypeError):
pass
if action.showstatus is True and response.status_code in [200, 204]:
if action.showstatus is True and response.ok:
print(f"{action.name} successful")
elif action.showstatus is True and response.status_code not in [200, 204]:
elif action.showstatus is True and not response.ok:
print(f"{action.name} failed with status code {response.status_code}")
try:
print(f"Response: {response.json()["error"]}")
except KeyError:
print(f"Response:", response.json())
response_data = response.json()
except ValueError:
response_data = response.text
if isinstance(response_data, dict):
print("Response:", response_data.get("error", response_data))
else:
print("Response:", response_data)
return
+4 -4
View File
@@ -2,7 +2,7 @@ import json
def buildOutput(response, action, outputs):
if hasattr(action, "outputs"):
if response != None:
if response is not None:
try:
response_data = response.json()
except AttributeError:
@@ -20,13 +20,13 @@ def buildOutput(response, action, outputs):
for output_name, response_key in action.outputs.items():
if key == response_key:
outputs[output_name] = value
return outputs
else:
return outputs
print("No response received"),
#return outputs
return outputs
+2 -2
View File
@@ -11,8 +11,8 @@ def recursiveSet(definition, outputs):
for job in recursiveset:
outputs, response = buildAction(job, outputs)
print("MESSAGE BODY DEBUG")
print(resolved["messages"])
#print("MESSAGE BODY DEBUG")
#print(resolved["messages"])
return outputs
from core.execution.action.action import buildAction
Binary file not shown.
+50
View File
@@ -0,0 +1,50 @@
import json
from core.runtime.outputs import buildOutput
from core.execution.operation import buildOperation
def buildListener(listener, self):
if self.path.startswith(listener.acceptpath):
#Prints can used buildlog for listener runtime
print("Matrix transaction received")
content_length = int(self.headers["Content-Length"])
data = self.rfile.read(content_length)
request = json.loads(data)
outputs = {}
outputs = buildOutput(data, listener, outputs)
#if applyConditions(listener, outputs)
# continue
print(outputs)
for event in outputs[listener.recursive["source"]]:
print("DEBUG")
print(listener.recursive["source"])
if "state_key" in event:
continue
if event.get("sender") != "@lyncoln:loxthelion.com":
continue
if "com.loxthelion.rmass_message_id" in event.get("content", {}):
continue
if event.get("type") == "m.room.message":
# Process and forward to RMASS
outputs = buildOperation(listener.execute, outputs)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
else:
self.send_error(404)
return outputs
+2 -33
View File
@@ -9,6 +9,7 @@ from core.runtime.resolver import resolveItem
from plugins.rmass.listeners import synapselistener
from plugins.rmass.operations import rmassmessagepush
from core.execution.operation import buildOperation
from core.server.createlistener import buildListener
port = int(os.environ.get("SERVER_PORT", 19001))
@@ -97,39 +98,7 @@ class RequestHandler(BaseHTTPRequestHandler):
def do_PUT(self):
print("PUT request received")
if self.path.startswith("/_matrix/app/v1/transactions/"):
print("Matrix transaction received")
outputs = {}
content_length = int(self.headers["Content-Length"])
data = self.rfile.read(content_length)
request = json.loads(data)
requestjson = json.dumps(request, indent=4)
#print (request)
#print(requestjson)
for event in request["events"]:
if "state_key" in event:
# Room state event
continue
if event.get("type") == "m.room.message":
# Process the message
print (event)
outputs = buildOutput(data, synapselistener, outputs)
#print (event)
outputs = buildOperation(rmassmessagepush, outputs)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
else:
self.send_error(404)
outputs = buildListener(synapselistener, self)
def startServer():
server = HTTPServer(("0.0.0.0", port), RequestHandler)
+12 -5
View File
@@ -1,12 +1,19 @@
name = "Reception Test"
kind = "action"
showstatus = False
from plugins.rmass.operations import rmassmessagepush
name = "Synapse Listener"
kind = "listener"
outputs = {
"events": "events",
}
acceptpath = "/_matrix/app/v1/transactions/"
execute = rmassmessagepush
recursive = {
"source": "events",
"reverse": False,
"label": "outboundmessage",
}
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
{"access_token": "eyJ0eXAiOiJKV1Q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