From 7b949ec004d03554e7b815a470f88eedf11407da Mon Sep 17 00:00:00 2001 From: Lyncoln Date: Sat, 24 Oct 2026 21:03:03 -0400 Subject: [PATCH] Improved recursive handling by nesting operations in operations under then new buildRecursive. Also changed extract module to attach its findings to outputs for better resolver and recursiveSet targeting. --- core/execution/recursive.py | 9 ++ core/runtime/resolver.py | 12 +- plugins/rmass/actions/getrmassattachments.py | 32 ++++ plugins/rmass/actions/getrmassconversation.py | 13 +- .../rmass/actions/rmassattachmenttosynapse.py | 48 ++++++ .../rmass/actions/synapsepushattachments.py | 150 ++++++++++++++++++ plugins/rmass/actions/synapsepushmessages.py | 6 + .../rmass/operations/getrmassconversations.py | 26 +++ .../rmass/operations/synapsemessagepush.py | 2 +- .../operations/synapsepushattachments.py | 17 ++ .../rmass/operations/synapsepushmessages.py | 4 +- 11 files changed, 308 insertions(+), 11 deletions(-) create mode 100644 plugins/rmass/actions/getrmassattachments.py create mode 100644 plugins/rmass/actions/rmassattachmenttosynapse.py create mode 100644 plugins/rmass/actions/synapsepushattachments.py create mode 100644 plugins/rmass/operations/getrmassconversations.py create mode 100644 plugins/rmass/operations/synapsepushattachments.py diff --git a/core/execution/recursive.py b/core/execution/recursive.py index b0d1e30..0727aea 100644 --- a/core/execution/recursive.py +++ b/core/execution/recursive.py @@ -23,6 +23,8 @@ def buildRecursive(definition, outputs): source = definition.recursiveset["source"] items = outputs.get(source) + #print(f"RECURSIVE DEBUG DURING {definition.name}") + #print(items) if items is None: print(f"No items available in {source} for {definition.name}") @@ -38,8 +40,15 @@ def buildRecursive(definition, outputs): outputs[definition.recursiveset["outputlabel"]] = item for job in recursiveset: + #print(f"RECURSIVE DEBUG DURING {job.name}") + #print(item) #outputs, response = buildAction(job, outputs) outputs, response = executeContract(job, outputs) responses.append(response) + retain = definition.recursiveset.get("retain", True) + + if not retain: + outputs.pop(source, None) + return outputs, responses diff --git a/core/runtime/resolver.py b/core/runtime/resolver.py index 07aba92..f64d56a 100644 --- a/core/runtime/resolver.py +++ b/core/runtime/resolver.py @@ -2,6 +2,8 @@ def resolveItem(action, item): resolved = {} if hasattr(action, "resolve"): for label, keys in action.resolve["get"].items(): + #print("RESOLVER DEBUG") + #print(item) target = item try: for key in keys: @@ -94,12 +96,6 @@ def extractItem(action, item, resolved): target = item try: for key in keys: - #if isinstance(target, dict): - #.get not compatible with resolving through lists - #target = target.get(key) - - #if isinstance(target, list): - #regular key not compatible with resolving potentially unknown values like upload image target = target[key] except (KeyError, IndexError) as error: @@ -108,7 +104,9 @@ def extractItem(action, item, resolved): print("EXTRACT MODULE TEST") print(target) - resolved[label] = target + + item[label] = target + if "construct" in action.extract: for label2, piece in action.extract["construct"].items(): constructed = "" diff --git a/plugins/rmass/actions/getrmassattachments.py b/plugins/rmass/actions/getrmassattachments.py new file mode 100644 index 0000000..646db58 --- /dev/null +++ b/plugins/rmass/actions/getrmassattachments.py @@ -0,0 +1,32 @@ +name = "Get RMASS Message Attachments" + +kind = "action" + +alias = "getrmassattachment" + +showstatus = True + +resolve = { + "get": { + "attachment_path": ["attachment_item", "original"], + } +} + +isrequest = False + +method = "GET" + +path = [ + {"resolved": "attachment_path"}, +] + +image = "message_attachment" + +#filters = [ +# { +# "filterkey": "attachment_list", +# "operator": "is", +# "filtervalue": None, +# "print": "No attachments detected. Continuing...", +# }, +#] \ No newline at end of file diff --git a/plugins/rmass/actions/getrmassconversation.py b/plugins/rmass/actions/getrmassconversation.py index 059f0af..8777ab0 100644 --- a/plugins/rmass/actions/getrmassconversation.py +++ b/plugins/rmass/actions/getrmassconversation.py @@ -62,7 +62,16 @@ saverow = { ], "rowitems": [ - {"resolved": "rmass_message_id"}, + {"outputs": "rmass_message_id"}, {"resolved": "event_id"}, ], -} \ No newline at end of file +} + +#filters = [ +# { +# "filterkey": "rmass_sent_status", +# "operator": "==", +# "filtervalue": "fail", +# "print": "Failed to send message to RMASS. Continuing...", +# }, +#] \ No newline at end of file diff --git a/plugins/rmass/actions/rmassattachmenttosynapse.py b/plugins/rmass/actions/rmassattachmenttosynapse.py new file mode 100644 index 0000000..5d41964 --- /dev/null +++ b/plugins/rmass/actions/rmassattachmenttosynapse.py @@ -0,0 +1,48 @@ +name = "Upload Attachments to Synapse" + +kind = "action" + +alias = "uploadattachment" + +showstatus = True + +#resolve = { +# "get": { + #"sender": ["messageheaders", "userCard", "id"], + #"avatar": ["uploadimage"], + #"username": ["messageheaders", "userCard", "username"], + #"avatar_hash": ["useravatar_hash"], +# }, +#} + +isrequest = True + +method = "POST" + +#To add resolution suffix, second item must be a dictionary. References the "path" library under resolved +path = [ + "https://loxthelion.com/_matrix/media/v3/upload?filename=attachment.jpg", +] + +headers = { + "Authorization": { + "os": "AS_TOKEN", + "prefix": "Bearer ", + }, + "Content-Type": "image/jpeg", +} + +requestdata = "message_attachment" + +outputs = { + "uploadattachment": "content_uri", +} + +#filters = [ +# { +# "filterkey": "message_attachment", +# "operator": "is", +# "filtervalue": None, +# "print": f"No attachments. Skipping {name}...", +# }, +#] diff --git a/plugins/rmass/actions/synapsepushattachments.py b/plugins/rmass/actions/synapsepushattachments.py new file mode 100644 index 0000000..6516fc9 --- /dev/null +++ b/plugins/rmass/actions/synapsepushattachments.py @@ -0,0 +1,150 @@ +from . import synapsenotify + +name = "Synapse Attachment Push" + +kind = "action" + +showstatus = True + +#recursive = { +# "source": "getmessage_select", +# "reverse": True, +# "label": "messageitem", +#} + +resolve = { + "get": { + "sender": ["messageitem", "senderId"], + "attachment_id": ["attachment_item", "id"], + #"message_body": ["messageitem", "text"], + "room_id": ["room_id"], + "timestamp": ["messageitem", "createdAt"], + "attachmenturl": ["uploadattachment"], + }, + "construct": { + "matrixuser": [ + "@rmass_", + {"resolved": "sender"}, + ":loxthelion.com", + ], + }, + "transform": { + "matrixuser": { + "@rmass_238302:loxthelion.com": "@lyncoln:loxthelion.com", + }, + }, +} + +isrequest = True + +keys = [ + { + "keytitle": "msgtype", + "keyvalue": "m.image", + }, + { + "keytitle": "body", + "keyvalue": "attachment.jpg", + }, + { + "keytitle": "url", + "keyvalue": { + "resolved": "attachmenturl", + }, + }, + { + "keytitle": "info", + "keyvalue": { + "mimetype": "image/jpeg", + }, + }, + { + "keytitle": "com.loxthelion.rmass_message_id", + "keyvalue": { + "resolved": "attachment_id", + }, + }, +] + +method = "PUT" + +path = [ + "https://loxthelion.com/_matrix/client/v3/rooms/", + {"resolved": "room_id"}, + "/send/m.room.message/", + {"resolved": "attachment_id"}, + "?user_id=", + {"resolved": "matrixuser"}, + "&ts=", + {"resolved": "timestamp"}, + "000" +] + +headers = { + "Authorization": { + "os": "AS_TOKEN", + "prefix": "Bearer ", + }, + "Content-Type": "application/json", +} + +#outputs = { +# "event_id": "event_id" +#} + +#extract = { +# "get": { +# "attachment_list": ["messageitem", "attachments"], +# }, +#} + +#saverow = { +# "table": "message_mapping", +# "columns": [ +# {"rmass_message_id": "INTEGER PRIMARY KEY"}, +# {"matrix_event_id": "TEXT NOT NULL UNIQUE"}, +# ], +# +# "rowitems": [ +# {"resolved": "attachment_id"}, +# {"outputs": "event_id"}, +# ], +#} + +#readrow = { +# "table": "message_mapping", +# "columns": [ +# {"rmass_message_id": "INTEGER PRIMARY KEY"}, +# {"matrix_event_id": "TEXT NOT NULL UNIQUE"}, +# ], +# "searchcolumn": "rmass_message_id", +# "rowsearchvalue": [ +# {"resolved": "attachment_id"}, +# ], +# "export": { +# 0: "db_message_id", +# } +#} + +#filters = [ +# { +# "filterkey": "attachment_id", +# "operator": "==", +# "filtervalue": {"outputs": "db_message_id"}, +# "print": "Message already forwarded. Continuing...", +# }, +## To be uncommented once getrmassattachments is introduced +# { +# "filterkey": "attachments", +# "operator": "is not", +# "filtervalue": None, +# "print": "Getting message attachments...", +# "execute": "getrmassattachments" +# }, +# { +# "filterkey": "room_id", +# "operator": "is", +# "filtervalue": None, +# "print": f"DM room is unavailable. Skipping {name}...", +# }, +#] \ No newline at end of file diff --git a/plugins/rmass/actions/synapsepushmessages.py b/plugins/rmass/actions/synapsepushmessages.py index 7c6762d..2eae59b 100644 --- a/plugins/rmass/actions/synapsepushmessages.py +++ b/plugins/rmass/actions/synapsepushmessages.py @@ -92,6 +92,12 @@ outputs = { "event_id": "event_id" } +extract = { + "get": { + "attachment_list": ["messageitem", "attachments"], + }, +} + saverow = { "table": "message_mapping", "columns": [ diff --git a/plugins/rmass/operations/getrmassconversations.py b/plugins/rmass/operations/getrmassconversations.py new file mode 100644 index 0000000..d5e0c59 --- /dev/null +++ b/plugins/rmass/operations/getrmassconversations.py @@ -0,0 +1,26 @@ +from plugins.rmass.actions import getmessage, synapseregister, synapseassignusername, getrmassuseravatar, rmassavatartosynapse, synapseassignavatar, synapsecreatespace, synapsegetspaceid, synapsecreatedmroom, synapseassigndmavatar, synapsegetroomid, synapseassignspace#, synapsepushmessages +from plugins.rmass.operations import synapsepushmessages + +name = "Get RMASS Conversations and Synapse Provisioning" + +kind = "recursiveset" + +recursiveset = { + "source": "pullmessages_select", + "outputlabel": "messageheaders", + "actions": [ + synapseregister, + synapseassignusername, + getrmassuseravatar, + rmassavatartosynapse, + synapseassignavatar, + getmessage, + #synapsecreatespace, + #synapsegetspaceid, + synapsecreatedmroom, + synapsegetroomid, + synapseassigndmavatar, + #synapseassignspace, + synapsepushmessages, + ], +} \ No newline at end of file diff --git a/plugins/rmass/operations/synapsemessagepush.py b/plugins/rmass/operations/synapsemessagepush.py index d5ed48c..d923512 100644 --- a/plugins/rmass/operations/synapsemessagepush.py +++ b/plugins/rmass/operations/synapsemessagepush.py @@ -10,7 +10,7 @@ actions = [ refresh_tokens, pullmessagelist, getrmassconversations, - synapsepushmessages, + #synapsepushmessages, ] #recursiveset = { diff --git a/plugins/rmass/operations/synapsepushattachments.py b/plugins/rmass/operations/synapsepushattachments.py new file mode 100644 index 0000000..20b4fd2 --- /dev/null +++ b/plugins/rmass/operations/synapsepushattachments.py @@ -0,0 +1,17 @@ +from plugins.rmass.actions import synapsepushmessages, synapsepushattachments, getrmassattachments, rmassattachmenttosynapse + +kind = "recursiveset" + +name = "Synapse Attachment Push Recursive Set" + +recursiveset = { + "source": "attachment_list", + "reverse": False, + "retain": False, + "outputlabel": "attachment_item", + "actions": [ + getrmassattachments, + rmassattachmenttosynapse, + synapsepushattachments, + ], +} \ No newline at end of file diff --git a/plugins/rmass/operations/synapsepushmessages.py b/plugins/rmass/operations/synapsepushmessages.py index 4c0fd5b..691dcef 100644 --- a/plugins/rmass/operations/synapsepushmessages.py +++ b/plugins/rmass/operations/synapsepushmessages.py @@ -1,4 +1,5 @@ -from plugins.rmass.actions import synapsepushmessages +from plugins.rmass.actions import synapsepushmessages +from plugins.rmass.operations import synapsepushattachments kind = "recursiveset" @@ -10,5 +11,6 @@ recursiveset = { "outputlabel": "messageitem", "actions": [ synapsepushmessages, + synapsepushattachments, ], } \ No newline at end of file