fix: Synology 응답에서 마크다운 제거 — **bold**, # header, - list → 순수 텍스트

상태 메시지(이모지)는 raw=True로 유지

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-06 12:57:50 +09:00
parent a16ff2ea88
commit 40c5d3cf21
3 changed files with 18 additions and 5 deletions

View File

@@ -69,7 +69,7 @@ async def synology_webhook(request: Request):
logger.info("Synology job %s from %s: %s", job.id, username, text[:50]) logger.info("Synology job %s from %s: %s", job.id, username, text[:50])
# "처리 중" 메시지 먼저 전송 (typing 느낌) # "처리 중" 메시지 먼저 전송 (typing 느낌)
await send_to_synology("🤔 생각 중...") await send_to_synology("🤔 생각 중...", raw=True)
# 파이프라인 시작 (비동기) # 파이프라인 시작 (비동기)
await jq_module.job_queue.submit(job) await jq_module.job_queue.submit(job)

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
import json import json
import logging import logging
import re
import httpx import httpx
@@ -12,12 +13,24 @@ from config import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def send_to_synology(text: str) -> bool: def _strip_markdown(text: str) -> str:
"""Incoming webhook URL로 메시지 전송. 성공 시 True.""" """마크다운 문법 제거 — Synology Chat은 렌더링 안 됨."""
text = re.sub(r'\*\*(.+?)\*\*', r'\1', text) # **bold**
text = re.sub(r'\*(.+?)\*', r'\1', text) # *italic*
text = re.sub(r'`(.+?)`', r'\1', text) # `code`
text = re.sub(r'^#{1,6}\s+', '', text, flags=re.MULTILINE) # ### headers
text = re.sub(r'^\s*[-*]\s+', '', text, flags=re.MULTILINE) # - list → •
return text
async def send_to_synology(text: str, *, raw: bool = False) -> bool:
"""Incoming webhook URL로 메시지 전송. raw=True면 마크다운 제거 안 함."""
if not settings.synology_incoming_url: if not settings.synology_incoming_url:
logger.warning("Synology incoming URL not configured") logger.warning("Synology incoming URL not configured")
return False return False
if not raw:
text = _strip_markdown(text)
payload = json.dumps({"text": text}, ensure_ascii=False) payload = json.dumps({"text": text}, ensure_ascii=False)
try: try:

View File

@@ -163,7 +163,7 @@ async def run(job: Job) -> None:
if job.callback != "synology": if job.callback != "synology":
await state_stream.push(job.id, "rewrite", {"content": rewritten_message}) await state_stream.push(job.id, "rewrite", {"content": rewritten_message})
else: else:
await send_to_synology("📝 더 깊이 살펴볼게요...") await send_to_synology("📝 더 깊이 살펴볼게요...", raw=True)
if job.status == JobStatus.cancelled: if job.status == JobStatus.cancelled:
return return
@@ -241,7 +241,7 @@ async def run(job: Job) -> None:
await state_stream.push(job.id, "error", {"message": "내부 오류가 발생했습니다."}) await state_stream.push(job.id, "error", {"message": "내부 오류가 발생했습니다."})
if job.callback == "synology": if job.callback == "synology":
try: try:
await send_to_synology("⚠️ 처리 중 오류가 발생했습니다. 다시 시도해주세요.") await send_to_synology("⚠️ 처리 중 오류가 발생했습니다. 다시 시도해주세요.", raw=True)
except Exception: except Exception:
pass pass
try: try: