From 52209217fc60e1122c7101123512c4e5b1114ac5 Mon Sep 17 00:00:00 2001 From: 6vision Date: Mon, 15 Jun 2026 19:47:19 +0800 Subject: [PATCH] refactor(wecom_bot): config-file-only callback mode + fixed callback path Remove the callback-mode fields (Callback Mode / Token / EncodingAESKey / Port) from the web console channel form; these are rarely changed and are now configured via config.json only. The console keeps Bot ID / Secret for the long-connection setup. Serve the callback HTTP server on a fixed path (/wecombot) instead of any path (/.*), so unrelated requests 404 rather than being processed as signature-failing WeCom callbacks. The bot's receive-message URL must point at http(s)://host:/wecombot. Co-authored-by: Cursor --- channel/web/web_channel.py | 4 ---- channel/wecom_bot/wecom_bot_channel.py | 10 ++++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/channel/web/web_channel.py b/channel/web/web_channel.py index 1dc36945..1be31c6a 100644 --- a/channel/web/web_channel.py +++ b/channel/web/web_channel.py @@ -3016,10 +3016,6 @@ class ChannelsHandler: "fields": [ {"key": "wecom_bot_id", "label": "Bot ID", "type": "text"}, {"key": "wecom_bot_secret", "label": "Secret", "type": "secret"}, - {"key": "wecom_bot_callback", "label": "Callback Mode", "type": "bool", "default": False}, - {"key": "wecom_bot_token", "label": "Token", "type": "secret"}, - {"key": "wecom_bot_encoding_aes_key", "label": "EncodingAESKey", "type": "secret"}, - {"key": "wecom_bot_port", "label": "Port", "type": "number", "default": 9892}, ], }), ("qq", { diff --git a/channel/wecom_bot/wecom_bot_channel.py b/channel/wecom_bot/wecom_bot_channel.py index 8d4601be..bc3b7695 100644 --- a/channel/wecom_bot/wecom_bot_channel.py +++ b/channel/wecom_bot/wecom_bot_channel.py @@ -12,6 +12,7 @@ import hashlib import json import math import os +import re import threading import time import uuid @@ -34,6 +35,9 @@ from config import conf WECOM_WS_URL = "wss://openws.work.weixin.qq.com" HEARTBEAT_INTERVAL = 30 MEDIA_CHUNK_SIZE = 512 * 1024 # 512KB per chunk (before base64 encoding) +# Fixed URL path for the callback (webhook) HTTP server. The bot's +# receive-message URL must point at this path, e.g. http://host:9892/wecombot +CALLBACK_PATH = "/wecombot" def _escape_control_chars_inside_json_strings(s: str) -> str: @@ -234,8 +238,10 @@ class WecomBotChannel(ChatChannel): return port = int(conf().get("wecom_bot_port", 9892)) - logger.info(f"[WecomBot] Starting callback (webhook) server on port {port}...") - urls = ("/.*", "channel.wecom_bot.wecom_bot_channel.WecomBotCallbackController") + logger.info(f"[WecomBot] Starting callback (webhook) server on port {port}, path {CALLBACK_PATH} ...") + # Only serve the fixed callback path; everything else 404s instead of being + # treated as a (signature-failing) WeCom callback. + urls = (re.escape(CALLBACK_PATH), "channel.wecom_bot.wecom_bot_channel.WecomBotCallbackController") app = web.application(urls, globals(), autoreload=False) func = web.httpserver.StaticMiddleware(app.wsgifunc()) func = web.httpserver.LogMiddleware(func)