forked from erp-dev/erp
feat: message-api for mission via wecomm agent
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.models import Case, IntegerField, Q, Value, When
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
@@ -10,7 +11,15 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def render_notification_content(*, notifier: Notifier, payload: dict) -> str:
|
||||
content = render_to_string(notifier.get_template_name(), payload or {}).strip()
|
||||
context = {
|
||||
**(payload or {}),
|
||||
"notifier_config": notifier.config or {},
|
||||
"notifier_config_url": notifier.get_config_value("url", "") or "",
|
||||
"notifier_config_image_url": notifier.get_config_value("image_url", "") or "",
|
||||
"default_news_image_url": getattr(settings, "MESSAGE_API_DEFAULT_NEWS_IMAGE_URL", "") or "",
|
||||
"notifier": notifier,
|
||||
}
|
||||
content = render_to_string(notifier.get_template_name(), context).strip()
|
||||
if not content:
|
||||
raise ValueError("通知模板渲染结果不能为空")
|
||||
return content
|
||||
|
||||
Reference in New Issue
Block a user