mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-24 00:45:57 +00:00
Feature/feishu receive file (#1608)
* feat(feishu): add channel file materialization hook for inbound messages - Introduce Channel.receive_file(msg, thread_id) as a base method for file materialization; default is no-op. - Implement FeishuChannel.receive_file to download files/images from Feishu messages, save to sandbox, and inject virtual paths into msg.text. - Update ChannelManager to call receive_file for any channel if msg.files is present, enabling downstream model access to user-uploaded files. - No impact on Slack/Telegram or other channels (they inherit the default no-op). * style(backend): format code with ruff for lint compliance - Auto-formatted packages/harness/deerflow/agents/factory.py and tests/test_create_deerflow_agent.py using `ruff format` - Ensured both files conform to project linting standards - Fixes CI lint check failures caused by code style issues * fix(feishu): handle file write operation asynchronously to prevent blocking * fix(feishu): rename GetMessageResourceRequest to _GetMessageResourceRequest and remove redundant code * test(feishu): add tests for receive_file method and placeholder replacement * fix(manager): remove unnecessary type casting for channel retrieval * fix(feishu): update logging messages to reflect resource handling instead of image * fix(feishu): sanitize filename by replacing invalid characters in file uploads * fix(feishu): improve filename sanitization and reorder image key handling in message processing * fix(feishu): add thread lock to prevent filename conflicts during file downloads * fix(test): correct bad merge in test_feishu_parser.py * chore: run ruff and apply formatting cleanup fix(feishu): preserve rich-text attachment order and improve fallback filename handling
This commit is contained in:
@@ -276,6 +276,31 @@ class _DummyChannel(Channel):
|
||||
|
||||
|
||||
class TestBaseChannelOnOutbound:
|
||||
def test_default_receive_file_returns_original_message(self):
|
||||
"""The base Channel.receive_file returns the original message unchanged."""
|
||||
|
||||
class MinimalChannel(Channel):
|
||||
async def start(self):
|
||||
pass
|
||||
|
||||
async def stop(self):
|
||||
pass
|
||||
|
||||
async def send(self, msg):
|
||||
pass
|
||||
|
||||
from app.channels.message_bus import InboundMessage
|
||||
|
||||
bus = MessageBus()
|
||||
ch = MinimalChannel(name="minimal", bus=bus, config={})
|
||||
msg = InboundMessage(channel_name="minimal", chat_id="c1", user_id="u1", text="hello", files=[{"file_key": "k1"}])
|
||||
|
||||
result = _run(ch.receive_file(msg, "thread-1"))
|
||||
|
||||
assert result is msg
|
||||
assert result.text == "hello"
|
||||
assert result.files == [{"file_key": "k1"}]
|
||||
|
||||
def test_send_file_called_for_each_attachment(self, tmp_path):
|
||||
"""_on_outbound sends text first, then uploads each attachment."""
|
||||
bus = MessageBus()
|
||||
|
||||
Reference in New Issue
Block a user