30 lines
803 B
Python
30 lines
803 B
Python
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
|