diff --git a/core/runtime/__pycache__/logs.cpython-314.pyc b/core/runtime/__pycache__/logs.cpython-314.pyc index dba84d4..b632788 100644 Binary files a/core/runtime/__pycache__/logs.cpython-314.pyc and b/core/runtime/__pycache__/logs.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/outputs.cpython-314.pyc b/core/runtime/__pycache__/outputs.cpython-314.pyc index 44e2c61..d4124be 100644 Binary files a/core/runtime/__pycache__/outputs.cpython-314.pyc and b/core/runtime/__pycache__/outputs.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/recursive.cpython-314.pyc b/core/runtime/__pycache__/recursive.cpython-314.pyc index 6b4456f..980851d 100644 Binary files a/core/runtime/__pycache__/recursive.cpython-314.pyc and b/core/runtime/__pycache__/recursive.cpython-314.pyc differ diff --git a/core/runtime/logs.py b/core/runtime/logs.py index 5d19255..b234093 100644 --- a/core/runtime/logs.py +++ b/core/runtime/logs.py @@ -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 diff --git a/core/runtime/outputs.py b/core/runtime/outputs.py index 418eea1..3719817 100644 --- a/core/runtime/outputs.py +++ b/core/runtime/outputs.py @@ -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 diff --git a/core/runtime/recursive.py b/core/runtime/recursive.py index e9a8eb1..2a72888 100644 --- a/core/runtime/recursive.py +++ b/core/runtime/recursive.py @@ -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 diff --git a/core/server/__pycache__/createlistener.cpython-314.pyc b/core/server/__pycache__/createlistener.cpython-314.pyc new file mode 100644 index 0000000..4ad6ddc Binary files /dev/null and b/core/server/__pycache__/createlistener.cpython-314.pyc differ diff --git a/core/server/__pycache__/server.cpython-314.pyc b/core/server/__pycache__/server.cpython-314.pyc index 941c636..f84e151 100644 Binary files a/core/server/__pycache__/server.cpython-314.pyc and b/core/server/__pycache__/server.cpython-314.pyc differ diff --git a/core/server/createlistener.py b/core/server/createlistener.py new file mode 100644 index 0000000..d0b119f --- /dev/null +++ b/core/server/createlistener.py @@ -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 \ No newline at end of file diff --git a/core/server/server.py b/core/server/server.py index 8ab5a01..f6b92d3 100644 --- a/core/server/server.py +++ b/core/server/server.py @@ -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) diff --git a/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc b/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc index 386c464..db393d2 100644 Binary files a/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc and b/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc differ diff --git a/plugins/rmass/listeners/synapselistener.py b/plugins/rmass/listeners/synapselistener.py index 61fab4b..f342a75 100644 --- a/plugins/rmass/listeners/synapselistener.py +++ b/plugins/rmass/listeners/synapselistener.py @@ -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", +} diff --git a/savedata/rmmanager.db b/savedata/rmmanager.db index e7aeb4f..c5cc505 100644 Binary files a/savedata/rmmanager.db and b/savedata/rmmanager.db differ diff --git a/savedata/tokens.json b/savedata/tokens.json index dd8fcdf..edbae19 100644 --- a/savedata/tokens.json +++ b/savedata/tokens.json @@ -1 +1 @@ -{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTIyMTE4NzEsIm5iZiI6MTc5MjIxMTY5MSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIxMTc1MX0.yPPrAkT6ZnR9Y3rLhUkWSgL6X_I0UuKznujBg2L-UkI3kGPZbe2G4ADSZBq0DGxiAVnmglwbhXZHs6QuHwIOTQ", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTQ4MDM3NTEsIm5iZiI6MTc5MjIxMTY5MSwianRpIjoia3FxVjB1dEpnRDM4V2MwNnE1b0l2Mkx6SGJGYTVKcjM2aHRtZUQxRk1vVT0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIxMTc1MSwic3ViIjoiMjM4MzAyIn0.4QG6fWWAwzvmox4QmWmcP6bIS6pA7Vi2srsppplI0BDXI2NWbigxfswrTrmb1-QI7PpB9azHDP7Xt_gY_6_pnA"} \ No newline at end of file +{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTIyMjI5MjQsIm5iZiI6MTc5MjIyMjc0NCwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIyMjgwNH0.ZAGwq0DlacX_VBfysDOu6pAlt1FzwccZe1zIlMZcozOs_C7jOiOhkC-o1BH4-UPxe_MniYKux3s5br6kwJHFqQ", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTQ4MTQ4MDQsIm5iZiI6MTc5MjIyMjc0NCwianRpIjoiRmVoVGM1cVFwQUQvRWtjYW1aLy85YllLbVB2ZEhPSXYyUE9YM25aTlhPRT0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIyMjgwNCwic3ViIjoiMjM4MzAyIn0.BOPpuwg88qWk5A0XciE2wi_4mC6V9jvnQzWms0vxIkWctsGMQnhLABzuD8Zjofdf1qK5pQXxf9010SYV5c9r8A"} \ No newline at end of file