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:<port>/wecombot.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
6vision
2026-06-15 19:47:19 +08:00
parent 018493a60b
commit 52209217fc
2 changed files with 8 additions and 6 deletions

View File

@@ -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", {

View File

@@ -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)