ForcePilot/backend/package/yuxi/channel/extensions/helpscout/template.py
Kris 432d5db970 feat(helpscout): 新增Help Scout客服工单渠道插件
完成Help Scout渠道的完整功能实现,包含API客户端、webhook处理、轮询同步、自动回复、工单标签分配、客户资料管理等核心能力,附带完整的配置Schema与插件元信息
2026-05-21 10:49:56 +08:00

86 lines
2.4 KiB
Python

from __future__ import annotations
import re
HELPSCOUT_EMAIL_TEMPLATE = """\
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto;">
<div style="padding: 20px 0;">
{greeting}
<div style="margin: 16px 0;">
{body}
</div>
{signature}
</div>
</body>
</html>"""
HELPSCOUT_NOTE_TEMPLATE = """\
<div style="background: #f0f7ff; border-left: 4px solid #2196F3;
padding: 12px 16px; margin: 8px 0; border-radius: 4px;">
<strong style="color: #1976D2;">AI Analysis:</strong> {content}
</div>
"""
def wrap_email_reply(
body_html: str,
greeting: str = "",
signature: str = "",
) -> str:
greeting_html = f"<p>{greeting}</p>" if greeting else ""
signature_html = f"<p style='margin-top: 24px; color: #666; font-size: 14px;'>{signature}</p>" if signature else ""
return HELPSCOUT_EMAIL_TEMPLATE.format(
greeting=greeting_html,
body=body_html,
signature=signature_html,
)
def wrap_ai_note(content: str) -> str:
escaped = content.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
return HELPSCOUT_NOTE_TEMPLATE.format(content=escaped)
def text_to_html_body(text: str) -> str:
result = text
result = re.sub(r"\*\*(.+?)\*\*", r"<strong>\1</strong>", result)
result = re.sub(r"\*(.+?)\*", r"<em>\1</em>", result)
result = re.sub(r"\[([^\]]+)\]\(([^\)]+)\)", r'<a href="\2">\1</a>', result)
lines = result.split("\n")
paragraphs = []
current = ""
for line in lines:
line = line.strip()
if not line:
if current:
paragraphs.append(f"<p>{current}</p>")
current = ""
continue
if line.startswith("- ") or line.startswith("* "):
if current:
paragraphs.append(f"<p>{current}</p>")
current = ""
item = line[2:]
paragraphs.append(f"<div>{item}</div>")
else:
if current:
current += f"<br>{line}"
else:
current = line
if current:
paragraphs.append(f"<p>{current}</p>")
return "\n".join(paragraphs)