Matrix bridge working and effectively pushing messages

This commit is contained in:
Lyncoln
2026-10-14 15:37:12 -04:00
parent e776eddb37
commit 56ae0ace33
45 changed files with 334 additions and 252 deletions
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3 -1
View File
@@ -22,5 +22,7 @@ def executeRequest(action, outputs, resolved):
# session.cookies.set( # session.cookies.set(
# sessioncookies[cookie_name] = response[cookie_key], # sessioncookies[cookie_name] = response[cookie_key],
print(request)
#print(response.status_code)
#print(response.text)
return response, outputs return response, outputs
+8 -1
View File
@@ -1,9 +1,16 @@
def buildKey(key, outputs, resolved): def buildKey(key, outputs, resolved):
value = key["keyvalue"] value = key["keyvalue"]
if isinstance(value, dict) and "output" in value: if isinstance(value, dict):
if "output" in value:
value = outputs[value["output"]] value = outputs[value["output"]]
elif "resolved" in value:
value = resolved[value["resolved"]]
if "prefix" in key["keyvalue"]:
value = key["keyvalue"]["prefix"] + str(value)
return { return {
key["keytitle"]: value, key["keytitle"]: value,
} }
+26 -2
View File
@@ -1,4 +1,22 @@
def buildPath(path, outputs, resolved): def buildPath(path, outputs, resolved):
result = ""
for part in path:
if isinstance(part, dict):
if "resolved" in part:
value = resolved[part["resolved"]]
elif "output" in part:
value = outputs[part["output"]]
else:
raise ValueError(f"Unsupported path component: {part}")
result += str(value)
else:
result += str(part)
return result
def buildPath3(path, outputs, resolved):
if isinstance(path, str): if isinstance(path, str):
return path return path
@@ -6,18 +24,24 @@ def buildPath(path, outputs, resolved):
for part in path: for part in path:
if isinstance(part, dict): if isinstance(part, dict):
if "resolved" in part:
#for key, val in part.items(): #for key, val in part.items():
#value = outputs[part["output"]][part["keys"]] #value = outputs[part["output"]][part["keys"]]
value = resolved["path"] value = resolved[part["resolved"]]
#print("DEBUG path", value) #print("DEBUG path", value)
#for key in part.get("keys", []): #for key in part.get("keys", []):
#value = value[key] #value = value[key]
if "suffix" in part:
suffix = part["suffix"]
if value != None:
result += str(value) result += str(value)
if suffix != None:
result += str(suffix)
else: else:
result += part result += part
#print(result) print(result)
return result return result
def buildPath2(path, outputs, resolved): def buildPath2(path, outputs, resolved):
+4
View File
@@ -1,5 +1,6 @@
from .object import buildObject from .object import buildObject
from .path import buildPath from .path import buildPath
import os
def buildRequest(definition, outputs, resolved): def buildRequest(definition, outputs, resolved):
path = buildPath(definition.path, outputs, resolved) path = buildPath(definition.path, outputs, resolved)
@@ -20,6 +21,9 @@ def buildRequest(definition, outputs, resolved):
if isinstance(value, dict) and "output" in header_value: if isinstance(value, dict) and "output" in header_value:
value = outputs[value["output"]] value = outputs[value["output"]]
if isinstance(value, dict) and "os" in header_value:
#value = os.environ[definition.headers[header_name]["os"]]
value = os.environ["AS_TOKEN"]
if isinstance(header_value, dict) and "prefix" in header_value: if isinstance(header_value, dict) and "prefix" in header_value:
value = header_value["prefix"] + value value = header_value["prefix"] + value
+1 -1
View File
@@ -23,5 +23,5 @@ def buildOperation(definition):
#except Exception as error: #except Exception as error:
#outputs = manageFailure(error, action, outputs) #outputs = manageFailure(error, action, outputs)
#print(outputs)
return outputs return outputs
-20
View File
@@ -1,20 +0,0 @@
def skipStep(definition, action, outputs):
try:
if action in definition.skipstep:
condition = definition.skipstep[action]
#if outputs.get([condition["output"]]) is None:
#return False
#current_value = 1
#else:
current_value = outputs[condition["output"]]
#current_value = 1
if condition["operator"] == ">=":
if current_value >= condition["value"]:
print(f"Skipping {action.name}")
return True
except KeyError:
#outputs = manageFailure(error)
return False
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -1
View File
@@ -15,6 +15,7 @@ def buildLog (action, outputs, response):
print(f"{action.name} successful") print(f"{action.name} successful")
elif action.showstatus is True and response.status_code != 200: elif action.showstatus is True and response.status_code != 200:
print(f"{action.name} failed") print(f"{action.name} failed with status code {response.status_code}")
print(f"Response: {response.json()["error"]}")
return return
+1 -1
View File
@@ -1,4 +1,4 @@
def buildOutput(response, action, outputs):#, select_data): def buildOutput(response, action, outputs):
#if select_data != "not applied": #if select_data != "not applied":
#response_data = select_data #response_data = select_data
#else: #else:
-18
View File
@@ -8,26 +8,8 @@ def recursiveAction(definition, outputs):
for job in recursiveset: for job in recursiveset:
outputs, response = buildAction(job, outputs) outputs, response = buildAction(job, outputs)
#outputs[action.recursive["target"]] = item
print(outputs["profile"]) print(outputs["profile"])
print(outputs["messages"]) print(outputs["messages"])
return outputs return outputs
def recursiveActionStale(action, outputs):
#if hasattr(action, "recursive"):
#outputs[action.recursive["target"]] = {}
for item in outputs[action.recursive["source"]]:
#resolved = resolveItem(action, item)#, outputs)#, resolved)
#print("DEBUG Resolved value:", resolved)
#outputs[action.recursive["target"]] = outputs[action.recursive["source"]][][action.recursive["target"]]
#print(outputs[action.recursive["target"]])
#Target may be phased out here. its not quite necessary after resolve
outputs[action.recursive["target"]] = item
#print(outputs[action.recursive["target"]])
#target = outputs[action.recursive["source"]["target"]
outputs, response = buildAction(action, outputs)#, resolved)
#print(outputs)
return outputs
+1 -65
View File
@@ -1,75 +1,11 @@
def resolveItem(action, item): def resolveItem(action, item):
resolved = {} resolved = {}
if hasattr(action, "resolve"): if hasattr(action, "resolve"):
#label = action.resolve["label"]
#targetkeys = action.resolve["targetkeys"]
#print(item)
#target = item
#for key in targetkeys:
# target = target[key]
#resolved[label] = target
for label, keys in action.resolve.items(): for label, keys in action.resolve.items():
target = item target = item
#print(item)
#print(target)
for key in keys: for key in keys:
target = target[key] target = target[key]
resolved[label] = target resolved[label] = target
#print(resolved[label])
return resolved
def resolveItem2(action, item, outputs):
#resolved = {}
label = action.resolve["label"]
targetkeys = action.resolve["targetkeys"]
#print(item)
target = item
for key in targetkeys:
target = target[key]
#resolved[label] = target
#for label, keys in action.resolve.items():
#target = item
#print(target)
#for key in keys:
#target = target[key]
#resolved[label] = target
#print(resolved[label])
outputs[label] = target
#print("Resolver DEBUG", target, outputs[label])
return outputs
def resolveItemBackup(action, item):
resolved = {}
if hasattr(action, "resolve"):
#label = action.resolve["label"]
#targetkeys = action.resolve["targetkeys"]
#print(item)
#target = item
#for key in targetkeys:
# target = target[key]
#resolved[label] = target
for label, keys in action.resolve.items():
target = item
#print(item)
#print(target)
for key in keys:
target = target[key]
resolved[label] = target
print(resolved[label])
return resolved return resolved
+2 -2
View File
@@ -28,7 +28,7 @@ def buildSelect(action, outputs):
#print(select_data) #print(select_data)
return select_data, action, outputs return select_data, action, outputs
except (KeyError, TypeError): except: (KeyError, TypeError)
select_data = ["no selection"] #select_data = ["no selection"]
return select_data, action, outputs return select_data, action, outputs
+2 -6
View File
@@ -1,6 +1,3 @@
import os
name = "Get messages" name = "Get messages"
kind = "action" kind = "action"
@@ -9,11 +6,12 @@ showstatus = True
method = "GET" method = "GET"
#Used to resolve path for recursive handling. Path location must match the location of the recursiveset data from pullmessage operation
resolve = { resolve = {
"path": ["messageheaders", "id"], "path": ["messageheaders", "id"],
#"label": "path",
} }
#To add resolution suffix, second item must be a dictionary. References the "path" library under resolved
path = [ path = [
"https://rentmasseur.com/api/v1/mailbox/", "https://rentmasseur.com/api/v1/mailbox/",
{"resolved": "path"}, {"resolved": "path"},
@@ -24,8 +22,6 @@ path = [
#} #}
] ]
#path = os.path.join(baseurl.messageid)
headers = { headers = {
"Authorization": { "Authorization": {
"output": "access_token", "output": "access_token",
-41
View File
@@ -2,43 +2,12 @@ name = "Get message list"
kind = "action" kind = "action"
id = "getmessagelist"
showstatus = True showstatus = True
#skipstep = {
# "checkavailable": "validTo >= 3600"
#}
#availabletime = int(os.environ.get("AVAILABLE_DURATION",3))
#duration = availabletime - 1
#keys = [
# {
# "keytitle": "option",
# "keyvalue": 1,
# },
# {
# "keytitle": "duration",
# "keyvalue": duration,
# },
#]
method = "GET" method = "GET"
#path = "https://rentmasseur.com/api/v1/mailbox?page=1&folder=1&sort=1"
path = "https://rentmasseur.com/api/v1/mailbox" path = "https://rentmasseur.com/api/v1/mailbox"
#path = [
# "https://rentmasseur.com/api/v1/mailbox/",
# {
# "output": "emails",
# "keys": [0, "id"]
# }
#]
headers = { headers = {
"Authorization": { "Authorization": {
"output": "access_token", "output": "access_token",
@@ -46,13 +15,6 @@ headers = {
}, },
} }
#select = {
# "source": "emails",
# "selectmethod": "exclude",
# "key": "unread",
# "value": 0,
#}
select = { select = {
"source": "emails", "source": "emails",
"include": { "include": {
@@ -69,6 +31,3 @@ outputs = {
"emails": "emails" "emails": "emails"
} }
#prints = {
# "messageid": "id"
#}
@@ -0,0 +1,55 @@
import os
name = "Synapse Assign Username"
kind = "action"
showstatus = True
astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["messages", 0, "senderId"],
#"messageid": ["message", "id"],
"username": ["profile", "username"],
#"location": ["profile", "location"],
}
keys = [
#{
# "keytitle": "type",
# "keyvalue": "m.login.application_service",
#},
{
"keytitle": "displayname",
"keyvalue": {
"resolved": "username",
},
},
]
method = "PUT"
#path = [
# "https://loxthelion.com/_matrix/client/v3/profile/rmass_",
# {"resolved": "sender"},
# {"suffix": "/displayname"},
#]
path = [
"https://loxthelion.com/_matrix/client/v3/profile/@rmass_",
{"resolved": "sender"},
":loxthelion.com/displayname?user_id=@rmass_",
{"resolved": "sender"},
":loxthelion.com"
]
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
#outputs = {
# "user_id": "user_id",
#}
@@ -0,0 +1,76 @@
import os
name = "Synapse Create DM Room"
kind = "action"
showstatus = True
astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["messages", 0, "senderId"],
#"messageid": ["message", "id"],
"username": ["profile", "username"],
#"location": ["profile", "location"],
}
keys = [
{
"keytitle": "name",
"keyvalue": {
"resolved": "username",
},
},
{
"keytitle": "room_alias_name",
"keyvalue": {
"resolved": "sender",
"prefix": "rmass_dmtest_",
},
},
{
"keytitle": "visibility",
"keyvalue": "private",
},
{
"keytitle": "preset",
"keyvalue": "private_chat",
},
{
"keytitle": "is_direct",
"keyvalue": True,
},
{
"keytitle": "invite",
"keyvalue": ["@lyncoln:loxthelion.com"],
},
#{
#"keytitle": "power_level_content_override",
#"keyvalue": {
#"users": {
#"@lyncoln:loxthelion.com": 100,
#"@rmass_:loxthelion.com": 100,
#},
#},
#}
]
method = "POST"
path = [
"https://loxthelion.com/_matrix/client/v3/createRoom?user_id=@rmass_",
{"resolved": "sender"},
":loxthelion.com",
]
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
outputs = {
"room_id": "room_id",
}
+38
View File
@@ -0,0 +1,38 @@
import os
name = "Synapse Get Room ID"
kind = "action"
showstatus = True
#astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["messages", 0, "senderId"],
#"message_id": ["messages", 0, "id"],
#"username": ["profile", "username"],
#"message_body": ["messages", 0, "text"],
#"room_id": ["room_id"],
#"location": ["profile", "location"],
}
method = "GET"
path = [
"https://loxthelion.com/_matrix/client/v3/directory/room/%23rmass_dmtest_",
{"resolved": "sender"},
"%3Aloxthelion.com",
]
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
outputs = {
"room_id": "room_id",
}
-52
View File
@@ -1,52 +0,0 @@
import os
name = "Synapse Message Push"
kind = "action"
showstatus = True
astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["message", "senderId"],
#"messageid": ["message", "id"],
"username": ["profile", "username"],
"location": ["profile", "location"],
}
keys = [
{
"keytitle": "type",
"keyvalue": ,
},
{
"keytitle": "username",
"keyvalue": {outputs: senderId},
},
{
"keytitle": "csrf",
"keyvalue": {
"outputs": "csrf_token",
},
},
{
"keytitle": "remember",
"keyvalue": 1,
},
]
method = "POST"
path = "https://rentmasseur.com/api/v1/login"
outputs = {
"access_token": "accessToken",
"refresh_token": "refreshToken",
}
savedata = [
"access_token",
"refresh_token",
]
savepath = os.environ["TOKEN_STORE"]
@@ -0,0 +1,54 @@
import os
name = "Synapse Message Push"
kind = "action"
showstatus = True
#astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["messages", 0, "senderId"],
"message_id": ["messages", 0, "id"],
#"username": ["profile", "username"],
"message_body": ["messages", 0, "text"],
"room_id": ["room_id"],
#"location": ["profile", "location"],
}
keys = [
{
"keytitle": "msgtype",
"keyvalue": "m.text",
},
{
"keytitle": "body",
"keyvalue": {
"resolved": "message_body",
},
},
]
method = "PUT"
path = [
"https://loxthelion.com/_matrix/client/v3/rooms/",
{"resolved": "room_id"},
"/send/m.room.message/",
{"resolved": "message_id"},
"?user_id=@rmass_",
{"resolved": "sender"},
":loxthelion.com",
]
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
#outputs = {
# "room_id": "room_id",
#}
+49
View File
@@ -0,0 +1,49 @@
import os
name = "Synapse User Registration"
kind = "action"
showstatus = True
astoken = os.environ["AS_TOKEN"]
resolve = {
"sender": ["messages", 0, "senderId"],
#"messageid": ["message", "id"],
"username": ["profile", "username"],
#"location": ["profile", "location"],
}
keys = [
{
"keytitle": "type",
"keyvalue": "m.login.application_service",
},
{
"keytitle": "username",
"keyvalue": {
"resolved": "sender",
"prefix": "rmass_"
},
},
{
"keytitle": "inhibitlogin",
"keyvalue": True,
},
]
method = "POST"
path = "https://loxthelion.com/_matrix/client/v3/register"
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
outputs = {
"user_id": "user_id",
}
+3 -3
View File
@@ -1,4 +1,4 @@
from plugins.rmass.actions import pullmessagelist, refresh_tokens, getmessage, checkavailable from plugins.rmass.actions import pullmessagelist, refresh_tokens, getmessage, checkavailable, synapseregister, synapseassignusername, synapsecreatedmroom, synapsegetroomid, synapsepushmessages
name = "Get Message List" name = "Get Message List"
@@ -7,13 +7,13 @@ kind = "operation"
actions = [ actions = [
refresh_tokens, refresh_tokens,
pullmessagelist, pullmessagelist,
#Recursiveset is used to reference a nested operation inside an operation whose actions are listed in the recursiveset action list
"recursiveset", "recursiveset",
#setavailable,
] ]
recursiveset = { recursiveset = {
"source": "emails", "source": "emails",
"outputlabel": "messageheaders", "outputlabel": "messageheaders",
"actions": [getmessage], "actions": [getmessage, synapseregister, synapseassignusername, synapsecreatedmroom, synapsegetroomid, synapsepushmessages],
} }
-28
View File
@@ -1,28 +0,0 @@
import time
from plugins import rmass
from core.execution.operation import buildOperation
outputs = buildOperation(rmass.operations.pullmessagelist)
#print(outputs)
user_list = []
for item in outputs["message_list"]:
sender = item["userCard"]
user_list.append(sender["id"])
print(user_list)
conversations = []
for item in outputs["message_list"]:
conversation = item["id"]
conversations.append(conversation)
print(conversations)
#for messageid in user_list
#outputs = buildOperation(rmass.operations.getmessage)
#id_list = []
#for user in user_list
# id_list.append
# print
#ime.sleep(rmass.operations.setavailable.sleeptime)
+2 -3
View File
@@ -1,8 +1,7 @@
import time
from plugins import rmass from plugins import rmass
from core.execution.operation import buildOperation from core.execution.operation import buildOperation
from core.execution.action import buildAction
#from plugins.rmass.actions.getmessage import getmessageaction
outputs = buildOperation(rmass.operations.pullmessagelist) outputs = buildOperation(rmass.operations.pullmessagelist)
+1 -1
View File
@@ -1 +1 @@
{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3OTE5NTY3NTUsIm5iZiI6MTc5MTk1NjU3NSwic3ViIjoiMjM4MzAyIiwidXNlcm5hbWUiOiJYeHhvdGlxIiwidXNlclR5cGUiOjEsInN0YWdlTmFtZSI6Ilh4eG90aXEiLCJhcHByb3ZlZCI6MSwibG9jYXRpb25JZCI6NDcyLCJzZWFyY2hDaXR5IjoiYXRsYW50YSIsImNvdW50cnlTaG9ydCI6IlVTIiwic2Vzc2lvbkNvdW50cnlDb250aW5lbnQiOiJOQSIsImlzRnJvemVuIjowLCJsb2NhdGlvbkxhYmVsIjoiQXRsYW50YSwgR0EiLCJpc3MiOiJodHRwczovL3JlbnRtYXNzZXVyLmNvbSIsImlhdCI6MTc5MTk1NjYzNX0.G1vCD8bSnaobc71onjgABLIlyoG1LO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