Initial commit with Advoware proxy

This commit is contained in:
root
2025-10-19 14:57:07 +00:00
commit 273aa8b549
45771 changed files with 5534555 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,95 @@
import requests
from datetime import datetime
from dateutil import parser
import pytz
import os
config = {
"name": "EspoCRMStatusCheck",
"type": "cron",
"cron": "*/1 * * * *", # Alle 5 Minuten (korrekte Feldname)
"description": "Checks CVmhErstgespraech for expired nchsterAnruf and updates status",
"emits": [] # Leer, da keine Events emittiert werden
}
async def handler(input, context): # Korrekte Signatur: input (oft None für Cron), context (erforderlich)
# EspoCRM API Konfiguration
api_url = "https://crm.bitbylaw.com/api/v1"
api_key = os.getenv("ESPOCRM_MARVIN_API_KEY")
if not api_key:
context.logger.error("ESPOCRM_API_KEY not set in environment")
return
headers = {"X-Api-Key": api_key}
# Aktuelle Zeit in UTC
now = datetime.now(pytz.UTC)
# Hole Einträge mit Status "Zurückgestellt" oder "Warte auf neuen Anruf"
try:
response = requests.get(
f"{api_url}/CVmhErstgespraech",
headers=headers,
params={
"where": [
{
"type": "or",
"value": [
{"type": "equals", "attribute": "status", "value": "Zurückgestellt"},
{"type": "equals", "attribute": "status", "value": "Warte auf neuen Anruf"}
]
}
],
"select": "id,status,nchsterAnruf"
}
)
response.raise_for_status()
entries = response.json().get("list", [])
context.logger.info(f"Found {len(entries)} matching CVmhErstgespraech entries")
except requests.RequestException as e:
context.logger.error(f"Failed to fetch entries: {str(e)}")
return
updated_count = 0
# Prüfe und aktualisiere Einträge
for entry in entries:
entry_id = entry["id"]
status = entry["status"]
nchster_anruf = entry.get("nchsterAnruf")
if not nchster_anruf:
context.logger.warning(f"Entry {entry_id} has no nchsterAnruf, skipping")
continue
# Parse Timestamp
try:
nchster_anruf_dt = parser.isoparse(nchster_anruf).astimezone(pytz.UTC)
except ValueError as e:
context.logger.error(f"Invalid nchsterAnruf for {entry_id}: {str(e)}")
continue
# Prüfe, ob abgelaufen
if nchster_anruf_dt < now:
context.logger.info(f"Entry {entry_id} expired (nchsterAnruf: {nchster_anruf}), updating status")
try:
update_response = requests.put(
f"{api_url}/CVmhErstgespraech/{entry_id}",
headers=headers,
json={"status": "Abgelaufen"} # Passe den Zielstatus an
)
update_response.raise_for_status()
context.logger.info(f"Updated status for {entry_id} to Abgelaufen")
# Speichere im State für Tracking
await context.state.set(f"crm_update_{entry_id}", {
"updated_at": now.isoformat(),
"old_status": status,
"new_status": "Abgelaufen"
})
updated_count += 1
except requests.RequestException as e:
context.logger.error(f"Failed to update {entry_id}: {str(e)}")
else:
context.logger.debug(f"Entry {entry_id} not expired (nchsterAnruf: {nchster_anruf})")
context.logger.info(f"Cron-Step completed: {updated_count} entries updated")

9
steps/event_step.py Normal file
View File

@@ -0,0 +1,9 @@
config = {
"name": "HelloEvent",
"type": "event",
"subscribes": ["hello.triggered"],
"emits": []
}
async def handler(input, context):
context.logger.info(f"Received event: {input['message']}")

11
steps/hello_step.py Normal file
View File

@@ -0,0 +1,11 @@
config = {
"name": "HelloWorld",
"type": "api",
"path": "/hello",
"method": "GET",
"emits": ["hello.triggered"]
}
async def handler(req, context):
await context.emit({"topic": "hello.triggered", "data": {"message": "Event from API"}})
return {"status": 200, "body": {"message": "Hello World from Motia!"}}