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.
This commit is contained in:
@@ -23,6 +23,8 @@ def buildRecursive(definition, outputs):
|
|||||||
source = definition.recursiveset["source"]
|
source = definition.recursiveset["source"]
|
||||||
|
|
||||||
items = outputs.get(source)
|
items = outputs.get(source)
|
||||||
|
#print(f"RECURSIVE DEBUG DURING {definition.name}")
|
||||||
|
#print(items)
|
||||||
|
|
||||||
if items is None:
|
if items is None:
|
||||||
print(f"No items available in {source} for {definition.name}")
|
print(f"No items available in {source} for {definition.name}")
|
||||||
@@ -38,8 +40,15 @@ def buildRecursive(definition, outputs):
|
|||||||
outputs[definition.recursiveset["outputlabel"]] = item
|
outputs[definition.recursiveset["outputlabel"]] = item
|
||||||
|
|
||||||
for job in recursiveset:
|
for job in recursiveset:
|
||||||
|
#print(f"RECURSIVE DEBUG DURING {job.name}")
|
||||||
|
#print(item)
|
||||||
#outputs, response = buildAction(job, outputs)
|
#outputs, response = buildAction(job, outputs)
|
||||||
outputs, response = executeContract(job, outputs)
|
outputs, response = executeContract(job, outputs)
|
||||||
responses.append(response)
|
responses.append(response)
|
||||||
|
|
||||||
|
retain = definition.recursiveset.get("retain", True)
|
||||||
|
|
||||||
|
if not retain:
|
||||||
|
outputs.pop(source, None)
|
||||||
|
|
||||||
return outputs, responses
|
return outputs, responses
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ def resolveItem(action, item):
|
|||||||
resolved = {}
|
resolved = {}
|
||||||
if hasattr(action, "resolve"):
|
if hasattr(action, "resolve"):
|
||||||
for label, keys in action.resolve["get"].items():
|
for label, keys in action.resolve["get"].items():
|
||||||
|
#print("RESOLVER DEBUG")
|
||||||
|
#print(item)
|
||||||
target = item
|
target = item
|
||||||
try:
|
try:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
@@ -94,12 +96,6 @@ def extractItem(action, item, resolved):
|
|||||||
target = item
|
target = item
|
||||||
try:
|
try:
|
||||||
for key in keys:
|
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]
|
target = target[key]
|
||||||
|
|
||||||
except (KeyError, IndexError) as error:
|
except (KeyError, IndexError) as error:
|
||||||
@@ -108,7 +104,9 @@ def extractItem(action, item, resolved):
|
|||||||
|
|
||||||
print("EXTRACT MODULE TEST")
|
print("EXTRACT MODULE TEST")
|
||||||
print(target)
|
print(target)
|
||||||
resolved[label] = target
|
|
||||||
|
item[label] = target
|
||||||
|
|
||||||
if "construct" in action.extract:
|
if "construct" in action.extract:
|
||||||
for label2, piece in action.extract["construct"].items():
|
for label2, piece in action.extract["construct"].items():
|
||||||
constructed = ""
|
constructed = ""
|
||||||
|
|||||||
@@ -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...",
|
||||||
|
# },
|
||||||
|
#]
|
||||||
@@ -62,7 +62,16 @@ saverow = {
|
|||||||
],
|
],
|
||||||
|
|
||||||
"rowitems": [
|
"rowitems": [
|
||||||
{"resolved": "rmass_message_id"},
|
{"outputs": "rmass_message_id"},
|
||||||
{"resolved": "event_id"},
|
{"resolved": "event_id"},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#filters = [
|
||||||
|
# {
|
||||||
|
# "filterkey": "rmass_sent_status",
|
||||||
|
# "operator": "==",
|
||||||
|
# "filtervalue": "fail",
|
||||||
|
# "print": "Failed to send message to RMASS. Continuing...",
|
||||||
|
# },
|
||||||
|
#]
|
||||||
@@ -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}...",
|
||||||
|
# },
|
||||||
|
#]
|
||||||
@@ -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}...",
|
||||||
|
# },
|
||||||
|
#]
|
||||||
@@ -92,6 +92,12 @@ outputs = {
|
|||||||
"event_id": "event_id"
|
"event_id": "event_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extract = {
|
||||||
|
"get": {
|
||||||
|
"attachment_list": ["messageitem", "attachments"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
saverow = {
|
saverow = {
|
||||||
"table": "message_mapping",
|
"table": "message_mapping",
|
||||||
"columns": [
|
"columns": [
|
||||||
|
|||||||
@@ -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,
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ actions = [
|
|||||||
refresh_tokens,
|
refresh_tokens,
|
||||||
pullmessagelist,
|
pullmessagelist,
|
||||||
getrmassconversations,
|
getrmassconversations,
|
||||||
synapsepushmessages,
|
#synapsepushmessages,
|
||||||
]
|
]
|
||||||
|
|
||||||
#recursiveset = {
|
#recursiveset = {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from plugins.rmass.actions import synapsepushmessages
|
from plugins.rmass.actions import synapsepushmessages
|
||||||
|
from plugins.rmass.operations import synapsepushattachments
|
||||||
|
|
||||||
kind = "recursiveset"
|
kind = "recursiveset"
|
||||||
|
|
||||||
@@ -10,5 +11,6 @@ recursiveset = {
|
|||||||
"outputlabel": "messageitem",
|
"outputlabel": "messageitem",
|
||||||
"actions": [
|
"actions": [
|
||||||
synapsepushmessages,
|
synapsepushmessages,
|
||||||
|
synapsepushattachments,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user