清空 Telegram webhook 使用者上下文
Some checks failed
CD Pipeline / deploy (push) Has been cancelled

This commit is contained in:
OoO
2026-05-13 09:40:19 +08:00
parent a335ab523f
commit d7ae243ece
2 changed files with 15 additions and 0 deletions

View File

@@ -8684,6 +8684,9 @@ def _handle_event_ignore_callback(data: str, cq: dict, chat_id, message_id) -> N
@openclaw_bot_bp.route('/bot/telegram/webhook', methods=['POST'])
def telegram_webhook():
try:
# 每個 webhook request 先清空 ContextVar避免同 worker thread 延用上一個 user。
_CURRENT_USER_ID_CTX.set(None)
update = request.get_json(silent=True)
if not update:
return jsonify({'ok': True})

View File

@@ -56,6 +56,18 @@ def test_openclaw_answer_variants_are_menu_wakeup():
assert bot._looks_like_wakeup_prompt("你好") is True
def test_webhook_clears_stale_user_context_at_request_start():
from routes import openclaw_bot_routes as bot
bot._CURRENT_USER_ID_CTX.set(999)
app = _build_request_app()
with app.test_request_context("/bot/telegram/webhook", method="POST", json=None):
bot.telegram_webhook()
assert bot._CURRENT_USER_ID_CTX.get() is None
def test_menu_command_returns_full_main_menu_keyboard(monkeypatch):
from routes import openclaw_bot_routes as bot
from services.openclaw_bot import menu_keyboards