diff --git a/core/execution/operation/__pycache__/operation.cpython-314.pyc b/core/execution/operation/__pycache__/operation.cpython-314.pyc index 0823dbe..2687027 100644 Binary files a/core/execution/operation/__pycache__/operation.cpython-314.pyc and b/core/execution/operation/__pycache__/operation.cpython-314.pyc differ diff --git a/core/execution/operation/operation.py b/core/execution/operation/operation.py index 69158d9..402d863 100644 --- a/core/execution/operation/operation.py +++ b/core/execution/operation/operation.py @@ -4,10 +4,11 @@ from core.execution.action.action import buildAction from core.runtime.skipstep import skipStep from core.runtime.recursive import recursiveSet -def buildOperation(definition): +outputs = {} +def buildOperation(definition, outputs): actions = definition.actions responses = [] - outputs = {} + #outputs = {} for action in actions: diff --git a/core/runtime/__pycache__/logs.cpython-314.pyc b/core/runtime/__pycache__/logs.cpython-314.pyc index f8ee91a..dba84d4 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 a6cee94..44e2c61 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__/resolver.cpython-314.pyc b/core/runtime/__pycache__/resolver.cpython-314.pyc index 86fb6ef..4cd847b 100644 Binary files a/core/runtime/__pycache__/resolver.cpython-314.pyc and b/core/runtime/__pycache__/resolver.cpython-314.pyc differ diff --git a/core/runtime/__pycache__/savedata.cpython-314.pyc b/core/runtime/__pycache__/savedata.cpython-314.pyc index 67ef52e..92c3dfc 100644 Binary files a/core/runtime/__pycache__/savedata.cpython-314.pyc and b/core/runtime/__pycache__/savedata.cpython-314.pyc differ diff --git a/core/runtime/logs.py b/core/runtime/logs.py index 81e593e..5d19255 100644 --- a/core/runtime/logs.py +++ b/core/runtime/logs.py @@ -11,11 +11,13 @@ def buildLog (action, outputs, response): except: (KeyError, TypeError) - if action.showstatus is True and response.status_code == 200: + if action.showstatus is True and response.status_code in [200, 204]: print(f"{action.name} successful") - elif action.showstatus is True and response.status_code != 200: + elif action.showstatus is True and response.status_code not in [200, 204]: print(f"{action.name} failed with status code {response.status_code}") - print(f"Response: {response.json()["error"]}") - + try: + print(f"Response: {response.json()["error"]}") + except KeyError: + print(f"Response:", response.json()) return diff --git a/core/runtime/outputs.py b/core/runtime/outputs.py index 8409d82..418eea1 100644 --- a/core/runtime/outputs.py +++ b/core/runtime/outputs.py @@ -1,30 +1,32 @@ import json def buildOutput(response, action, outputs): - #if select_data != "not applied": - #response_data = select_data - #else: - #response_data = response.json() if hasattr(action, "outputs"): - try: - response_data = response.json() - except AttributeError: - response_data = json.loads(response) - response_objects = [response_data] + if response != None: + try: + response_data = response.json() + except AttributeError: + response_data = json.loads(response) + response_objects = [response_data] - while response_objects: - response_object = response_objects.pop() + while response_objects: + response_object = response_objects.pop() - for key, value, in response_object.items(): + for key, value, in response_object.items(): - if isinstance(value, dict): - response_objects.append(value) + if isinstance(value, dict): + response_objects.append(value) - for output_name, response_key in action.outputs.items(): - if key == response_key: - outputs[output_name] = value + for output_name, response_key in action.outputs.items(): + if key == response_key: + outputs[output_name] = value + return outputs + + else: + return outputs + - return outputs + #return outputs diff --git a/core/runtime/recursive.py b/core/runtime/recursive.py index e1a2ee9..e9a8eb1 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(outputs["profile"]) - #print(outputs["messages"]) + print("MESSAGE BODY DEBUG") + print(resolved["messages"]) return outputs from core.execution.action.action import buildAction diff --git a/core/runtime/resolver.py b/core/runtime/resolver.py index c4a56d8..cc5201a 100644 --- a/core/runtime/resolver.py +++ b/core/runtime/resolver.py @@ -26,4 +26,15 @@ def resolveItem(action, item): if resolved[source] == key: resolved[source] = value + if "deconstruct" in action.resolve: + for source, mutation in action.resolve["deconstruct"].items(): + deconstructed = str(resolved[source]) + + for item in mutation: + + deconstructed = deconstructed.replace(str(item), "") + print("DECONSTRUCT TESTING") + print(deconstructed) + resolved[source] = deconstructed + print(resolved["sender"]) return resolved diff --git a/core/runtime/savedata.py b/core/runtime/savedata.py index 1906117..52696d8 100644 --- a/core/runtime/savedata.py +++ b/core/runtime/savedata.py @@ -17,8 +17,8 @@ def buildSave(action, outputs): for key, value in save_data.items(): database.execute(""" CREATE TABLE IF NOT EXISTS output_test ( - dictionary TEXT NOT NULL UNIQUE, - value TEXT NOT NULL UNIQUE + dictionary TEXT PRIMARY KEY, + value TEXT NOT NULL ) """) diff --git a/core/server/__pycache__/server.cpython-314.pyc b/core/server/__pycache__/server.cpython-314.pyc index ed91582..941c636 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/server.py b/core/server/server.py index 4329062..8ab5a01 100644 --- a/core/server/server.py +++ b/core/server/server.py @@ -5,7 +5,10 @@ from http.server import HTTPServer, BaseHTTPRequestHandler from .dispatcher import dispatchRequest from .createresponse import buildResponse from core.runtime.outputs import buildOutput +from core.runtime.resolver import resolveItem from plugins.rmass.listeners import synapselistener +from plugins.rmass.operations import rmassmessagepush +from core.execution.operation import buildOperation port = int(os.environ.get("SERVER_PORT", 19001)) @@ -104,13 +107,20 @@ class RequestHandler(BaseHTTPRequestHandler): request = json.loads(data) requestjson = json.dumps(request, indent=4) - print (request) - print(requestjson) - - outputs = buildOutput(data, synapselistener, outputs) - print (outputs) - #resolved = - #outputs = buildOperation(listener, outputs, resolved) + #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") diff --git a/login.py b/login.py index a39d8bd..0dcb070 100644 --- a/login.py +++ b/login.py @@ -1,5 +1,7 @@ from plugins import rmass from core.execution.operation import buildOperation -outputs = buildOperation(rmass.operations.login) +outputs = {} + +outputs = buildOperation(rmass.operations.login, outputs) diff --git a/plugins/rmass/__init__.py b/plugins/rmass/__init__.py index 9516405..905e15f 100644 --- a/plugins/rmass/__init__.py +++ b/plugins/rmass/__init__.py @@ -1 +1 @@ -from . import actions, operations, inbound +from . import actions, operations, listeners diff --git a/plugins/rmass/__pycache__/__init__.cpython-314.pyc b/plugins/rmass/__pycache__/__init__.cpython-314.pyc index e8ecef0..d95e6c4 100644 Binary files a/plugins/rmass/__pycache__/__init__.cpython-314.pyc and b/plugins/rmass/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/rmassmessagepush.cpython-314.pyc b/plugins/rmass/actions/__pycache__/rmassmessagepush.cpython-314.pyc new file mode 100644 index 0000000..cbeb82c Binary files /dev/null and b/plugins/rmass/actions/__pycache__/rmassmessagepush.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/synapsegetroomalias.cpython-314.pyc b/plugins/rmass/actions/__pycache__/synapsegetroomalias.cpython-314.pyc new file mode 100644 index 0000000..a75be1a Binary files /dev/null and b/plugins/rmass/actions/__pycache__/synapsegetroomalias.cpython-314.pyc differ diff --git a/plugins/rmass/actions/__pycache__/synapsepushmessages.cpython-314.pyc b/plugins/rmass/actions/__pycache__/synapsepushmessages.cpython-314.pyc index cffdc72..859f83f 100644 Binary files a/plugins/rmass/actions/__pycache__/synapsepushmessages.cpython-314.pyc and b/plugins/rmass/actions/__pycache__/synapsepushmessages.cpython-314.pyc differ diff --git a/plugins/rmass/actions/rmassmessagepush.py b/plugins/rmass/actions/rmassmessagepush.py new file mode 100644 index 0000000..09a1e75 --- /dev/null +++ b/plugins/rmass/actions/rmassmessagepush.py @@ -0,0 +1,70 @@ +name = "RMASS Message Push" + +kind = "action" + +showstatus = True + +#recursive = { +# "source": "events", +# "reverse": False, +# "label": "outmessageitem", +#} + +#Resolve sources its data from outputs. Ensure keys are in outputs +resolve = { + "get": { + "sender": ["room_name"], + "event_id": ["outmessageitem", "event_id"], + "message_body": ["outmessageitem", "content", "body"], + #"room_id": ["outmessageitem", "room_id"], + "timestamp": ["outmessageitem", "origin_server_ts"], + }, +# "construct": { +# "matrixuser": [ +# "@rmass_", +# {"resolved": "sender"}, +# ":loxthelion.com", +# ], +# }, +# "transform": { +# "matrixuser": { +# "@lyncoln:loxthelion.com": "@rmass_238302:loxthelion.com", +# }, +# }, + "deconstruct": { + "sender" : [ + "#rmass_dm_", + ":loxthelion.com", + ], + }, +} + +keys = [ + { + "keytitle": "message", + "keyvalue": { + "resolved": "message_body", + }, + }, + { + "keytitle": "profileId", + "keyvalue": { + "resolved": "sender", + }, + }, +] + +method = "POST" + +path = [ + "https://rentmasseur.com/api/v1/mailbox", +] + +headers = { + "Authorization": { + "output": "access_token", + "prefix": "Bearer ", + }, +} + + diff --git a/plugins/rmass/actions/synapsegetroomalias.py b/plugins/rmass/actions/synapsegetroomalias.py new file mode 100644 index 0000000..4959651 --- /dev/null +++ b/plugins/rmass/actions/synapsegetroomalias.py @@ -0,0 +1,54 @@ +name = "Get Synapse Room Alias" + +kind = "action" + +showstatus = True + +#recursive = { +# "source": "getmessage", +# "reverse": True, +# "label": "messageitem", +#} + +resolve = { + "get": { + #"sender": ["messageitem", "senderId"], + #"event_id": ["messageitem", "id"], + #"message_body": ["events", 0, "content", "body"], + "room_id": ["outmessageitem", "room_id"], + #"timestamp": ["events", 0, "original_server_ts"], + }, +# "construct": { +# "matrixuser": [ +# "@rmass_", +# {"resolved": "sender"}, +# ":loxthelion.com", +# ], +# }, +# "transform": { +# "matrixuser": { +# "@lyncoln:loxthelion.com": "@rmass_238302:loxthelion.com", +# }, +# }, +} + + +method = "GET" + +path = [ + "https://loxthelion.com/_matrix/client/v3/rooms/", + {"resolved": "room_id"}, + "/state/m.room.canonical_alias", +] + +headers = { + "Authorization": { + "os": "ADMIN_TOKEN", + "prefix": "Bearer ", + }, + "Content-Type": "application/json", +} + +outputs = { + "room_name": "alias" +} diff --git a/plugins/rmass/actions/synapsepushmessages.py b/plugins/rmass/actions/synapsepushmessages.py index f2392f0..1d5867b 100644 --- a/plugins/rmass/actions/synapsepushmessages.py +++ b/plugins/rmass/actions/synapsepushmessages.py @@ -1,4 +1,4 @@ -import os +#import os name = "Synapse Message Push" diff --git a/plugins/rmass/listeners/__init__.py b/plugins/rmass/listeners/__init__.py index b418dc1..7d22e37 100644 --- a/plugins/rmass/listeners/__init__.py +++ b/plugins/rmass/listeners/__init__.py @@ -1 +1 @@ -from . import receive +from . import synapselistener diff --git a/plugins/rmass/listeners/__pycache__/__init__.cpython-314.pyc b/plugins/rmass/listeners/__pycache__/__init__.cpython-314.pyc index 24ea4a8..590664c 100644 Binary files a/plugins/rmass/listeners/__pycache__/__init__.cpython-314.pyc and b/plugins/rmass/listeners/__pycache__/__init__.cpython-314.pyc differ diff --git a/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc b/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc new file mode 100644 index 0000000..386c464 Binary files /dev/null and b/plugins/rmass/listeners/__pycache__/synapselistener.cpython-314.pyc differ diff --git a/plugins/rmass/operations/__pycache__/rmassmessagepush.cpython-314.pyc b/plugins/rmass/operations/__pycache__/rmassmessagepush.cpython-314.pyc new file mode 100644 index 0000000..0a88fc0 Binary files /dev/null and b/plugins/rmass/operations/__pycache__/rmassmessagepush.cpython-314.pyc differ diff --git a/plugins/rmass/operations/rmassmessagepush.py b/plugins/rmass/operations/rmassmessagepush.py new file mode 100644 index 0000000..9752f8f --- /dev/null +++ b/plugins/rmass/operations/rmassmessagepush.py @@ -0,0 +1,17 @@ +from plugins.rmass.actions import rmassmessagepush, synapsegetroomalias, refresh_tokens + +name = "RMASS Message Push" + +kind = "operation" + +actions = [ + #Recursiveset is used to reference a nested operation inside an operation whose actions are listed in the recursiveset action list + "recursiveset", +] + +recursiveset = { + "source": "events", + "outputlabel": "outmessageitem", + "actions": [synapsegetroomalias, refresh_tokens, rmassmessagepush], +} + diff --git a/savedata/rmmanager.db b/savedata/rmmanager.db index 94e431d..e7aeb4f 100644 Binary files a/savedata/rmmanager.db and b/savedata/rmmanager.db differ diff --git a/savedata/tokens.json b/savedata/tokens.json index 71096e7..dd8fcdf 100644 --- a/savedata/tokens.json +++ b/savedata/tokens.json @@ -1 +1 @@ -{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTIwNDA4ODgsIm5iZiI6MTc5MjA0MDcwOCwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjA0MDc2OH0.8twTKQb2OG-OfT_C2eAwD2OpV__X7S-MWnpVXdLeLvBzfZcW6ZJLesvSqgYXeO56yn-_UblIUEwfy_B8EuDTSw", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTQ2MzI3NjgsIm5iZiI6MTc5MjA0MDcwOCwianRpIjoiUXRjRXE2TWtGdWhHNjdiTHdLak1kdzJXazIzMlFtVkp4K2J3aGs2RTlCZz0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjA0MDc2OCwic3ViIjoiMjM4MzAyIn0.zmQ9S08NHgr2q0g3VloTgY3xBjATxXk2mdg6MbeHjuQ47OZ24E8bBNyRaqDJYJ0OnCkF5CvepJ5ISlnvkqTPRA"} \ No newline at end of file +{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTIyMTE4NzEsIm5iZiI6MTc5MjIxMTY5MSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIxMTc1MX0.yPPrAkT6ZnR9Y3rLhUkWSgL6X_I0UuKznujBg2L-UkI3kGPZbe2G4ADSZBq0DGxiAVnmglwbhXZHs6QuHwIOTQ", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTQ4MDM3NTEsIm5iZiI6MTc5MjIxMTY5MSwianRpIjoia3FxVjB1dEpnRDM4V2MwNnE1b0l2Mkx6SGJGYTVKcjM2aHRtZUQxRk1vVT0iLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MjIxMTc1MSwic3ViIjoiMjM4MzAyIn0.4QG6fWWAwzvmox4QmWmcP6bIS6pA7Vi2srsppplI0BDXI2NWbigxfswrTrmb1-QI7PpB9azHDP7Xt_gY_6_pnA"} \ No newline at end of file diff --git a/synapsemessagepush.py b/synapsemessagepush.py index 7849309..a7528b3 100644 --- a/synapsemessagepush.py +++ b/synapsemessagepush.py @@ -2,6 +2,6 @@ from plugins import rmass from core.execution.operation import buildOperation - -outputs = buildOperation(rmass.operations.synapsemessagepush) +outputs = {} +outputs = buildOperation(rmass.operations.synapsemessagepush, outputs)