feat(api): support variable reference and substitution in Email delivery

The EmailDeliveryConfig.body now support referencing variables generated
by precedent nodes.
This commit is contained in:
QuantumGhost
2026-01-21 15:19:17 +08:00
parent 32dab780ba
commit 20be1dd819
7 changed files with 189 additions and 18 deletions

View File

@ -15,6 +15,7 @@ from core.workflow.nodes.human_input.entities import (
ExternalRecipient,
MemberRecipient,
)
from core.workflow.runtime import VariablePool
from extensions.ext_database import db
from extensions.ext_mail import mail
from libs.email_template_renderer import render_email_template
@ -42,6 +43,7 @@ class DeliveryTestContext:
rendered_content: str
template_vars: dict[str, str] = field(default_factory=dict)
recipients: list[DeliveryTestEmailRecipient] = field(default_factory=list)
variable_pool: VariablePool | None = None
@dataclass(frozen=True)
@ -154,9 +156,10 @@ class EmailDeliveryTestHandler:
recipient_email=recipient_email,
)
subject = render_email_template(method.config.subject, substitutions)
templated_body = EmailDeliveryConfig.replace_url_placeholder(
method.config.body,
substitutions.get("form_link"),
templated_body = EmailDeliveryConfig.render_body_template(
body=method.config.body,
url=substitutions.get("form_link"),
variable_pool=context.variable_pool,
)
body = render_email_template(templated_body, substitutions)

View File

@ -962,6 +962,7 @@ class WorkflowService:
rendered_content=rendered_content,
template_vars={"form_id": form_id},
recipients=recipients,
variable_pool=variable_pool,
)
try:
test_service.send_test(context=context, method=delivery_method)
@ -1087,8 +1088,6 @@ class WorkflowService:
config=node_config,
)
normalized_user_inputs: dict[str, Any] = dict(manual_inputs)
for raw_key, value in manual_inputs.items():
normalized_user_inputs[f"#{raw_key}#"] = value
load_into_variable_pool(
variable_loader=variable_loader,