fix: dingtalk adapters couldn't handle images (#1500)

This commit is contained in:
Guanchao Wang
2025-06-05 23:37:58 +08:00
committed by GitHub
parent ac8fe049de
commit 6402755ac6

View File

@@ -80,17 +80,20 @@ class DingTalkClient:
if download_url:
return await self.download_url_to_base64(download_url)
async def download_url_to_base64(self, download_url):
async with httpx.AsyncClient() as client:
response = await client.get(download_url)
if response.status_code == 200:
file_bytes = response.content
base64_str = base64.b64encode(file_bytes).decode('utf-8') # 返回字符串格式
return base64_str
mime_type = response.headers.get("Content-Type", "application/octet-stream")
base64_str = base64.b64encode(file_bytes).decode("utf-8")
return f"data:{mime_type};base64,{base64_str}"
else:
await self.logger.error(f"failed to get files: {response.json()}")
async def get_audio_url(self, download_code: str):
if not await self.check_access_token():
await self.get_access_token()