refactor(block-h): resolve CommConversation hardcoding via kommunikation contract
This commit is contained in:
+6
-14
@@ -92,22 +92,16 @@ class WorkflowEngine:
|
||||
# Post workflow completion to Communication (G-WORK)
|
||||
try:
|
||||
from app.plugins.builtins.contracts import get_contract_registry
|
||||
from app.plugins.builtins.kommunikation.models import CommConversation
|
||||
from sqlalchemy import select as sa_select
|
||||
komm = get_contract_registry().get("kommunikation")
|
||||
if komm and instance.initiated_by:
|
||||
room_title = f"Workflow: {workflow.name if hasattr(workflow, 'name') else str(instance.workflow_id)}"
|
||||
existing = await self.db.execute(
|
||||
sa_select(CommConversation).where(
|
||||
CommConversation.tenant_id == self.tenant_id,
|
||||
CommConversation.title == room_title,
|
||||
CommConversation.is_locked.is_(True),
|
||||
CommConversation.locked_by == "workflow",
|
||||
CommConversation.deleted_at.is_(None),
|
||||
)
|
||||
conv_id = await komm.find_locked_room_id(
|
||||
db=self.db,
|
||||
tenant_id=self.tenant_id,
|
||||
plugin_name="workflow",
|
||||
title=room_title,
|
||||
)
|
||||
conv = existing.scalar_one_or_none()
|
||||
if not conv:
|
||||
if not conv_id:
|
||||
room = await komm.create_plugin_room(
|
||||
db=self.db,
|
||||
tenant_id=self.tenant_id,
|
||||
@@ -117,8 +111,6 @@ class WorkflowEngine:
|
||||
participant_type="workflow",
|
||||
)
|
||||
conv_id = uuid.UUID(room["conversation_id"])
|
||||
else:
|
||||
conv_id = conv.id
|
||||
await komm.send_message(
|
||||
db=self.db,
|
||||
tenant_id=self.tenant_id,
|
||||
|
||||
Reference in New Issue
Block a user