Commit a4eeb8db by sunqi02

feat: 更新发送消息功能,支持从环境变量加载IM服务的基础URL和API密钥

1 parent 97a47fde
......@@ -134,6 +134,8 @@ def send_im_message(
True 发送成功 / False 发送失败
"""
settings = ConfigLoader().load_settings()
base_url = os.getenv("IM_BASE_URL", settings.im.base_url)
api_key = os.getenv("IM_API_KEY", settings.im.api_key) or settings.im.api_key
payload = {
"contact_id": group_id,
"content": content,
......@@ -142,10 +144,10 @@ def send_im_message(
"biz_rela_no": f"biz-msg-{int(time.time() * 1000)}",
}
headers = {"Content-Type": "application/json"}
if settings.im.api_key:
headers["X-Api-Key"] = settings.im.api_key
if api_key:
headers["X-Api-Key"] = api_key
url = f"{settings.im.base_url}/api/v1/business/messages/send"
url = f"{base_url}/api/v1/business/messages/send"
try:
resp = httpx.post(url, json=payload, headers=headers, timeout=10)
resp.raise_for_status()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!