Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix: save DingTalk downloaded files to media dir instead of /tmp
Meng Yuhangf9ba6197de16
diff --git a/nanobot/channels/dingtalk.py b/nanobot/channels/dingtalk.pyindex 8a822ff29..ab12211e8 100644--- a/nanobot/channels/dingtalk.py+++ b/nanobot/channels/dingtalk.py@@ -538,8 +538,8 @@ class DingTalkChannel(BaseChannel):filename: str,sender_id: str,) -> str | None:- """Download a DingTalk file to a local temp directory, return local path."""- import tempfile+ """Download a DingTalk file to the media directory, return local path."""+ from nanobot.config.paths import get_media_dirtry:token = await self._get_access_token()@@ -568,8 +568,8 @@ class DingTalkChannel(BaseChannel):logger.error("DingTalk file download failed: status={}", file_resp.status_code)return None- # Save to local temp directory- download_dir = Path(tempfile.gettempdir()) / "nanobot_dingtalk" / sender_id+ # Save to media directory (accessible under workspace)+ download_dir = get_media_dir("dingtalk") / sender_iddownload_dir.mkdir(parents=True, exist_ok=True)file_path = download_dir / filenameawait asyncio.to_thread(file_path.write_bytes, file_resp.content)diff --git a/tests/test_dingtalk_channel.py b/tests/test_dingtalk_channel.pyindex 5bcbcfa9c..a0b866fad 100644--- a/tests/test_dingtalk_channel.py+++ b/tests/test_dingtalk_channel.py@@ -194,14 +194,17 @@ async def test_download_dingtalk_file(tmp_path, monkeypatch) -> None:])channel._http._responses[1].content = file_content- # Redirect temp dir to tmp_path- monkeypatch.setattr("tempfile.gettempdir", lambda: str(tmp_path))+ # Redirect media dir to tmp_path+ monkeypatch.setattr(+ "nanobot.config.paths.get_media_dir",+ lambda channel_name=None: tmp_path / channel_name if channel_name else tmp_path,+ )result = await channel._download_dingtalk_file("code123", "test.xlsx", "user1")assert result is not Noneassert result.endswith("test.xlsx")- assert (tmp_path / "nanobot_dingtalk" / "user1" / "test.xlsx").read_bytes() == file_content+ assert (tmp_path / "dingtalk" / "user1" / "test.xlsx").read_bytes() == file_content# Verify API callsassert channel._http.calls[0]["method"] == "POST"