From 3a9d6ea536063935f26e468c53424cdced8f7e1f Mon Sep 17 00:00:00 2001 From: xcosmosbox <2162381070@qq.com> Date: Tue, 24 Mar 2026 14:38:18 +0800 Subject: [PATCH] feat(WeXin): add route_tag property to adapt to WeChat official ilinkai 1.0.3 requirements --- nanobot/channels/weixin.py | 3 +++ tests/channels/test_weixin_channel.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/nanobot/channels/weixin.py b/nanobot/channels/weixin.py index 48a97f582..a8a4a636d 100644 --- a/nanobot/channels/weixin.py +++ b/nanobot/channels/weixin.py @@ -83,6 +83,7 @@ class WeixinConfig(Base): allow_from: list[str] = Field(default_factory=list) base_url: str = "https://ilinkai.weixin.qq.com" cdn_base_url: str = "https://novac2c.cdn.weixin.qq.com/c2c" + route_tag: str | int | None = None token: str = "" # Manually set token, or obtained via QR login state_dir: str = "" # Default: ~/.nanobot/weixin/ poll_timeout: int = DEFAULT_LONG_POLL_TIMEOUT_S # seconds for long-poll @@ -187,6 +188,8 @@ class WeixinChannel(BaseChannel): } if auth and self._token: headers["Authorization"] = f"Bearer {self._token}" + if self.config.route_tag is not None and str(self.config.route_tag).strip(): + headers["SKRouteTag"] = str(self.config.route_tag).strip() return headers async def _api_get( diff --git a/tests/channels/test_weixin_channel.py b/tests/channels/test_weixin_channel.py index a16c6b750..6107d117b 100644 --- a/tests/channels/test_weixin_channel.py +++ b/tests/channels/test_weixin_channel.py @@ -22,6 +22,20 @@ def _make_channel() -> tuple[WeixinChannel, MessageBus]: return channel, bus +def test_make_headers_includes_route_tag_when_configured() -> None: + bus = MessageBus() + channel = WeixinChannel( + WeixinConfig(enabled=True, allow_from=["*"], route_tag=123), + bus, + ) + channel._token = "token" + + headers = channel._make_headers() + + assert headers["Authorization"] == "Bearer token" + assert headers["SKRouteTag"] == "123" + + @pytest.mark.asyncio async def test_process_message_deduplicates_inbound_ids() -> None: channel, bus = _make_channel()