feat: track designer downloads and notifications
This commit is contained in:
29
backend/app/services/wecom_bot.py
Normal file
29
backend/app/services/wecom_bot.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def send_wecom_text(content: str) -> bool:
|
||||
text = str(content or "").strip()
|
||||
webhook = str(getattr(settings, "WECOM_BOT_WEBHOOK", "") or "").strip()
|
||||
if not text or not webhook:
|
||||
return False
|
||||
try:
|
||||
response = httpx.post(
|
||||
webhook,
|
||||
json={"msgtype": "text", "text": {"content": text[:3500]}},
|
||||
timeout=10.0,
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
ok = int(data.get("errcode", -1)) == 0
|
||||
if not ok:
|
||||
logger.warning(f"WeCom bot send failed: {data}")
|
||||
return ok
|
||||
except Exception as e:
|
||||
logger.warning(f"WeCom bot send exception: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user