Fix IM channel backend URLs in Docker (#1497)

* Fix IM channel backend URLs in Docker

* Address Copilot review comments
This commit is contained in:
DanielWalnut
2026-03-28 16:37:41 +08:00
committed by GitHub
parent 9caea0266e
commit c2dd8937ed
7 changed files with 58 additions and 3 deletions

View File

@@ -318,6 +318,7 @@ Bridges external messaging platforms (Feishu, Slack, Telegram) to the DeerFlow a
**Configuration** (`config.yaml` -> `channels`):
- `langgraph_url` - LangGraph Server URL (default: `http://localhost:2024`)
- `gateway_url` - Gateway API URL for auxiliary commands (default: `http://localhost:8001`)
- In Docker Compose, IM channels run inside the `gateway` container, so `localhost` points back to that container. Use `http://langgraph:2024` / `http://gateway:8001`, or set `DEER_FLOW_CHANNELS_LANGGRAPH_URL` / `DEER_FLOW_CHANNELS_GATEWAY_URL`.
- Per-channel configs: `feishu` (app_id, app_secret), `slack` (bot_token, app_token), `telegram` (bot_token)
### Memory System (`packages/harness/deerflow/agents/memory/`)

View File

@@ -3,9 +3,10 @@
from __future__ import annotations
import logging
import os
from typing import Any
from app.channels.manager import ChannelManager
from app.channels.manager import DEFAULT_GATEWAY_URL, DEFAULT_LANGGRAPH_URL, ChannelManager
from app.channels.message_bus import MessageBus
from app.channels.store import ChannelStore
@@ -18,6 +19,19 @@ _CHANNEL_REGISTRY: dict[str, str] = {
"telegram": "app.channels.telegram:TelegramChannel",
}
_CHANNELS_LANGGRAPH_URL_ENV = "DEER_FLOW_CHANNELS_LANGGRAPH_URL"
_CHANNELS_GATEWAY_URL_ENV = "DEER_FLOW_CHANNELS_GATEWAY_URL"
def _resolve_service_url(config: dict[str, Any], config_key: str, env_key: str, default: str) -> str:
value = config.pop(config_key, None)
if isinstance(value, str) and value.strip():
return value
env_value = os.getenv(env_key, "").strip()
if env_value:
return env_value
return default
class ChannelService:
"""Manages the lifecycle of all configured IM channels.
@@ -30,8 +44,8 @@ class ChannelService:
self.bus = MessageBus()
self.store = ChannelStore()
config = dict(channels_config or {})
langgraph_url = config.pop("langgraph_url", None) or "http://localhost:2024"
gateway_url = config.pop("gateway_url", None) or "http://localhost:8001"
langgraph_url = _resolve_service_url(config, "langgraph_url", _CHANNELS_LANGGRAPH_URL_ENV, DEFAULT_LANGGRAPH_URL)
gateway_url = _resolve_service_url(config, "gateway_url", _CHANNELS_GATEWAY_URL_ENV, DEFAULT_GATEWAY_URL)
default_session = config.pop("session", None)
channel_sessions = {name: channel_config.get("session") for name, channel_config in config.items() if isinstance(channel_config, dict)}
self.manager = ChannelManager(

View File

@@ -1681,6 +1681,33 @@ class TestChannelService:
assert service.manager._channel_sessions["telegram"]["assistant_id"] == "mobile_agent"
assert service.manager._channel_sessions["telegram"]["users"]["vip"]["assistant_id"] == "vip_agent"
def test_service_urls_fall_back_to_env(self, monkeypatch):
from app.channels.service import ChannelService
monkeypatch.setenv("DEER_FLOW_CHANNELS_LANGGRAPH_URL", "http://langgraph:2024")
monkeypatch.setenv("DEER_FLOW_CHANNELS_GATEWAY_URL", "http://gateway:8001")
service = ChannelService(channels_config={})
assert service.manager._langgraph_url == "http://langgraph:2024"
assert service.manager._gateway_url == "http://gateway:8001"
def test_config_service_urls_override_env(self, monkeypatch):
from app.channels.service import ChannelService
monkeypatch.setenv("DEER_FLOW_CHANNELS_LANGGRAPH_URL", "http://langgraph:2024")
monkeypatch.setenv("DEER_FLOW_CHANNELS_GATEWAY_URL", "http://gateway:8001")
service = ChannelService(
channels_config={
"langgraph_url": "http://custom-langgraph:2024",
"gateway_url": "http://custom-gateway:8001",
}
)
assert service.manager._langgraph_url == "http://custom-langgraph:2024"
assert service.manager._gateway_url == "http://custom-gateway:8001"
# ---------------------------------------------------------------------------
# Slack send retry tests