mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 01:18:05 +08:00
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:
@ -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)
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user